Guard syncTerrain against running before the style has loaded
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 12s

This commit is contained in:
randy committed 2026-09-12 13:27:53 +02:00
1 parent cd02b03502
commit 17d1adedbc
1 file changed
+5
+5
View File
@@ -100,6 +100,11 @@ class HillshadeControl {
// showing raised terrain needs both "tilted enough to see it" and "the // showing raised terrain needs both "tilted enough to see it" and "the
// DEM source this checkbox controls is actually loaded". // DEM source this checkbox controls is actually loaded".
syncTerrain(pitched) { syncTerrain(pitched) {
// setLight/setTerrain throw if the style isn't loaded yet — called
// synchronously from map.js's setOverlaysControl during page init,
// before the first style.load; that listener re-invokes this once it
// actually is loaded, so bailing here just skips the premature call.
if (!this._map.isStyleLoaded()) return;
const terrainOn = pitched && this._active && this._map.getSource(HILLSHADE_ID); const terrainOn = pitched && this._active && this._map.getSource(HILLSHADE_ID);
if (terrainOn) { if (terrainOn) {
this._map.setTerrain({ source: HILLSHADE_ID, exaggeration: 3 }); this._map.setTerrain({ source: HILLSHADE_ID, exaggeration: 3 });