0

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.

1
  • are you refreshing after removing the layer ?
    – radouxju
    Commented Feb 9, 2016 at 14:45

2 Answers 2

1

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);
}
0

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):

https://jsfiddle.net/gavinr/b1ay90o1/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.