i have this code to detect change on my checkbox.
if is true turn on layer if is not true turn off layer
in my map service the layer have id 14
$(document).ready(function() {
$('#checkboxOrtofoto10m').change(function() {
if(this.checked) {
Layers.findSublayerById(14).labelsVisible = true;
}
});
in console mark this
any suggestions?
Solved! Go to Solution.
Here is a sample that toggles sublayer visibility: MapImageLayer - Toggle sublayer visibility | ArcGIS API for JavaScript 4.13
Here is a sample that toggles sublayer visibility: MapImageLayer - Toggle sublayer visibility | ArcGIS API for JavaScript 4.13
Hmm, I tested this functionality as a sanity check, and it is possible to do.
Test app (toggle state labels on and off with the button at the bottom)
https://codepen.io/noash/pen/MWWbWZy
Perhaps the MapServer you're using doesn't support dynamic layers? You need it to in order to make changes dynamically.
When you inspect the MapServer from REST, do you see:
Supports Dynamic Layers: true
?
Thank you for answering if it supports Dynamic Layers, my quick stop solution that works for me is to load the map again, for now I will stay with this solution later I will see the performance.
I have the solution i only need findSublayerById function .
$('#checkbox').change(function(event) {
var idcheck = event.target.getAttribute("data-id");
if(idcheck){
var sublayer = Layers.findSublayerById(parseInt(idcheck));
sublayer.visible = !sublayer.visible;
}
});