Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sprite loading to a separate private method (refactoring of _load) #9226

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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