Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1.9 KB
Raw Blame
import { clusterPoints, type WorldPx } from './journeyMapMarks'

/** A photo that knows where it was taken (#1614). */
export interface MapPhoto {
  id: string
  lat: number
  lng: number
  thumbUrl: string
}

/**
 * Grid clustering of the photos, shared by the Leaflet and the GL journey map.
 *
 * The Journey maps have never had clustering, and the library the planner uses
 * hangs off react-leaflet while these maps drive their engines directly.
 * Bucketing by rounded world-pixel position is a few lines, is deterministic,
 * and is enough for the job: photos of one place collapse into one thumbnail
 * with a count, zooming in separates them again, and panning leaves them be.
 */
export const PHOTO_CLUSTER_PX = 64

export function clusterPhotos(
  photos: MapPhoto[],
  toWorldPx: WorldPx,
): { lat: number; lng: number; members: MapPhoto[] }[] {
  // Anchored on the first member rather than the centroid: the thumbnail shown
  // is that photo's, so the pin should point where that picture was taken.
  return clusterPoints(photos, toWorldPx, PHOTO_CLUSTER_PX)
}

export function photoMarkerHtml(thumbUrl: string, count: number): string {
  const badge = count > 1
    ? `<span style="position:absolute;top:-6px;right:-6px;min-width:20px;height:20px;padding:0 5px;border-radius:10px;background:#fff;border:1.5px solid rgba(0,0,0,.12);box-shadow:0 1px 4px rgba(0,0,0,.22);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:800;color:#111827;line-height:1;box-sizing:border-box;">${count}</span>` // theme-lint-disable: map marker chrome, drawn over any basemap
    : ''
  return `<div style="position:relative;width:48px;height:48px;border-radius:12px;border:3px solid #fff;box-shadow:0 2px 8px rgba(0,0,0,.3);background-image:url('${encodeURI(thumbUrl)}');background-size:cover;background-position:center;"></div>${badge}` // theme-lint-disable: map marker chrome, drawn over any basemap
}