diff --git a/src/style/style.js b/src/style/style.js index c0f80e4e046..7b5d410325e 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -515,10 +515,7 @@ class Style extends Evented { return this.fire(new ErrorEvent(new Error('An image with this name already exists.'))); } this.imageManager.addImage(id, image); - this._availableImages = this.imageManager.listImages(); - this._changedImages[id] = true; - this._changed = true; - this.fire(new Event('data', {dataType: 'style'})); + this._afterImageUpdated(id); } updateImage(id: string, image: StyleImage) { @@ -534,9 +531,14 @@ class Style extends Evented { return this.fire(new ErrorEvent(new Error('No image with this name exists.'))); } this.imageManager.removeImage(id); + this._afterImageUpdated(id); + } + + _afterImageUpdated(id: string) { this._availableImages = this.imageManager.listImages(); this._changedImages[id] = true; this._changed = true; + this.dispatcher.broadcast('setImages', this._availableImages); this.fire(new Event('data', {dataType: 'style'})); } diff --git a/test/integration/render-tests/runtime-styling/image-add-coalesce/expected.png b/test/integration/render-tests/runtime-styling/image-add-coalesce/expected.png new file mode 100644 index 00000000000..7e1f6d1b2a1 Binary files /dev/null and b/test/integration/render-tests/runtime-styling/image-add-coalesce/expected.png differ diff --git a/test/integration/render-tests/runtime-styling/image-add-coalesce/style.json b/test/integration/render-tests/runtime-styling/image-add-coalesce/style.json new file mode 100644 index 00000000000..3d6dc2fba2d --- /dev/null +++ b/test/integration/render-tests/runtime-styling/image-add-coalesce/style.json @@ -0,0 +1,45 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 64, + "height": 64, + "operations": [ + [ + "addImage", + "rocket", + "./image/rocket.png" + ], + [ + "addLayer", + { + "id": "geometry", + "type": "symbol", + "source": "geometry", + "layout": { + "icon-image": ["coalesce", + ["image", "non-existing-image1"], + ["image", "non-existing-image2"], + ["image", "rocket"], + ["image", "non-existing-image3"] + ] + } + } + ], + [ + "wait" + ] + ] + } + }, + "sources": { + "geometry": { + "type": "geojson", + "data": { + "type": "Point", + "coordinates": [0, 0] + } + } + }, + "layers": [] +}