add try catch to setTerrain

This commit is contained in:
vcoppe
2026-01-28 17:53:26 +01:00
parent 200a6586ba
commit d76c03af4f

View File

@@ -212,6 +212,7 @@ export class MapboxGLMap {
const map = get(this._map); const map = get(this._map);
if (map) { if (map) {
const source = get(terrainSource); const source = get(terrainSource);
try {
if (!map.getSource(source)) { if (!map.getSource(source)) {
map.addSource(source, terrainSources[source]); map.addSource(source, terrainSources[source]);
} }
@@ -223,6 +224,10 @@ export class MapboxGLMap {
} else { } else {
map.setTerrain(null); map.setTerrain(null);
} }
} catch (e) {
// No reliable way to check if the map is ready to add sources and layers
return;
}
} }
} }
} }