GoogleWebComponents / google-map

Google Maps web components

Home Page:https://elements.polymer-project.org/elements/google-map

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Calling map.clear() does not correctly remove marker nodes.

runia1 opened this issue · comments

Say you have a google-map with the "fit-to-markers" attribute set, and some markers on it all in a specific city.. Let's say Seattle. Then you want to clear the markers off the map and append some other markers all in a totally different city, let's say New York City. Calling m.clear() WILL remove the current markers, but after appending the new markers all in New York to the map,,, the map zooms out to show (fit) both Seattle and New York, even though there are no Markers in Seattle anymore.

This behavior got me thinking that maybe the clear() method only removes the graphical representation of the current markers and does not actually remove the marker dom nodes. Thus when new markers are appended and the map auto-fits to show all the markers, it has to zoom way out because there are some invisible markers in seattle still.

I can verify that this is the case,, instead of calling map.clear() I instead loop and remove all marker nodes... while(map.firstChild) Polymer.dom(map).removeChild(map.firstChild);
This works and when new markers are added the auto-fit is zoomed in to New York.

Please correct the way clear() works. Shouldn't take all that long. If you want I can do a PR, just let me know, but it may be faster for one of you to just do it.