Skip to content

geospatial: every WarpedMapLayer gets the same id, so a second Allmaps overlay crashes the map #594

Description

@jamiefolsom

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:

  1. map.addLayer fails: Layer "warped-map-layer" already exists.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions