我知道我可以动画在Google地图上添加标记,la https://developers.google.com/maps/documentation/javascript/overlays#MarkerAnimations
无论如何,我可以使用反向动画从地图中删除标记吗?我希望它能够在删除标记时飞回地图的顶部......这可能吗?
到目前为止,这是我的删除代码(只是将其从地图中删除,没有动画):
// TODO figure out if there is a way to animate this removal, like the add
$.contextualMap.prototype.removeMarker = function(m) {
m.mapMarker.setMap(null);
m.mapMarker = null;
};
答案 0 :(得分:11)
由于google.maps.Animation不支持删除的反向动画,因此您需要编写自己的脚本来为标记设置动画。
你可以这样写:
function removeMarkerWithAnimation(map, marker){
(function animationStep(){
//Converting GPS to World Coordinates
var newPosition = map.getProjection().fromLatLngToPoint(marker.getPosition());
//Moving 10px to up
newPosition.y -= 10 / (1 << map.getZoom());
//Converting World Coordinates to GPS
newPosition = map.getProjection().fromPointToLatLng(newPosition);
//updating maker's position
marker.setPosition( newPosition );
//Checking whether marker is out of bounds
if( map.getBounds().getNorthEast().lat() < newPosition.lat() ){
marker.setMap(null);
}else{
//Repeating animation step
setTimeout(animationStep,10);
}
})();
}
这是DEMO:
答案 1 :(得分:-1)
我的想法:
icon
以显示GIF 它可能会阻止事件传播,这是许多可能的缺点之一。