0

I am attempting to remove a GraphicsLayer that was added into the map. This GraphicsLayer was added with var resultsGraphics = new GraphicsLayer({ id: 'resultsGraphics' }); after a map tool is opened, and needs to be removed when the tool is closed. I have tried map.removeLayer('resultsGraphics') which doesn't work, and baffles me that it doesn't because map.getLayer('resultsGraphics') works just fine.

2

map.removeLayer() function takes a layer object as an input parameter. So you need to do something like this:

map.removeLayer(resultsGraphics); // passing the variable

Or if you'd like to use the layer ID:

map.removeLayer(map.getLayer('resultsGraphics'));
  • Didn't think about that because I thought map.removeLayer()'s only parameter was the layer's ID. – Pyro Mar 26 at 14:43
  • Would just map.removeLayer(resultsGraphics) have worked (using the variable instead of the name in quotes)? – kenbuja Mar 26 at 20:45
  • Great point @kenbuja ! Added that option. Thanks – GavinR Mar 27 at 3:18

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.