Skip to content

Commit

Permalink
fix: only load sprite file if sprite property in style is available (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JinIgarashi authored Aug 27, 2023
1 parent 8141113 commit 0dfb343
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-eggs-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@watergis/maplibre-gl-legend": patch
---

fix: only load sprite file if sprite property in style is available
20 changes: 11 additions & 9 deletions packages/maplibre-gl-legend/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0dfb343

Please sign in to comment.