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.
This commit is contained in:
Maurice
2026-10-20 18:23:50 +02:00
parent 1d7c8a63e2
commit 49e306ea48
5 changed files with 63 additions and 15 deletions
+21
View File
@@ -0,0 +1,21 @@
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()));
}