I know I can animate the "adding" of a marker on a google map, a la https://developers.google.com/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;
};
Click the marker to reveal the editing options. Click the "Delete" link in the lower-left corner of the dialog box.
If you want to animate marker back-and-forth, just toggle setPosition each second. setTimeout(function() { var newPosition = /* select new position */ marker. setPosition(newPosition) }, 1000);
Inside the Info Window of the marker, there's an HTML button (Delete) which when clicked triggers the DeleteMarker JavaScript function. This function accepts the ID of the marker as a parameter and using this ID the selected marker is removed from the Map. };
If you want to remove the pin from Google Maps, simply right click on it and select "Remove this destination." Poof, it's gone.
As 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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With