From dde48e00842995df4e0d751792087c6d595a9fc9 Mon Sep 17 00:00:00 2001 From: Jin Igarashi Date: Sun, 27 Aug 2023 10:21:34 +0100 Subject: [PATCH 1/2] fix: add error handling when sprite@2x.png is not reachable --- .changeset/small-steaks-refuse.md | 5 +++++ packages/maplibre-gl-legend/src/lib/index.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/small-steaks-refuse.md diff --git a/.changeset/small-steaks-refuse.md b/.changeset/small-steaks-refuse.md new file mode 100644 index 0000000..6b14610 --- /dev/null +++ b/.changeset/small-steaks-refuse.md @@ -0,0 +1,5 @@ +--- +"@watergis/maplibre-gl-legend": patch +--- + +fix: add error handling when sprite@2x.png is not reachable diff --git a/packages/maplibre-gl-legend/src/lib/index.ts b/packages/maplibre-gl-legend/src/lib/index.ts index 4d39b3c..cfc7579 100644 --- a/packages/maplibre-gl-legend/src/lib/index.ts +++ b/packages/maplibre-gl-legend/src/lib/index.ts @@ -350,9 +350,11 @@ export class MaplibreLegendControl implements IControl { this.loadImage(`${styleUrl}@2x.png`), this.loadJson(`${styleUrl}.json`) ]); - await promise.then(([image, json]) => { - this.setSprite(image, json); - }); + await promise + .then(([image, json]) => { + this.setSprite(image, json); + }) + .catch((err) => console.error(err)); this.updateLegendControl(); map.off('idle', afterLoadListener); } @@ -422,6 +424,7 @@ export class MaplibreLegendControl implements IControl { if (!cancelled) resolve(img); }; img.onerror = (e) => { + console.log(e); if (!cancelled) reject(e); }; img.src = url; From 063b40f724d279f92c1fcdfaa523cae422cf4d42 Mon Sep 17 00:00:00 2001 From: Jin Igarashi Date: Sun, 27 Aug 2023 10:23:01 +0100 Subject: [PATCH 2/2] delete console.log --- packages/maplibre-gl-legend/src/lib/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/maplibre-gl-legend/src/lib/index.ts b/packages/maplibre-gl-legend/src/lib/index.ts index cfc7579..06126be 100644 --- a/packages/maplibre-gl-legend/src/lib/index.ts +++ b/packages/maplibre-gl-legend/src/lib/index.ts @@ -424,7 +424,6 @@ export class MaplibreLegendControl implements IControl { if (!cancelled) resolve(img); }; img.onerror = (e) => { - console.log(e); if (!cancelled) reject(e); }; img.src = url;