【发布时间】:2021-09-20 00:05:25
【问题描述】:
我的网页上集成了一张带有标记动画的地图。我在地图上有多个标记。我想实现类似,当单击任何标记时,其他标记的动画应该停止当前正在运行。
目前我可以在标记点击时停止相同标记的动画。如果有多个标记,我应该得到一些标记对象。
到目前为止,我已经做到了。
latlngarray 是一个对象格式的经纬度数组。
var centerlatlng={center lat lng are here};
var zoomlevel=zoomlevel is here;
function initMap(){
map = new google.maps.Map(document.getElementById('map'),{
center: centerlatlng,
zoom: zoomlevel
});
if(latlngarray.length > 0){
for(i=0; i < latlngarray.length; i++){
marker = new google.maps.Marker({
position: latlngarray[i],
map: map
});
marker.addListener('click', function(){
toggleBounce(this);
map.setZoom(10);
map.setCenter(marker.getPosition());
});
}
}}
function toggleBounce(ele){
if(ele.getAnimation() !== null){
ele.setAnimation(null);
}else{
ele.setAnimation(google.maps.Animation.BOUNCE);
}}
【问题讨论】:
标签: jquery google-maps