fix Circle getBounds, closes #1068
This commit is contained in:
parent
09060ff163
commit
cca3180f30
@ -47,6 +47,7 @@
|
|||||||
<!-- /layer -->
|
<!-- /layer -->
|
||||||
<script type="text/javascript" src="suites/layer/TileLayerSpec.js"></script>
|
<script type="text/javascript" src="suites/layer/TileLayerSpec.js"></script>
|
||||||
<script type="text/javascript" src="suites/layer/vector/PolylineGeometrySpec.js"></script>
|
<script type="text/javascript" src="suites/layer/vector/PolylineGeometrySpec.js"></script>
|
||||||
|
<script type="text/javascript" src="suites/layer/vector/CircleSpec.js"></script>
|
||||||
|
|
||||||
<!-- /map -->
|
<!-- /map -->
|
||||||
<script type="text/javascript" src="suites/map/MapSpec.js"></script>
|
<script type="text/javascript" src="suites/map/MapSpec.js"></script>
|
||||||
|
17
spec/suites/layer/vector/CircleSpec.js
Normal file
17
spec/suites/layer/vector/CircleSpec.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
describe('Circle', function () {
|
||||||
|
describe('#getBounds', function () {
|
||||||
|
|
||||||
|
var circle;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
circle = L.circle([50, 30], 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct bounds', function () {
|
||||||
|
var bounds = circle.getBounds();
|
||||||
|
|
||||||
|
expect(bounds.getSouthWest().equals([49.998203369, 29.997204939])).toBeTruthy();
|
||||||
|
expect(bounds.getNorthEast().equals([50.001796631, 30.002795061])).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -34,13 +34,11 @@ L.Circle = L.Path.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getBounds: function () {
|
getBounds: function () {
|
||||||
var map = this._map,
|
var lngRadius = this._getLngRadius(),
|
||||||
delta = this._radius * Math.cos(Math.PI / 4),
|
latRadius = (this._mRadius / 40075017) * 360,
|
||||||
point = map.project(this._latlng),
|
latlng = this._latlng,
|
||||||
swPoint = new L.Point(point.x - delta, point.y + delta),
|
sw = new L.LatLng(latlng.lat - latRadius, latlng.lng - lngRadius),
|
||||||
nePoint = new L.Point(point.x + delta, point.y - delta),
|
ne = new L.LatLng(latlng.lat + latRadius, latlng.lng + lngRadius);
|
||||||
sw = map.unproject(swPoint),
|
|
||||||
ne = map.unproject(nePoint);
|
|
||||||
|
|
||||||
return new L.LatLngBounds(sw, ne);
|
return new L.LatLngBounds(sw, ne);
|
||||||
},
|
},
|
||||||
@ -72,11 +70,14 @@ L.Circle = L.Path.extend({
|
|||||||
return this._mRadius;
|
return this._mRadius;
|
||||||
},
|
},
|
||||||
|
|
||||||
_getLngRadius: function () {
|
// TODO Earth hardcoded, move into projection code!
|
||||||
var equatorLength = 40075017,
|
|
||||||
hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
|
||||||
|
|
||||||
return (this._mRadius / hLength) * 360;
|
_getLatRadius: function () {
|
||||||
|
return (this._mRadius / 40075017) * 360;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getLngRadius: function () {
|
||||||
|
return this._getLatRadius() / Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
||||||
},
|
},
|
||||||
|
|
||||||
_checkIfEmpty: function () {
|
_checkIfEmpty: function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user