| Issue 2040: | Feature Request: Easy way to remove all Overlays / Markers | |
| 44 people starred this issue and may be notified of changes. | Back to list |
Please could you add in map.clearOverlays() as per the v2 API to make the code for constantly updating maps simpler. The only current way (as far as I know) is to store all the current markers in an array, then set them all to null and then add the updated ones back which seems needlessly complicated...
Feb 6, 2010
I would expect some kind of key eg, or even a DOM Id
eg
map.clearOverlay("my-id");
Mar 24, 2010
I'd certainly like a map.clearMarkers() call. I have maps that can display hundreds of markers within a given area, all taken from a database. By using object literals and events, there's absolutely no need to keep a record of the markers after they've been initialised. Storing them all in some hideous array would just be nasty.
Mar 25, 2010
Storing all your markers in an Array may seem nasty, but there are no performance benefits from not storing them. Also, it's fairly trivial to write a 4-line function which iterates through the collection of Overlay objects and adds/removes them from the Map. http://gmaps-samples-v3.googlecode.com/svn/trunk/clear-all-overlays/clear-all-overlays.html function toggleOverlays(overlays, enable) { for (var n = 0, overlay; overlay = overlays[n]; n++) { overlay.setMap(enable ? map : null); } } Here's a different idea. Instead of clearing all Overlays from the map and then creating new ones, is it possible to reuse them instead? The same applies to InfoWindows.
Status:
NeedsMoreInfo
Mar 28, 2010
Personally I agree with Daniel. making a function(s) to remove all that you added to the map is pretty easy and quick to execute. I've written similar functions to do the same thing. That said having a optimized built-in function would be nice. Not necessary but nice.
Mar 31, 2010
Thanks for your comment Ian. I'm just not convinced there's much to optimize by building this function into the API. There's no getting around having to store all Overlay objects into a global collection variable. Either we give this responsibility to developers, or we add additional code to the core API to do this for them. However, some consequences could result: 1) Additional code means additional bytes, increasing the size of the JS file 2) Additional variable is added to the global namespace, affecting all maps developers regardless of whether they need a 'clear' function
Mar 31, 2010
Daniel, as far as I'm concerned this (non)issue is totally dead to me now. Thanks for the reply.
Apr 5, 2010
Thanks for letting me know Ian. Regardless, it looks like this commonly asked feature is starting to pick up some traction regarding 'Stars'. We'll re-evaluate our decision with including this feature as part of the core API.
Status:
Acknowledged
Labels: Internal-2572069
Jun 29, 2010
(No comment was entered for this change.)
Owner:
thor.mitchell
Jul 27, 2010
This simply needs to be added to the API. There shouldn't even be a discussion about it.
Jul 27, 2010
Absolutely. Then you don't have to keep an own array of markers. Although having one is probably a good practice, but not neccessarily needed. (in my opinion) :)
Jan 28, 2011
There's absolutely no need for this. In any application of decent complexity I'm going to be storing references to my markers and map overlays in my own way so that I can manipulate them as needed. Having another copy maintained in the core API is simply unnecessary and wasteful.
Jun 10, 2011
This seems to be a very specific use case because removing a marker would usually depend on a predicate. Even the original request is talking about "add[ing] the updated ones back", which acknowledges that the requested function would remove markers that should not be removed. So, why not just write that 4-line custom function to remove what you don't need, then simply update the rest?
Sep 8, 2011
Issue 3607 has been merged into this issue. |
|
| ► Sign in to add a comment |
Owner: [email protected]