mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-04-20 10:31:17 +00:00
catch errors when fetching styles and add fallback one
This commit is contained in:
@@ -81,8 +81,13 @@ export class StyleManager {
|
|||||||
|
|
||||||
let basemap = get(currentBasemap);
|
let basemap = get(currentBasemap);
|
||||||
const basemapInfo = basemaps[basemap] ?? custom[basemap]?.value ?? basemaps[defaultBasemap];
|
const basemapInfo = basemaps[basemap] ?? custom[basemap]?.value ?? basemaps[defaultBasemap];
|
||||||
const basemapStyle = await this.get(basemapInfo);
|
|
||||||
|
|
||||||
|
let basemapStyle = basemaps.openStreetMap as maplibregl.StyleSpecification;
|
||||||
|
try {
|
||||||
|
basemapStyle = await this.get(basemapInfo);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
this.merge(style, basemapStyle);
|
this.merge(style, basemapStyle);
|
||||||
|
|
||||||
if (this._maptilerKey !== '') {
|
if (this._maptilerKey !== '') {
|
||||||
@@ -109,16 +114,21 @@ export class StyleManager {
|
|||||||
if (!layers[overlay]) {
|
if (!layers[overlay]) {
|
||||||
if (this._pastOverlays.has(overlay)) {
|
if (this._pastOverlays.has(overlay)) {
|
||||||
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
||||||
|
try {
|
||||||
const overlayStyle = await this.get(overlayInfo);
|
const overlayStyle = await this.get(overlayInfo);
|
||||||
for (let layer of overlayStyle.layers ?? []) {
|
for (let layer of overlayStyle.layers ?? []) {
|
||||||
if (map_.getLayer(layer.id)) {
|
if (map_.getLayer(layer.id)) {
|
||||||
map_.removeLayer(layer.id);
|
map_.removeLayer(layer.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Should not happen
|
||||||
|
}
|
||||||
this._pastOverlays.delete(overlay);
|
this._pastOverlays.delete(overlay);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
||||||
|
try {
|
||||||
const overlayStyle = await this.get(overlayInfo);
|
const overlayStyle = await this.get(overlayInfo);
|
||||||
const opacity = overlayOpacities[overlay];
|
const opacity = overlayOpacities[overlay];
|
||||||
|
|
||||||
@@ -146,8 +156,10 @@ export class StyleManager {
|
|||||||
map_.addLayer(layer, ANCHOR_LAYER_KEY.overlays);
|
map_.addLayer(layer, ANCHOR_LAYER_KEY.overlays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._pastOverlays.add(overlay);
|
this._pastOverlays.add(overlay);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@@ -181,6 +193,9 @@ export class StyleManager {
|
|||||||
styleUrl = styleUrl.replace(maptilerKeyPlaceHolder, this._maptilerKey);
|
styleUrl = styleUrl.replace(maptilerKeyPlaceHolder, this._maptilerKey);
|
||||||
}
|
}
|
||||||
const response = await fetch(styleUrl, { cache: 'force-cache' });
|
const response = await fetch(styleUrl, { cache: 'force-cache' });
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error fetching style "${styleInfo}": ${response.status}`);
|
||||||
|
}
|
||||||
const style = await response.json();
|
const style = await response.json();
|
||||||
return style;
|
return style;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user