admin管理员组文章数量:1345726
I know I can animate the "adding" of a marker on a google map, a la
Is there anyway I can do the reverse animation for removing the marker from the map? I'd like it to fly back up to the top of the map on marker removal... is that possible?
Here's my remove code so far (just removes it from the map, no animation):
// 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;
};
I know I can animate the "adding" of a marker on a google map, a la https://developers.google./maps/documentation/javascript/overlays#MarkerAnimations
Is there anyway I can do the reverse animation for removing the marker from the map? I'd like it to fly back up to the top of the map on marker removal... is that possible?
Here's my remove code so far (just removes it from the map, no animation):
// 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;
};
Share
Improve this question
edited Apr 16, 2012 at 18:37
Engineer
48.8k12 gold badges90 silver badges92 bronze badges
asked Apr 16, 2012 at 17:29
neezerneezer
20.6k33 gold badges129 silver badges222 bronze badges
1
- Doesn't seem to be possible via the standard google.maps.Animation class, as there are only 2 supported animations (BOUNCE and DROP). You will probabl have to make your own animation using normal javascript and moving the marker on the map.... Don't forget to switch off the shadow or handle it specially... – Tomas Commented Apr 16, 2012 at 17:39
2 Answers
Reset to default 13As google.maps.Animation does not support reverse animation of droping, you need to write your own script for animating the marker.
You could write something like this:
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);
}
})();
}
Here is DEMO:
My idea:
- create an animated GIF of a flying marker pin, which then fades away.
- on the marker delete event, swap
icon
to show the GIF - Since you created the GIF, you should know the animation time length. Then, setTimeout with this value to call setMap(null)
It might be preventing event propagation, which is one of many possible drawbacks.
本文标签: javascriptReverse animation for Google Map marker removalStack Overflow
版权声明:本文标题:javascript - Reverse animation for Google Map marker removal? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743813687a2543529.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论