Skip to content

Commit

Permalink
Supoort marker animation. Fixes #197
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Sep 25, 2015
1 parent cca29b8 commit 42b4158
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions google-map-marker.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,23 @@
</dom-module>

<script>

(function() {

function setupDragHandler_() {
if (this.draggable) {
this.dragHandler_ = google.maps.event.addListener(
this.marker, 'dragend', onDragEnd_.bind(this));
} else {
google.maps.event.removeListener(this.dragHandler_);
this.dragHandler_ = null;
}
}

function onDragEnd_(e, details, sender) {
this.latitude = e.latLng.lat();
this.longitude = e.latLng.lng();
}

Polymer({

is: 'google-map-marker',
Expand All @@ -53,45 +68,53 @@
* @param {google.maps.MouseEvent} event The mouse event.
* @event google-map-marker-click
*/

/**
* Fired when the marker icon was double clicked. Requires the clickEvents attribute to be true.
* @param {google.maps.MouseEvent} event The mouse event.
* @event google-map-marker-dblclick
*/

/**
* Fired for a mousedown on the marker. Requires the mouseEvents attribute to be true.
* @event google-map-marker-mousedown
* @param {google.maps.MouseEvent} event The mouse event.
*/

/**
* Fired when the DOM `mousemove` event is fired on the marker. Requires the mouseEvents
* attribute to be true.
* @event google-map-marker-mousemove
* @param {google.maps.MouseEvent} event The mouse event.
*/

/**
* Fired when the mouse leaves the area of the marker icon. Requires the mouseEvents attribute to be
* true.
* @event google-map-marker-mouseout
* @param {google.maps.MouseEvent} event The mouse event.
*/

/**
* Fired when the mouse enters the area of the marker icon. Requires the mouseEvents attribute to be
* true.
* @event google-map-marker-mouseover
* @param {google.maps.MouseEvent} event The mouse event.
*/

/**
* Fired for a mouseup on the marker. Requires the mouseEvents attribute to be true.
*
* @event google-map-marker-mouseup
* @param {google.maps.MouseEvent} event The mouse event.
*/

/**
* Fired for a rightclick on the marker. Requires the clickEvents attribute to be true.
* @event google-map-marker-rightclick
* @param {google.maps.MouseEvent} event The mouse event.
*/

properties: {
/**
* A Google Maps marker object.
Expand Down Expand Up @@ -161,13 +184,24 @@
value: null,
reflectToAttribute: true
},

/**
* The marker's latitude coordinate.
*/
latitude: {
type: Number,
value: null,
reflectToAttribute: true
},

/**
* A animation for the marker. "DROP" or "BOUNCE". See
* https://developers.google.com/maps/documentation/javascript/examples/marker-animations.
*/
animation: {
type: String,
value: null,
observer: '_animationChanged'
}
},

Expand Down Expand Up @@ -231,6 +265,12 @@
}
},

_animationChanged: function() {
if (this.marker) {
this.marker.setAnimation(google.maps.Animation[this.animation]);
}
},

_iconChanged: function() {
if (this.marker) {
this.marker.setIcon(this.icon);
Expand Down Expand Up @@ -293,6 +333,7 @@
lng: parseFloat(this.longitude)
},
title: this.title,
animation: google.maps.Animation[this.animation],
draggable: this.draggable,
visible: !this.hidden,
icon: this.icon,
Expand Down Expand Up @@ -339,19 +380,5 @@
}
});

function setupDragHandler_() {
if (this.draggable) {
this.dragHandler_ = google.maps.event.addListener(
this.marker, 'dragend', onDragEnd_.bind(this));
} else {
google.maps.event.removeListener(this.dragHandler_);
this.dragHandler_ = null;
}
}

function onDragEnd_(e, details, sender) {
this.latitude = e.latLng.lat();
this.longitude = e.latLng.lng();
}
})();
</script>

0 comments on commit 42b4158

Please sign in to comment.