I have a very simple question. How do I simply remove a layer with a switch function? My below function adds the layer twoYear to the map but doesn't remove the sixMonth.
switch (layerSwitchValue) {
case "6Month":
break;
case "2year":
map.addLayers([twoYear]);
map.removeLayers([sixMonth]);
break;
As far as I can see, there isn't a removeLayers() option (to remove an array of layers) on the map object. Instead, there is a removeLayer() option (to remove a single layer).
So you could iterate through each layer on the map to find the correct layer. You can iterate through all of the tiled/dynamic layers using map.layerIds and through all of the feature layers using map.graphicsLayerIds.