javascript - Google maps - markers flash before bounce onmouseover - Stack Overflow

I've built a Google map where the markers bounce on rollover of some external links. I've cre

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: .html).

I've created a JS Fiddle here which demonstrates it: / (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: /

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./2010/12/map-markers-they-move.html).

I've created a JS Fiddle here which demonstrates it: http://jsfiddle/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/RmDuz/1/

Share Improve this question edited Jun 20, 2020 at 22:13 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 7, 2012 at 15:11 melat0ninmelat0nin 8791 gold badge16 silver badges38 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744206518a4563130.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信