Turning on a second georeferenced (Allmaps) overlay crashes the map page. Seen on a FairData Sites site with geospatial 3.1.25 and @allmaps/maplibre 1.0.0-beta.43 (the latest release).
Cause. In packages/geospatial/src/utils/Map.js:
const warpedMapLayer = new WarpedMapLayer(layerId);
Allmaps changed this constructor during the beta releases: it now expects { layerId: … } rather than the id itself (the doc comment still says @param id). The id we pass is ignored, so every overlay ends up with the same default id, warped-map-layer. One overlay works; a second one collides with the first:
map.addLayer fails: Layer "warped-map-layer" already exists.
- The code carries on and calls
setOpacity() on the layer that never made it onto the map: Renderer not defined. That error escapes while React is updating the page, so React tears the page down — the user sees it go blank.
- Removing the first overlay fails too:
Cannot remove non-existing layer. Removal looks the layer up by the id we meant to give it, and nothing is registered under that id.
Fix.
const warpedMapLayer = new WarpedMapLayer({ layerId });
Each overlay gets its own id again, which fixes the collision and the removal in one go. Also worth wrapping the add/opacity calls in a try/catch, so a bad overlay fails quietly instead of taking the page with it.
This is the only place a WarpedMapLayer is created — WarpedImageLayer.js and WarpedImageLayerPeripleo.js both go through this function, and neither creates one directly, so the one change covers both.
Turning on a second georeferenced (Allmaps) overlay crashes the map page. Seen on a FairData Sites site with geospatial 3.1.25 and @allmaps/maplibre 1.0.0-beta.43 (the latest release).
Cause. In
packages/geospatial/src/utils/Map.js:Allmaps changed this constructor during the beta releases: it now expects
{ layerId: … }rather than the id itself (the doc comment still says@param id). The id we pass is ignored, so every overlay ends up with the same default id,warped-map-layer. One overlay works; a second one collides with the first:map.addLayerfails:Layer "warped-map-layer" already exists.setOpacity()on the layer that never made it onto the map:Renderer not defined. That error escapes while React is updating the page, so React tears the page down — the user sees it go blank.Cannot remove non-existing layer. Removal looks the layer up by the id we meant to give it, and nothing is registered under that id.Fix.
Each overlay gets its own id again, which fixes the collision and the removal in one go. Also worth wrapping the add/opacity calls in a try/catch, so a bad overlay fails quietly instead of taking the page with it.
This is the only place a
WarpedMapLayeris created —WarpedImageLayer.jsandWarpedImageLayerPeripleo.jsboth go through this function, and neither creates one directly, so the one change covers both.