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
Show file tree
Hide file tree
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
Next Next commit
use projected coordinates in Circle, close #1465
  • Loading branch information
mourner committed Jan 2, 2014
commit 6940b5bac9f80fa6f6af488dcd1bed9fbb895f0e
2 changes: 2 additions & 0 deletions debug/map/simple-proj.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

map.addLayer(grid);

L.circle([0, 0], 100, {color: 'red'}).addTo(map);

</script>
</body>
</html>
28 changes: 10 additions & 18 deletions src/layer/vector/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,26 @@ L.Circle = L.CircleMarker.extend({
},

getBounds: function () {
var rlng = this._getLngRadius(),
rlat = this._getLatRadius(),
latlng = this._latlng;
var half = [this._radius, this._radius];

return new L.LatLngBounds(
[latlng.lat - rlat, latlng.lng - rlng],
[latlng.lat + rlat, latlng.lng + rlng]);
this._map.layerPointToLatLng(this._point.subtract(half)),
this._map.layerPointToLatLng(this._point.add(half)));
},

setStyle: L.Path.prototype.setStyle,

// TODO Earth hardcoded, move into projection code!
_project: function () {
var lngRadius = this._getLngRadius(),
latlng = this._latlng,
pointLeft = this._map.latLngToLayerPoint([latlng.lat, latlng.lng - lngRadius]);
var crs = this._map.options.crs,
p1 = crs.project(this._latlng),
latlng2 = crs.unproject(p1.subtract([this._mRadius, 0]));

this._point = this._map.latLngToLayerPoint(latlng);
this._radius = Math.max(this._point.x - pointLeft.x, 1);
this._updateBounds();
},
var pointLeft = this._map.latLngToLayerPoint(latlng2);

_getLatRadius: function () {
return (this._mRadius / 40075017) * 360;
},
this._point = this._map.latLngToLayerPoint(this._latlng);
this._radius = Math.max(this._point.x - pointLeft.x, 1);

_getLngRadius: function () {
return this._getLatRadius() / Math.cos((Math.PI / 180) * this._latlng.lat);
this._updateBounds();
}
});

Expand Down