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); }