Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps - markers flash before bounce onmouseover

I've built a Google map where the markers bounce on rollover of some external links. I've created this short function to bounce the marker:

function makeBounce(marker) {
        marker.setAnimation(google.maps.Animation.BOUNCE);
        setTimeout(function(){ marker.setAnimation(null); }, 750);
}

and I'm using this to execute it:

<a onmouseover="javascript:map.panToBounds(bounds);makeBounce(markersArray[1]);"  href="javascript:google.maps.event.trigger(markersArray[1], 'click');">Marker name</a>

What I'm noticing is that just before the markers bounce they flash. It's almost imperceptible, but it's enough to be really annoying (especially since Google's own blog post launching bouncing markers is very smooth: http://googlegeodevelopers.blogspot.com/2010/12/map-markers-they-move.html).

I've created a JS Fiddle here which demonstrates it: http://jsfiddle.net/RmDuz/ (roll over the blue links to see the problem).

I've tried it in Firefox9 and Chrome 16 and the problem is there in both.

Any thoughts?

The problem seems to be that the marker image is dynamically (re)loaded just before the bounce, because in Chrome I see the 'no image' box just before the marker reappears then bounces.

EDIT: I've altered the code to make use of a maps API listener instead of a Javascript function, in the hope that the API code might be a bit more efficient, but no joy :(

    google.maps.event.addListener(marker, 'dblclick', (function(marker, i) {
        return function() {
            marker.setAnimation(google.maps.Animation.BOUNCE);
            setTimeout(function(){ marker.setAnimation(null); }, 750);
        }
    })(marker, i));

I'm using dblclick because I don't want mouseover, which would mean the animation was triggered when the markers are rolled over. I only want the animation triggered when the external links are rolled over:

<a onmouseover="javascript:google.maps.event.trigger(markersArray[1], 'dblclick');">Link name</a>

I've updated the JS Fiddle to reflect this: http://jsfiddle.net/RmDuz/1/

like image 515
melat0nin Avatar asked Nov 18 '25 06:11

melat0nin


1 Answers

I ran into this problem as well. It turns out setting MarkerOptions optimized: false or draggable: true will stop the markers from flashing before they animate.

A non-optimized marker:

// Create a non-optimized marker
var marker = new google.maps.Marker({
    position: new google.maps.LatLng(39.107182, -123.501868),
    map: map,
    optimized: false // stops the marker from flashing
});

// Bounce once
marker.setAnimation(google.maps.Animation.BOUNCE);
marker.setAnimation(null);

A draggable marker:

// Create a draggable marker
var draggableMarker = new google.maps.Marker({
    position: new google.maps.LatLng(39.107182, -123.501868),
    map: map,
    draggable: true // stops the marker from flashing
});

// Bounce once
draggableMarker.setAnimation(google.maps.Animation.BOUNCE);
draggableMarker.setAnimation(null);

If you take a look at the Google example, you'll see that they set draggable: true.

like image 119
lazd Avatar answered Nov 19 '25 20:11

lazd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!