Skip to content

Commit

Permalink
Refactor style._load function, move sprite loading to a private method (
Browse files Browse the repository at this point in the history
  • Loading branch information
webdeb authored and mike-unearth committed Mar 18, 2020
1 parent b31a32f commit 9be0bfb
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,7 @@ class Style extends Evented {
}

if (json.sprite) {
this._spriteRequest = loadSprite(json.sprite, this.map._requestManager, (err, images) => {
this._spriteRequest = null;
if (err) {
this.fire(new ErrorEvent(err));
} else if (images) {
for (const id in images) {
this.imageManager.addImage(id, images[id]);
}
}

this.imageManager.setLoaded(true);
this.dispatcher.broadcast('setImages', this.imageManager.listImages());
this.fire(new Event('data', {dataType: 'style'}));
});
this._loadSprite(json.sprite);
} else {
this.imageManager.setLoaded(true);
}
Expand All @@ -288,6 +275,23 @@ class Style extends Evented {
this.fire(new Event('style.load'));
}

_loadSprite(url: string) {
this._spriteRequest = loadSprite(url, this.map._requestManager, (err, images) => {
this._spriteRequest = null;
if (err) {
this.fire(new ErrorEvent(err));
} else if (images) {
for (const id in images) {
this.imageManager.addImage(id, images[id]);
}
}

this.imageManager.setLoaded(true);
this.dispatcher.broadcast('setImages', this.imageManager.listImages());
this.fire(new Event('data', {dataType: 'style'}));
});
}

_validateLayer(layer: StyleLayer) {
const sourceCache = this.sourceCaches[layer.source];
if (!sourceCache) {
Expand Down

0 comments on commit 9be0bfb

Please sign in to comment.