From c6eb1a945030b8d66bb65f0d0df5ed54140d1b09 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Fri, 27 Mar 2026 08:07:38 +0200 Subject: [PATCH] =?UTF-8?q?fix(geoportal):=20building=20labels=20=E2=80=94?= =?UTF-8?q?=20force=20overlap=20+=20delayed=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../geoportal/components/map-viewer.tsx | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/src/modules/geoportal/components/map-viewer.tsx b/src/modules/geoportal/components/map-viewer.tsx index 733e51a..c74d5f3 100644 --- a/src/modules/geoportal/components/map-viewer.tsx +++ b/src/modules/geoportal/components/map-viewer.tsx @@ -441,28 +441,41 @@ export const MapViewer = forwardRef( paint: { "line-color": "#1e3a5f", "line-width": 0.6 } }); // Building body labels (C1, C2...) — visible at high zoom // cadastral_ref = "77102-C1" → display "C1" - map.addLayer({ - id: LAYER_IDS.cladiriLabel, - type: "symbol", - source: SOURCES.cladiri, - "source-layer": SOURCES.cladiri, - minzoom: 16, - filter: ["has", "cadastral_ref"], - layout: { - // Simple approach: show full cadastral_ref, let the user see "77102-C1" - // MapLibre will auto-hide overlapping labels - "text-field": ["get", "cadastral_ref"], - "text-font": ["Noto Sans Regular"], - "text-size": 10, - "text-anchor": "center", - "text-allow-overlap": false, - }, - paint: { - "text-color": "#1e3a8a", - "text-halo-color": "#ffffff", - "text-halo-width": 1.5, - }, - }); + { + // Add after a small delay to ensure the style is fully loaded + // and the source has been registered + const addBuildingLabels = () => { + try { + if (map.getLayer(LAYER_IDS.cladiriLabel)) return; + map.addLayer({ + id: LAYER_IDS.cladiriLabel, + type: "symbol", + source: SOURCES.cladiri, + "source-layer": SOURCES.cladiri, + minzoom: 17, + filter: ["has", "cadastral_ref"], + layout: { + "text-field": ["get", "cadastral_ref"], + "text-font": ["Noto Sans Regular"], + "text-size": 9, + "text-anchor": "center", + "text-allow-overlap": true, + "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 === map.addLayer({ id: LAYER_IDS.selectionFill, type: "fill", source: SOURCES.terenuri, "source-layer": SOURCES.terenuri, minzoom: 13,