Files
TREK/client/src/components/Map/glViewport.ts
T
Maurice 49e306ea48 refactor(map): report the GL viewport from a module of its own
reportGlViewport says what a GL map shows, its bounds and its zoom on the
raster tile scale, and has its own test for that scale. MapViewGL only
wires it to moveend and idle, and its test checks that wiring. The GL map
tests put the zoom back to its default before each test, as they do for
every other value a test overrides, instead of each test restoring it.
2026-10-20 18:23:50 +02:00

22 lines
966 B
TypeScript

import { rasterTileZoom } from './glRasterLayers';
import type { MapViewProps } from './mapViewContract';
/** Enough of a GL map to say what it shows: its bounds and its zoom. */
interface ViewportSource {
getBounds(): { getSouth(): number; getWest(): number; getNorth(): number; getEast(): number } | null;
getZoom(): number;
}
/**
* Tells the page what a GL map shows, so the POI explore pill can fetch the
* OSM places of the visible area: its bounds, and its zoom on the raster tile
* scale Leaflet reports too, so both maps ask for the same places at the
* same view. A map without bounds yet says nothing.
*/
export function reportGlViewport(map: ViewportSource, report: MapViewProps['onViewportChange']): void {
const bounds = map.getBounds();
if (!report || !bounds) return;
const bbox = { south: bounds.getSouth(), west: bounds.getWest(), north: bounds.getNorth(), east: bounds.getEast() };
report(bbox, rasterTileZoom(map.getZoom()));
}