I would like to know how I can check if I have an existing Map Layer before I call map.removeLayer(layer)
. I am having an issue because I am calling that even if there isn't one to remove.
if (document.getElementById('layer').checked) {
layer = new esri.layers.ArcGISDynamicMapServiceLayer("---url here---", { "opacity": 1 });
map.addLayer(layer);
}
else {
if(map.layerIds.contains(
map.removeLayer(layer);
}
If the box is unchecked, it will try to remove a non-existing layer. How do I get around this?