From 9d98b86de1b74e57149d637522573abc0e0cc13e Mon Sep 17 00:00:00 2001 From: Javier Puerto Date: Wed, 15 Oct 2014 12:36:31 +0200 Subject: [PATCH] #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); + } } });