From a72cb694f4e4fc3fced8a9f2afd81c069b9acb27 Mon Sep 17 00:00:00 2001 From: Javier Puerto Date: Wed, 15 Oct 2014 11:48:24 +0200 Subject: [PATCH 1/4] Ignore netbeans project files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 496ee2c..ddb3e36 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +/nbproject From 9d98b86de1b74e57149d637522573abc0e0cc13e Mon Sep 17 00:00:00 2001 From: Javier Puerto Date: Wed, 15 Oct 2014 12:36:31 +0200 Subject: [PATCH 2/4] #28: Use map CRS if it is possible --- src/AnimatedMarker.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/AnimatedMarker.js b/src/AnimatedMarker.js index ab95e1f..6610863 100644 --- a/src/AnimatedMarker.js +++ b/src/AnimatedMarker.js @@ -26,7 +26,7 @@ L.AnimatedMarker = L.Marker.extend({ for (i=1;i this.options.distance) { while (dist > this.options.distance) { cur = new L.LatLng(cur.lat + dLat, cur.lng + dLng); - dist = cur.distanceTo(next); + dist = this._distance(cur, next); chunkedLatLngs.push(cur); } } else { @@ -48,6 +48,7 @@ L.AnimatedMarker = L.Marker.extend({ onAdd: function (map) { L.Marker.prototype.onAdd.call(this, map); + this._map = map; // Start animating when added to the map if (this.options.autoStart) { @@ -62,7 +63,7 @@ L.AnimatedMarker = L.Marker.extend({ // Normalize the transition speed from vertex to vertex if (this._i < len) { - speed = this._latlngs[this._i-1].distanceTo(this._latlngs[this._i]) / this.options.distance * this.options.interval; + speed = this._distance(this._latlngs[this._i-1], this._latlngs[this._i]) / this.options.distance * this.options.interval; } // Only if CSS3 transitions are supported @@ -108,6 +109,14 @@ L.AnimatedMarker = L.Marker.extend({ this.options.interval = 30; } this._i = 1; + }, + + _distance: function(cur, next) { + if (this._map.options.crs.distance) { + return this._map.options.crs.distance(cur, next); + } else { + return cur.distanceTo(next); + } } }); From 05fbf02ccce1e8b886142003ff132065452473c4 Mon Sep 17 00:00:00 2001 From: Javier Puerto Date: Tue, 21 Oct 2014 14:26:21 +0200 Subject: [PATCH 3/4] Restore TRANSITION style after animation ends. --- src/AnimatedMarker.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AnimatedMarker.js b/src/AnimatedMarker.js index 6610863..7b88ba6 100644 --- a/src/AnimatedMarker.js +++ b/src/AnimatedMarker.js @@ -79,6 +79,8 @@ L.AnimatedMarker = L.Marker.extend({ // Queue up the animation to the next next vertex this._tid = setTimeout(function(){ if (self._i === len) { + if (self._icon) { self._icon.style[L.DomUtil.TRANSITION] = ''; } + if (self._shadow) { self._shadow.style[L.DomUtil.TRANSITION] = ''; } self.options.onEnd.apply(self, Array.prototype.slice.call(arguments)); } else { self.animate(); From 65b0c890255a3157511a0eff60f95a0e71b1521c Mon Sep 17 00:00:00 2001 From: Javier Puerto Date: Tue, 21 Oct 2014 16:36:18 +0200 Subject: [PATCH 4/4] Remove optional onEnd callback and fires 'endanimation' event. --- src/AnimatedMarker.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/AnimatedMarker.js b/src/AnimatedMarker.js index 7b88ba6..7832e80 100644 --- a/src/AnimatedMarker.js +++ b/src/AnimatedMarker.js @@ -1,4 +1,5 @@ L.AnimatedMarker = L.Marker.extend({ + includes: L.Mixin.Events, options: { // meters distance: 200, @@ -6,8 +7,6 @@ L.AnimatedMarker = L.Marker.extend({ interval: 1000, // animate on add? autoStart: true, - // callback onend - onEnd: function(){}, clickable: false }, @@ -81,7 +80,7 @@ L.AnimatedMarker = L.Marker.extend({ if (self._i === len) { if (self._icon) { self._icon.style[L.DomUtil.TRANSITION] = ''; } if (self._shadow) { self._shadow.style[L.DomUtil.TRANSITION] = ''; } - self.options.onEnd.apply(self, Array.prototype.slice.call(arguments)); + self.fire('animationend'); } else { self.animate(); }