gpt4 book ai didi

javascript - Google Maps API v3 标记掉落和反弹动画

转载 作者:数据小太阳 更新时间:2023-10-29 06:12:44 24 4
gpt4 key购买 nike

我从谷歌得到了这个修改过的示例代码

var stockholm = new google.maps.LatLng(59.32522, 18.07002);
var parliament = new google.maps.LatLng(59.327383, 18.06747);
var marker;
var map;

function initialize() {
var mapOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: stockholm
};

map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: parliament,
icon: '/img/marker.png'
});
google.maps.event.addListener(marker, 'click', toggleBounce);


setTimeout(function() { marker.setAnimation(google.maps.Animation.BOUNCE); }, 2000);

}

function toggleBounce() {

if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}

我想知道是否可以在 DROP 动画停止后将标记动画从 DROP 更改为 BOUNCE?

我设法使用 setTimeout() 函数更改了它,但它执行起来并不顺利。任何帮助将不胜感激。

最佳答案

尝试更改 google.maps.event.addListener(map, 'idle', function ()...) 上的标记动画 - 这将在添加标记后调用.

document.write('<script src="https://maps.googleapis.com/maps/api/js">\x3C/script>');

window.onload = function () {
// Create map
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 12,
center: new google.maps.LatLng(-33.87, 151.24),
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
}
});

// Create marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(-33.890542, 151.274856),
map: map,
animation: google.maps.Animation.DROP,
title: 'Bondi Beach'
});

// On idle, change marker animation to bounce
google.maps.event.addListener(map, 'idle', function () {
marker.setAnimation(google.maps.Animation.BOUNCE);
});
}
#map_canvas {
width: 300px;
height: 300px;
}
<div id="map_canvas"></div>

关于javascript - Google Maps API v3 标记掉落和反弹动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11961718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com