From 444e0dba7c7abfc62e3da68206dfeb9da2580cb5 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 13 Jul 2012 12:11:20 +0300 Subject: [PATCH] scale control fixes, closes #674 --- src/control/Control.Scale.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/control/Control.Scale.js b/src/control/Control.Scale.js index 76a506353..1d60e94ef 100644 --- a/src/control/Control.Scale.js +++ b/src/control/Control.Scale.js @@ -34,16 +34,15 @@ L.Control.Scale = L.Control.extend({ _update: function () { var bounds = this._map.getBounds(), centerLat = bounds.getCenter().lat, - - left = new L.LatLng(centerLat, bounds.getSouthWest().lng), - right = new L.LatLng(centerLat, bounds.getNorthEast().lng), + halfWorldMeters = new L.LatLng(centerLat, 0).distanceTo(new L.LatLng(centerLat, 180)), + dist = halfWorldMeters * (bounds.getNorthEast().lng - bounds.getSouthWest().lng) / 180, size = this._map.getSize(), options = this.options, - maxMeters = 0; + maxMeters = 0; if (size.x > 0) { - maxMeters = left.distanceTo(right) * (options.maxWidth / size.x); + maxMeters = dist * (options.maxWidth / size.x); } if (options.metric && maxMeters) { @@ -90,7 +89,7 @@ L.Control.Scale = L.Control.extend({ var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1), d = num / pow10; - d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 2 ? 2 : 1; + d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1; return pow10 * d; }