我在我的网页上集成了带有标记动画的地图.我在地图中有多个标记.我希望实现类似的功能,当点击任何标记时,其他标记的动画应停止当前正在运行的动画.
目前,我可以在标记点击上停止相同标记的动画.在多个标记的情况下,我必须得到一些标记对象.
到目前为止我已经这样做了.
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);
}}
Run Code Online (Sandbox Code Playgroud)