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

Add style#setSprite method #3662

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion debug/dark-v9.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ window.darkv9 = {
"type": "vector"
}
},
"sprite": "mapbox://sprites/mapbox/light-v9",
"sprite": "mapbox://sprites/mapbox/dark-v9",
"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
"layers": [
{
Expand Down
26 changes: 22 additions & 4 deletions js/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const supportedDiffOperations = util.pick(diff.operations, [
'removeSource',
'setLayerZoomRange',
'setLight',
'setTransition'
'setTransition',
'setSprite'
// 'setGlyphs',
// 'setSprite',
]);

const ignoredDiffOperations = util.pick(diff.operations, [
Expand Down Expand Up @@ -94,8 +94,7 @@ class Style extends Evented {
}

if (stylesheet.sprite) {
this.sprite = new ImageSprite(stylesheet.sprite);
this.sprite.setEventedParent(this);
this.setSprite(stylesheet.sprite);
}

this.glyphSource = new GlyphSource(stylesheet.glyphs);
Expand Down Expand Up @@ -312,6 +311,8 @@ class Style extends Evented {

this._updatedPaintProps = {};
this._updatedAllPaintProps = false;

this._updatedSprite = false;
}

/**
Expand Down Expand Up @@ -779,6 +780,23 @@ class Style extends Evented {
}
}

setSprite(sprite) {
if (this.sprite) {
this.sprite.setEventedParent(null);
this.spriteAtlas = new SpriteAtlas(1024, 1024);
}
this.sprite = new ImageSprite(sprite);
this.sprite.setEventedParent(this);
this._updatedSprite = true;

for (const layerId in this._layers) {
const layer = this._layers[layerId];
if (layer.type === 'symbol' && !this._updatedSources[layer.source]) {
this._updatedSources[layer.source] = 'reload';
}
}
}

// Callbacks from web workers

getIcons(mapId, params, callback) {
Expand Down