Skip to content

Commit 8e9f16c

Browse files
committed
Merge branch 'dev'
2 parents c60b64f + 36b16dd commit 8e9f16c

1 file changed

Lines changed: 41 additions & 26 deletions

File tree

website/src/lib/components/map/style.ts

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@ export class StyleManager {
8181

8282
let basemap = get(currentBasemap);
8383
const basemapInfo = basemaps[basemap] ?? custom[basemap]?.value ?? basemaps[defaultBasemap];
84-
const basemapStyle = await this.get(basemapInfo);
8584

85+
let basemapStyle = basemaps.openStreetMap as maplibregl.StyleSpecification;
86+
try {
87+
basemapStyle = await this.get(basemapInfo);
88+
} catch (e) {
89+
console.error(e.message);
90+
}
8691
this.merge(style, basemapStyle);
8792

8893
if (this._maptilerKey !== '') {
@@ -109,45 +114,52 @@ export class StyleManager {
109114
if (!layers[overlay]) {
110115
if (this._pastOverlays.has(overlay)) {
111116
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
112-
const overlayStyle = await this.get(overlayInfo);
113-
for (let layer of overlayStyle.layers ?? []) {
114-
if (map_.getLayer(layer.id)) {
115-
map_.removeLayer(layer.id);
117+
try {
118+
const overlayStyle = await this.get(overlayInfo);
119+
for (let layer of overlayStyle.layers ?? []) {
120+
if (map_.getLayer(layer.id)) {
121+
map_.removeLayer(layer.id);
122+
}
116123
}
124+
} catch (e) {
125+
// Should not happen
117126
}
118127
this._pastOverlays.delete(overlay);
119128
}
120129
} else {
121130
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
122-
const overlayStyle = await this.get(overlayInfo);
123-
const opacity = overlayOpacities[overlay];
131+
try {
132+
const overlayStyle = await this.get(overlayInfo);
133+
const opacity = overlayOpacities[overlay];
124134

125-
for (let sourceId in overlayStyle.sources) {
126-
if (!map_.getSource(sourceId)) {
127-
map_.addSource(sourceId, overlayStyle.sources[sourceId]);
135+
for (let sourceId in overlayStyle.sources) {
136+
if (!map_.getSource(sourceId)) {
137+
map_.addSource(sourceId, overlayStyle.sources[sourceId]);
138+
}
128139
}
129-
}
130140

131-
for (let layer of overlayStyle.layers ?? []) {
132-
if (!map_.getLayer(layer.id)) {
133-
if (opacity !== undefined) {
134-
if (layer.type === 'raster') {
135-
if (!layer.paint) {
136-
layer.paint = {};
137-
}
138-
layer.paint['raster-opacity'] = opacity;
139-
} else if (layer.type === 'hillshade') {
140-
if (!layer.paint) {
141-
layer.paint = {};
141+
for (let layer of overlayStyle.layers ?? []) {
142+
if (!map_.getLayer(layer.id)) {
143+
if (opacity !== undefined) {
144+
if (layer.type === 'raster') {
145+
if (!layer.paint) {
146+
layer.paint = {};
147+
}
148+
layer.paint['raster-opacity'] = opacity;
149+
} else if (layer.type === 'hillshade') {
150+
if (!layer.paint) {
151+
layer.paint = {};
152+
}
153+
layer.paint['hillshade-exaggeration'] = opacity / 2;
142154
}
143-
layer.paint['hillshade-exaggeration'] = opacity / 2;
144155
}
156+
map_.addLayer(layer, ANCHOR_LAYER_KEY.overlays);
145157
}
146-
map_.addLayer(layer, ANCHOR_LAYER_KEY.overlays);
147158
}
159+
this._pastOverlays.add(overlay);
160+
} catch (e) {
161+
console.error(e.message);
148162
}
149-
150-
this._pastOverlays.add(overlay);
151163
}
152164
}
153165
} catch (e) {}
@@ -181,6 +193,9 @@ export class StyleManager {
181193
styleUrl = styleUrl.replace(maptilerKeyPlaceHolder, this._maptilerKey);
182194
}
183195
const response = await fetch(styleUrl, { cache: 'force-cache' });
196+
if (!response.ok) {
197+
throw new Error(`HTTP error fetching style "${styleInfo}": ${response.status}`);
198+
}
184199
const style = await response.json();
185200
return style;
186201
} else {

0 commit comments

Comments
 (0)