mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-14 08:11:03 +00:00
51af575c9a
A right-click, click or drag on a repeated world copy reported the longitude it has on that copy (274.9 for -85.1). The place was saved there, the geocoder found nothing, and a route to a place on the real world ran across the whole map (#2976). Longitudes are now brought back onto [-180, 180] where the map hands them out (Leaflet and GL), where they are stored (places, booking endpoints, collection places, so REST, MCP, plugin RPC and importers alike) and before reverse geocoding. A migration moves the ones already stored. Leaflet draws a layer at its literal longitude only, so a trip from Los Angeles to Auckland had its pins at opposite ends of the world while the flight ran off the edge to the next copy (#2975). A trip that crosses the antimeridian is now drawn in one longitude frame, seamed in the widest stretch it leaves empty, so pins, routes, flights and every overlay lie on one copy and the map opens across the Pacific. Every other trip has no frame and draws exactly as before. The GL day fit also takes the short way. A new install now starts with Journey and Collections switched on, next to the trip addons (all but Road trip), Atlas, Vacay and the Naver import that already were. Existing installs keep their addons as they are. Closes #2975 Closes #2976
24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
/**
|
|
* A longitude brought back onto the one real world, in [-180, 180].
|
|
*
|
|
* A map that repeats the world sideways (Leaflet and MapLibre both do) reports a
|
|
* point on a neighbouring copy as, say, -220 or 274.9 instead of 140 or -85.1.
|
|
* Stored like that, a place sat on its copy for good: the geocoder found nothing
|
|
* there, and a route to a place on the real world ran across the whole map (#2976).
|
|
*
|
|
* The edges are kept as given, so a stored -180 or 180 does not flip sides. A
|
|
* value that is not a finite number is returned untouched, for the caller's own
|
|
* validation to deal with.
|
|
*/
|
|
export function wrapLongitude(lng: number): number {
|
|
if (!Number.isFinite(lng) || (lng >= -180 && lng <= 180)) return lng;
|
|
const wrapped = ((((lng + 180) % 360) + 360) % 360) - 180;
|
|
// -0 reads as 0 everywhere else; keep it out of storage and snapshots.
|
|
return wrapped === 0 ? 0 : wrapped;
|
|
}
|
|
|
|
/** wrapLongitude for an optional column: null and undefined pass through. */
|
|
export function wrapOptionalLongitude<T extends number | null | undefined>(lng: T): T {
|
|
return (typeof lng === 'number' ? wrapLongitude(lng) : lng) as T;
|
|
}
|