Toggling layer visibility with a checkbox and updateTriggers
See original GitHub issueDescription
I am facing issue with implementing a checkbox to turn on or off a layer in pure js using updatetriggers. I have looked at the documentation here and here.
I have this layer with the visible property controlled by a function “enabled”. I added the updateTriggers for the visible property.
const myIconlayer = new IconLayer({
id: 'icon-layer',
data:educationData.features,
pickable: true,
iconAtlas: './schooltr.png',
iconMapping: ICON_MAPPING,
getIcon: d => 'marker',
visible: enabled,
updateTriggers: {
visible: [true, false],
},
sizeScale: 6,
getPosition: d => d.geometry.coordinates,
getSize: d => 5,
getColor: d => [Math.sqrt(1000), 140, 0],
});
deckgl.setProps({
layers: [hexagonLayer,myIconlayer],
viewState: Object.assign({}, currentViewState)
});
I am updating the visibility with the following enabled function that reads a checkbox element id.
function enabled() {
// Get the checkbox
var checkBox = document.getElementById("Education");
// If the checkbox is checked, display return true
if (checkBox.checked == true){
console.log("checkbox true")
return true
} else {
console.log("checkbox false")
return false
}
}
However nothing happens on the map, it doesnt seem to change the visibility of the layer. However when i do it manually (replacing with false and true the visible prop) it works.
Here is an example of the working app. https://covmob-website.herokuapp.com/
What am I missing to make the checkbox turn on and off the visibility of the layers?
Environment (please complete the following information):
- Framework Version: deck.gl latest
- Browser Version: Chrome Version 81.0.4044.129
- OS: W10 64bit
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
Layer Class - deck.gl
The Layer class is the base class of all deck.gl layers, and it provides a ... Under most circumstances, using visible prop to...
Read more >How to easily toggle layers visibility with a checkbox control ...
One of them is the ability to hide an object from the viewport, but have it show up in the render. There are...
Read more >Toggle Layer Visibility With a Checkbox Control in After Effects
Great tutorials! But I think “layer visibility” (your title) is the eye icon on the left of a layer, which can't be controlled...
Read more >toggle visibility of a Layer in Openlayers 3(!) with a Checkbox
You need to call setVisibility(true/false) on the layer. setVisibility. All you are doing in your code is changing the value of static ...
Read more >Solved: Toggle Feature Layer with a checkbox - Esri Community
Solved: What is the simplest way to use a checkbox input to toggle the visibility of a featureLayer?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, this is how I worked it out. Also checkout the source code for this example https://deck.gl/gallery/hexagon-layer. renderlayer function and also you can have a look at http://sets-cloud.com/covrex/
You have the
renderlayer()
function:You are correct that layer props cannot be changed after creation. Even
updateTriggers
cannot be changed. You must create a new instance of the layer if you want to update a prop. See this example.You can learn more about the reactive programming model in https://deck.gl/#/documentation/developer-guide/using-layers