mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +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
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// Coordinates the map hands out, brought back from a repeated world copy (#2976).
|
|
//
|
|
// Leaflet and MapLibre/Mapbox repeat the world sideways, and a pointer on a copy
|
|
// reports the longitude it has on that copy: 274.9 for -85.1. Anything that
|
|
// stores a point or asks a server about it wants the point on the real world.
|
|
|
|
import { wrapLongitude } from '@trek/shared';
|
|
|
|
/** The same point with its longitude on the real world, in [-180, 180]. */
|
|
export function onRealWorld<T extends { lat: number; lng: number }>(point: T): T {
|
|
const lng = wrapLongitude(point.lng);
|
|
return lng === point.lng ? point : { ...point, lng };
|
|
}
|
|
|
|
export interface Bbox {
|
|
south: number;
|
|
west: number;
|
|
north: number;
|
|
east: number;
|
|
}
|
|
|
|
/**
|
|
* A viewport box moved whole by a multiple of 360 degrees so its centre lies on
|
|
* the real world. A box looking at a copy of Japan then asks for Japan. A box
|
|
* that spans the antimeridian keeps one edge past it, as it always had.
|
|
*/
|
|
export function bboxOnRealWorld<T extends Bbox>(bbox: T): T {
|
|
const centre = (bbox.west + bbox.east) / 2;
|
|
const shift = wrapLongitude(centre) - centre;
|
|
if (shift === 0) return bbox;
|
|
return { ...bbox, west: bbox.west + shift, east: bbox.east + shift };
|
|
}
|