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.

  • are you refreshing after removing the layer ? – radouxju Feb 9 '16 at 14:45
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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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