fix(geoportal): building labels — force overlap + delayed init

Labels were hidden by MapLibre collision detection with terrain
labels. Now using text-allow-overlap + text-ignore-placement to
force visibility. Also added retry with setTimeout in case source
isn't ready when layer is first added.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-27 08:07:38 +02:00
parent 49a239006d
commit c6eb1a9450
+35 -22
View File
@@ -441,28 +441,41 @@ export const MapViewer = forwardRef<MapViewerHandle, MapViewerProps>(
paint: { "line-color": "#1e3a5f", "line-width": 0.6 } }); paint: { "line-color": "#1e3a5f", "line-width": 0.6 } });
// Building body labels (C1, C2...) — visible at high zoom // Building body labels (C1, C2...) — visible at high zoom
// cadastral_ref = "77102-C1" → display "C1" // cadastral_ref = "77102-C1" → display "C1"
map.addLayer({ {
id: LAYER_IDS.cladiriLabel, // Add after a small delay to ensure the style is fully loaded
type: "symbol", // and the source has been registered
source: SOURCES.cladiri, const addBuildingLabels = () => {
"source-layer": SOURCES.cladiri, try {
minzoom: 16, if (map.getLayer(LAYER_IDS.cladiriLabel)) return;
filter: ["has", "cadastral_ref"], map.addLayer({
layout: { id: LAYER_IDS.cladiriLabel,
// Simple approach: show full cadastral_ref, let the user see "77102-C1" type: "symbol",
// MapLibre will auto-hide overlapping labels source: SOURCES.cladiri,
"text-field": ["get", "cadastral_ref"], "source-layer": SOURCES.cladiri,
"text-font": ["Noto Sans Regular"], minzoom: 17,
"text-size": 10, filter: ["has", "cadastral_ref"],
"text-anchor": "center", layout: {
"text-allow-overlap": false, "text-field": ["get", "cadastral_ref"],
}, "text-font": ["Noto Sans Regular"],
paint: { "text-size": 9,
"text-color": "#1e3a8a", "text-anchor": "center",
"text-halo-color": "#ffffff", "text-allow-overlap": true,
"text-halo-width": 1.5, "text-ignore-placement": true,
}, },
}); paint: {
"text-color": "#1e3a8a",
"text-halo-color": "#ffffff",
"text-halo-width": 1.5,
},
});
} catch (e) {
console.warn("[map] building labels failed:", e);
}
};
// Try immediately, retry after 2s if source not ready
try { addBuildingLabels(); } catch { /* */ }
setTimeout(addBuildingLabels, 2000);
}
// === Selection highlight === // === Selection highlight ===
map.addLayer({ id: LAYER_IDS.selectionFill, type: "fill", source: SOURCES.terenuri, "source-layer": SOURCES.terenuri, minzoom: 13, map.addLayer({ id: LAYER_IDS.selectionFill, type: "fill", source: SOURCES.terenuri, "source-layer": SOURCES.terenuri, minzoom: 13,