mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
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:
@@ -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()));
|
||||
}
|
||||
Reference in New Issue
Block a user