From 6ce2f5e8b6810c997d01f14d645539afc9e2800c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Sat, 4 Jul 2020 18:03:12 +0200 Subject: [PATCH 1/3] Update the worker images once an image is added or removed. --- src/style/style.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/style/style.js b/src/style/style.js index c0f80e4e046..9e845b8be60 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -518,6 +518,7 @@ class Style extends Evented { 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'})); } @@ -537,6 +538,7 @@ class Style extends Evented { 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'})); } From 1f62a195422e4a9d5896c32bb66c29af841036dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Sat, 4 Jul 2020 18:24:36 +0200 Subject: [PATCH 2/3] Factorize the {add,remove}Image code. --- src/style/style.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/style/style.js b/src/style/style.js index 9e845b8be60..7b5d410325e 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -515,11 +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.dispatcher.broadcast('setImages', this._availableImages); - this.fire(new Event('data', {dataType: 'style'})); + this._afterImageUpdated(id); } updateImage(id: string, image: StyleImage) { @@ -535,6 +531,10 @@ 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; From 97642d0b9b4382283a8fd24d58c10244d43152c7 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Mon, 3 Aug 2020 10:23:42 -0700 Subject: [PATCH 3/3] Add render test coverage for image coalesce fallback --- .../image-add-coalesce/expected.png | Bin 0 -> 909 bytes .../image-add-coalesce/style.json | 45 ++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/integration/render-tests/runtime-styling/image-add-coalesce/expected.png create mode 100644 test/integration/render-tests/runtime-styling/image-add-coalesce/style.json 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 0000000000000000000000000000000000000000..7e1f6d1b2a1ca45c655f18a76abe0b96c2971e04 GIT binary patch literal 909 zcmV;819JR{P)mT5I z6JtWqgqScBl@J}6m^hn3kvJB%0NWUDvl(-@(RTfDz20Nv|8O@FpU($E2qAi`Y`I0#@TfFOXfWm#!m*U!QwDjosMJYd=O$s3b}1DVP7Hq$JH zt+Jyg6aM0v_jmgMoP|qNYyoDbI<9L1@b>hb+`E^5UG2U-R|scK_T>r=3S~xr7ZZR6 zxJbnoAR?{{S8BE4KW?lIU%dR!-t^6iI=xauTN5D`0zw9$2dKu(n{bf|4>^vrkBFWD z5CIUMxVkntdTC|! zm-*l_W+qit@266!Ya=6{(cIkTKrE*FcO;F1RjwL~Sxc|gKpREi)x+WZsW;lb_bJNf zM6?Qk;4%d+BO*qf<2ZYkvi3*kMzhDxU0CXjMg66duWX+`)Ems_N`M1E(-aWV10s6B z%mjepG6fzXqQPIr&3&_r6=m{PF?M$@kK_}L^L<@G^VT|$Y*r9zRPz9Gs3RhV2UK`x z4{STqv$tXG#L@U{TZi!lfK~#Y>y9fpKG0900000NkvXXu0mjfZQz~x literal 0 HcmV?d00001 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": [] +}