Files
TREK/client/src/components/Journey/journeyPhotoLayer.ts
T
Maurice 55b11f792a fix(journey): keep map photo and mark clusters stable while panning
The journey map grouped its photo thumbnails and its plan and stay marks
on a grid laid over container pixels. Every pan shifted that grid against
the map, so photos near a cell edge changed groups after each move: the
count badges jumped and the thumbnail switched to another photo, although
the zoom never changed.

Both renderers now bucket in world pixels at the current zoom, Leaflet
through its own CRS (so GCJ-02 basemaps stay right) and GL through a
plain Web Mercator projection that ignores centre, bearing and pitch.
Panning keeps every group as it is; only a zoom regroups.

Closes #2889
2026-10-29 17:26:50 +01:00

37 lines
1.9 KiB
TypeScript

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
}