mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-20 14:34:38 +00:00
scale control fixes, closes #674
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user