Search code examples
google-maps-api-3markerclusterer

Markers disappear after animating


I use a google maps v3 with marker clusterer v3 to display 1000's of markers. I also have a side-panel that lists the titles of each marker. When a user hovers over a title in the panel I animate the corresponding marker, and I stop animating on mouseout.

This works fine when the marker isn't in a cluster. I have a problem when the marker is in a cluster.

If the marker is in a cluster I first change the marker's map object from null (previously set by markerClusterer so to hide the marker once it puts it in a cluster) to my map object, and then I animate the marker. Again, this works. It's on mouseout that I experience my problem.

On mouseout I set the marker animation to null and then set the marker's map object to null. This does what you would expect (hides the marker), but I can't get the marker to show again on any subsequent hover event. The marker still exists inside the appropriate cluster object, and I can call setMap() to set the marker's map property, but the marker still won't show up on the map. Here is the relevant code:

        if (event.type === 'mouseover' || event.type === 'mouseenter' ) {       
            if (!marker.getMap()) { //marker is in a cluster
                inCluster = true;
                marker.setMap(map)
            } else {
                inCluster = false
            };
            marker.setAnimation(google.maps.Animation.BOUNCE);
        } else {
            marker.setAnimation(null);
            if (inCluster == true) { //hide the clusterized marker
                marker.setMap(null)
            }
        };

If I comment-out the two setAnimation() calls, then the code will work and the marker can be displayed and then hidden as expected (just not animated). Also, when I play around with the console, I can display the marker out of the cluster, then I can animate it, then i can de-animate it, then I can hide it again, over-and-over. But, if I call setMap(null) before de-animating the marker, then I hit my bug.

So, the problem only exists when animation hasn't stopped prior to calling setMap(null). I've tried setting a timer to give the animation a few hundred milliseconds to stop before calling setMap, and this sometimes works, but other times it triggers other, even worse behavior.

Any help solving this would be greatly appreciated (and eagerly accepted)!


Solution

  • I've been experiencing thr same issue. It's a new bug in the API. I plan on using my enterprise account to create a case once I have a simple reproducable example.