Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better geodesy handling #2345

Merged
merged 16 commits into from
Jan 3, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify calculations in scale control
  • Loading branch information
mourner committed Jan 2, 2014
commit ea1402ec4fb7511e5ad366523a1c4f4cc77c0bf4
20 changes: 9 additions & 11 deletions src/control/Control.Scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,21 @@ L.Control.Scale = L.Control.extend({
},

_update: function () {
var bounds = this._map.getBounds(),
centerLat = bounds.getCenter().lat,
halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
dist = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180,
var map = this._map,
y = map.getSize().y / 2;

size = this._map.getSize(),
options = this.options,
maxMeters = size.x > 0 ? dist * (options.maxWidth / size.x) : 0;
var maxMeters = L.CRS.Earth.distance(
map.containerPointToLatLng([0, y]),
map.containerPointToLatLng([this.options.maxWidth, y]));

this._updateScales(options, maxMeters);
this._updateScales(maxMeters);
},

_updateScales: function (options, maxMeters) {
if (options.metric && maxMeters) {
_updateScales: function (maxMeters) {
if (this.options.metric && maxMeters) {
this._updateMetric(maxMeters);
}
if (options.imperial && maxMeters) {
if (this.options.imperial && maxMeters) {
this._updateImperial(maxMeters);
}
},
Expand Down