fix(geoportal): building labels — inline addLayer like terenuriLabel
Removed wrapper function/setTimeout approach. Now uses exact same inline addLayer pattern as terenuriLabel which is proven to work. Same source, same font, same coalesce pattern. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -439,43 +439,14 @@ export const MapViewer = forwardRef<MapViewerHandle, MapViewerProps>(
|
|||||||
paint: { "fill-color": "#3b82f6", "fill-opacity": 0.5 } });
|
paint: { "fill-color": "#3b82f6", "fill-opacity": 0.5 } });
|
||||||
map.addLayer({ id: LAYER_IDS.cladiriLine, type: "line", source: SOURCES.cladiri, "source-layer": SOURCES.cladiri, minzoom: 14,
|
map.addLayer({ id: LAYER_IDS.cladiriLine, type: "line", source: SOURCES.cladiri, "source-layer": SOURCES.cladiri, minzoom: 14,
|
||||||
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 — same pattern as terenuriLabel (which works)
|
||||||
// cadastral_ref = "77102-C1" → display "C1"
|
map.addLayer({ id: LAYER_IDS.cladiriLabel, type: "symbol", source: SOURCES.cladiri, "source-layer": SOURCES.cladiri, minzoom: 17,
|
||||||
{
|
layout: {
|
||||||
// Add after a small delay to ensure the style is fully loaded
|
"text-field": ["coalesce", ["get", "cadastral_ref"], ""],
|
||||||
// and the source has been registered
|
"text-font": ["Noto Sans Regular"],
|
||||||
const addBuildingLabels = () => {
|
"text-size": 9, "text-anchor": "center", "text-allow-overlap": true,
|
||||||
try {
|
},
|
||||||
if (map.getLayer(LAYER_IDS.cladiriLabel)) return;
|
paint: { "text-color": "#1e3a8a", "text-halo-color": "#fff", "text-halo-width": 1.5 } });
|
||||||
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 ===
|
// === 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user