Skip to content

Commit

Permalink
openplans#28: Use map CRS if it is possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuerto committed Oct 15, 2014
1 parent a72cb69 commit 9d98b86
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/AnimatedMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ L.AnimatedMarker = L.Marker.extend({
for (i=1;i<len;i++) {
var cur = latlngs[i-1],
next = latlngs[i],
dist = cur.distanceTo(next),
dist = this._distance(cur, next),
factor = this.options.distance / dist,
dLat = factor * (next.lat - cur.lat),
dLng = factor * (next.lng - cur.lng);

if (dist > 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 {
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}

});
Expand Down

0 comments on commit 9d98b86

Please sign in to comment.