Select to view content in your preferred language

Remove Layer

1155
1
01-11-2012 12:34 PM
deleted-user-K_IRAXrpGKsG
Deactivated User
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;
0 Kudos
1 Reply
StephenLead
Honored Contributor
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.

Once you'd found the correct layer, you can remove it using map.removeLayer(layer)

Steve
0 Kudos