Select to view content in your preferred language

Removing  KML Layers from the map

3496
3
Jump to solution
04-12-2012 09:36 AM
JamesVillanueva
Regular Contributor
I'm stumped on this one. I add a KML Layer to the map: http://www.climatehotmap.org/kml/chm.kml and it gets added as many different layers. After this occurs, I can not figure out how to remove them all from the map. Normal things like removing them one at a time or calling removeAllLayers doesn't seem to work. Any suggestions?
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
You're correct in that the KML uses several layers to display features from a KML file. But you can still treat a KMLLayer as a regular layer meaning you can pass it to map.removeLayer and all associated layers will be removed from the map. Here's an example:  http://jsfiddle.net/Zd8ne/

View solution in original post

0 Kudos
3 Replies
BetsySchenck-Gardner
Deactivated User
I haven't had much success with .removeAllLayers but I've used the .hide() instead to remove layers from being displayed on a map.  I add and hide layers all the time this way.  I took your kml link and was able to add it to the map, and then hide it from the map.
0 Kudos
derekswingley1
Deactivated User
You're correct in that the KML uses several layers to display features from a KML file. But you can still treat a KMLLayer as a regular layer meaning you can pass it to map.removeLayer and all associated layers will be removed from the map. Here's an example:  http://jsfiddle.net/Zd8ne/
0 Kudos
JamesVillanueva
Regular Contributor
Derek,

Your response makes sense. I got myself in trouble as I have a custom map widget that inherits from the original map. I had overriden the AddLayer and Addlayers to add custom functionality for tracking layers for use with in a Custom TOC. Your post helped me to understand I need to go back revise my means of tracking added layers in the TOC. Thanks for the help.
0 Kudos