From 97ae0b626d5ca787402d9624215040a6e9186b92 Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Thu, 17 Nov 2016 22:13:05 -0800 Subject: [PATCH] Add style#setSprite method Closes #2058 --- debug/dark-v9.js | 2 +- js/style/style.js | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/debug/dark-v9.js b/debug/dark-v9.js index d32abbf194f..887285fc306 100644 --- a/debug/dark-v9.js +++ b/debug/dark-v9.js @@ -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": [ { diff --git a/js/style/style.js b/js/style/style.js index 060e50b2121..784b71d4d1c 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -34,9 +34,9 @@ const supportedDiffOperations = util.pick(diff.operations, [ 'removeSource', 'setLayerZoomRange', 'setLight', - 'setTransition' + 'setTransition', + 'setSprite' // 'setGlyphs', - // 'setSprite', ]); const ignoredDiffOperations = util.pick(diff.operations, [ @@ -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); @@ -312,6 +311,8 @@ class Style extends Evented { this._updatedPaintProps = {}; this._updatedAllPaintProps = false; + + this._updatedSprite = false; } /** @@ -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) {