This PR fixes an issue where, if a layer has an opacity set on the initial render, it would be discarded.
The problem was located in the Mapbox plugin, specifically in the setRender method. On instantiation, all the layers are added via the add method of LayerManager. This method calls requestLayer, which, among other things, calls the setOpacity and setRender methods of the plugin, in this order.
In setOpacity, the *-opacity paint properties are set accordingly to the top-level opacity property passed to the layer-manager. This is done using Mapbox' setPaintProperty method. Nevertheless, setRender would set the properties again (and others unrelated too) using setPaintProperty, disregarding the top-level opacity property. It would effectively overwrite the properties setOpacity updated.
To fix the issue, this PR adds a new method in the plugin, computePaintPropertyValue, which ensures that if a *-opacity property is to be set, its value will depend on the top-level opacity property.
Testing instructions
Open sandbox/src/layers.js
Add an opacity property with the value 0 to the “Protected areas” layer (after line 110):
Once the sandbox has opened in your browser, make sure the protected areas are not showing on the map. The legend will display the correct information patch or not.
This PR fixes an issue where, if a layer has an opacity set on the initial render, it would be discarded.
The problem was located in the Mapbox plugin, specifically in the
setRender
method. On instantiation, all the layers are added via theadd
method ofLayerManager
. This method callsrequestLayer
, which, among other things, calls thesetOpacity
andsetRender
methods of the plugin, in this order.In
setOpacity
, the*-opacity
paint properties are set accordingly to the top-levelopacity
property passed to the layer-manager. This is done using Mapbox'setPaintProperty
method. Nevertheless,setRender
would set the properties again (and others unrelated too) usingsetPaintProperty
, disregarding the top-levelopacity
property. It would effectively overwrite the propertiessetOpacity
updated.To fix the issue, this PR adds a new method in the plugin,
computePaintPropertyValue
, which ensures that if a*-opacity
property is to be set, its value will depend on the top-levelopacity
property.Testing instructions
sandbox/src/layers.js
opacity
property with the value0
to the “Protected areas” layer (after line 110):yarn start:sandbox
Once the sandbox has opened in your browser, make sure the protected areas are not showing on the map. The legend will display the correct information patch or not.
Pivotal Tracker
Not tracked.