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
much better circle approximation near poles
  • Loading branch information
mourner committed Jan 3, 2014
commit 06fb3ce6e4bab3a9ff3cf5fb71ed2370134db241
25 changes: 15 additions & 10 deletions src/layer/vector/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ L.Circle = L.CircleMarker.extend({

_project: function () {

var lng = this._latlng.lng,
var rad = Math.PI / 180,
lng = this._latlng.lng,
lat = this._latlng.lat,
map = this._map,

latR = 360 * this._mRadius / (2 * L.CRS.Earth.R * Math.PI),
top = map.latLngToLayerPoint([this._latlng.lat + latR, lng]),
bottom = map.latLngToLayerPoint([this._latlng.lat - latR, lng]),
p = this._point = top.add(bottom).divideBy(2),
newLat = map.layerPointToLatLng(p).lat,
lngR = latR / Math.cos(newLat * Math.PI / 180),
left = map.latLngToLayerPoint([newLat, lng - lngR]);
latR = (this._mRadius / L.CRS.Earth.R) / rad,
top = map.project([lat + latR, lng]),
bottom = map.project([lat - latR, lng]),
p = top.add(bottom).divideBy(2),
lat2 = map.unproject(p).lat,

this._radius = Math.max(p.x - left.x, 1);
this._radiusY = Math.max(p.y - top.y, 1);
lngR = Math.acos((Math.cos(latR * rad) - Math.sin(lat * rad) * Math.sin(lat2 * rad)) /
(Math.cos(lat * rad) * Math.cos(lat2 * rad))) / rad || 0,
left = map.project([lat2, lng - lngR]);

this._point = p.subtract(map.getPixelOrigin());
this._radius = Math.max(Math.round(p.x - left.x), 1);
this._radiusY = Math.max(Math.round(p.y - top.y), 1);

this._updateBounds();
}
Expand Down