From 692721d1c086c99ecd1ccd8c0db85a2fa52bbe6e Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 25 Jul 2026 11:19:49 +0000 Subject: [PATCH] Resolve the data-layer anchor against the running style The hardcoded 'building-number-label-hover' beforeId only existed in the legacy Mapbox style; after the basemap swap every addLayer threw and no data layers rendered. Resolve the anchor at runtime instead: env override, then the purple boundary lines, then the first symbol layer, then on top - a missing id degrades placement, never the mapset. Co-Authored-By: Claude Fable 5 --- src/components/Mapbox/useMapLayers.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/Mapbox/useMapLayers.ts b/src/components/Mapbox/useMapLayers.ts index 875f37a..50bdef7 100644 --- a/src/components/Mapbox/useMapLayers.ts +++ b/src/components/Mapbox/useMapLayers.ts @@ -92,7 +92,20 @@ export const useMapLayers = function useMapLayers( // Add ownership fencing applyOwnershipFilterToLayerSpecification(layerSpecification) - mapInstance.value.addLayer(layerSpecification, import.meta.env.VITE_FUNDERMAPS_NUMBER_LAYER || 'building-number-label-hover') + // Insert data layers below the purple admin-boundary lines (and + // thus below all labels). The anchor is resolved against the + // running style: the env override first, then the boundary + // layer, then the first symbol layer, then simply on top - + // a missing anchor id must never take the whole mapset down + // (the legacy hardcoded 'building-number-label-hover' anchor + // did exactly that after the basemap swap). + const anchorCandidates = [ + import.meta.env.VITE_FUNDERMAPS_NUMBER_LAYER, + 'fundermaps-municipality', + ].filter(Boolean) as string[] + const anchor = anchorCandidates.find((id) => mapInstance.value?.getLayer(id)) + || mapInstance.value.getStyle().layers.find((l) => l.type === 'symbol')?.id + mapInstance.value.addLayer(layerSpecification, anchor) attachEventHandlers(layerId)