我在网页上集成了一个带有标记动画的地图。地图上有多个标记。我想实现这样的效果:当单击任何标记时,当前正在运行的其他标记动画应停止。
目前,我能够在单击标记时停止同一标记的动画。在有多个标记的情况下,必须获取某些标记对象。
到目前为止,我已经做到了这一点。 latlngarray是一个包含纬度和经度的对象格式数组。
目前,我能够在单击标记时停止同一标记的动画。在有多个标记的情况下,必须获取某些标记对象。
到目前为止,我已经做到了这一点。 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);
}}