My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
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
Status:  Acknowledged
Owner:  [email protected]


Sign in to add a comment
 
Reported by [email protected], Dec 21, 2009
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...
Jan 7, 2010
#1 [email protected]
We've had this requested before, but the V3 API is not designed in such a way to
facilitate this.

Maintaining your own local collection of overlay objects may seem tedious, but I
question whether it really is needlessly complicated.  There are also other use cases
and benefits for keeping a reference to these objects.

Let's leave this an open question for now and revisit when it accrues more stars.
Status: Started
Owner: [email protected]
Feb 6, 2010
#2 [email protected]
I would expect some kind of key eg, or even a DOM Id
eg
map.clearOverlay("my-id");
Mar 24, 2010
#3 [email protected]
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
#4 [email protected]
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
#5 [email protected]
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
#6 [email protected]
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
#7 [email protected]
Daniel, as far as I'm concerned this (non)issue is totally dead to me now. Thanks for 
the reply. 
Apr 5, 2010
#8 [email protected]
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
#9 [email protected]
(No comment was entered for this change.)
Owner: thor.mitchell
Jul 1, 2010
#10 [email protected]
(No comment was entered for this change.)
Jul 27, 2010
#11 [email protected]
This simply needs to be added to the API. There shouldn't even be a discussion about it.
Jul 27, 2010
#12 [email protected]
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
#13 [email protected]
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
#14 [email protected]
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
#15 [email protected]
 Issue 3607  has been merged into this issue.
Jul 30, 2012
#16 [email protected]
(No comment was entered for this change.)
Sign in to add a comment

Powered by Google Project Hosting