scale control fixes, closes #674

This commit is contained in:
Vladimir Agafonkin
2012-07-13 12:11:20 +03:00
parent 7abe4c7d70
commit 444e0dba7c

View File

@ -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;
}