From 0dfb343de82618ad40811860cc17801bec90ae67 Mon Sep 17 00:00:00 2001 From: Jin Igarashi Date: Sun, 27 Aug 2023 10:33:16 +0100 Subject: [PATCH] fix: only load sprite file if sprite property in style is available (#19) --- .changeset/grumpy-eggs-greet.md | 5 +++++ packages/maplibre-gl-legend/src/lib/index.ts | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 .changeset/grumpy-eggs-greet.md diff --git a/.changeset/grumpy-eggs-greet.md b/.changeset/grumpy-eggs-greet.md new file mode 100644 index 0000000..2358f4f --- /dev/null +++ b/.changeset/grumpy-eggs-greet.md @@ -0,0 +1,5 @@ +--- +"@watergis/maplibre-gl-legend": patch +--- + +fix: only load sprite file if sprite property in style is available diff --git a/packages/maplibre-gl-legend/src/lib/index.ts b/packages/maplibre-gl-legend/src/lib/index.ts index 06126be..ee87e56 100644 --- a/packages/maplibre-gl-legend/src/lib/index.ts +++ b/packages/maplibre-gl-legend/src/lib/index.ts @@ -346,15 +346,17 @@ export class MaplibreLegendControl implements IControl { if (map.loaded()) { const style = map.getStyle(); const styleUrl = style.sprite; - const promise = Promise.all([ - this.loadImage(`${styleUrl}@2x.png`), - this.loadJson(`${styleUrl}.json`) - ]); - await promise - .then(([image, json]) => { - this.setSprite(image, json); - }) - .catch((err) => console.error(err)); + if (styleUrl) { + const promise = Promise.all([ + this.loadImage(`${styleUrl}@2x.png`), + this.loadJson(`${styleUrl}.json`) + ]); + await promise + .then(([image, json]) => { + this.setSprite(image, json); + }) + .catch((err) => console.error(err)); + } this.updateLegendControl(); map.off('idle', afterLoadListener); }