I am using arcgis javascript api . I want to remove a recently added layer , i wrote like this
var a = map.layerIds;
var b = map.getLayer(a[2]);
map.removeLayer(b);
But I am not able to remove any layer.
I am using arcgis javascript api . I want to remove a recently added layer , i wrote like this
var a = map.layerIds;
var b = map.getLayer(a[2]);
map.removeLayer(b);
But I am not able to remove any layer.
try this
for (var j = 0, k = map.layerIds.length; j < k; j++) {
var currentLayer = map.getLayer(map.layerIds[j]);
if (currentLayer.id == "yourLayerID") {
map.removeLayer(currentLayer);
}
That code should work. I'm guessing you don't have the right index of your a
variable. Here's a jsfiddle showing your code working (click the "remove" button to run your code and see the layer get removed):