I think I must be missing something very basic here, but all I want to do is have toggle working for map services. When the checkbox is checked, show the layer and when the checkbox is unchecked, hide the layer. The showing the layer bit works, but the hide does not. I've tried a lot of different methods and the only one that works is removeAllLayers()?
function visibleDPLayers() {
var DPlayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis.mstn.govt.nz/ArcGIS/rest/services/DistrictPlan/MapServer");
map.addLayer(DPlayer);
if (legend.DPCheckbox.checked == true) {
alert ('show')
DPlayer.show();
}
else {
alert ('hide')
DPlayer.hide();
}
}
Yes your logic is a little scrambled (mixing visibility and adding layer). I would suggest having 2 functions, an add layer function and a toggle visibility function. Otherwise you will be adding your layer over and overso function visibleDPLayers() {
var DPlayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis.mstn.govt.nz/ArcGIS/rest/services/DistrictPlan/MapServer");
map.addLayer(DPlayer);
called from your initand then an onClick(toggleVis) functionfunction toggleVis(){
if (legend.DPCheckbox.checked == true) {
alert ('show')
DPlayer.show();
}
else {
alert ('hide')
DPlayer.hide();
}
}