Added Circle#getBounds, closed #440
This commit is contained in:
parent
ae99354857
commit
6040d8bf77
@ -9,11 +9,12 @@ Leaflet Changelog
|
||||
|
||||
#### API Improvements
|
||||
|
||||
* Added `Circle` `getBounds` method. [#440](https://github.com/CloudMade/Leaflet/issues/440)
|
||||
* Added `setPosition` and `getPosition` to all controls, as well as ability to pass certain position as an option when creating a control.
|
||||
* Made controls implementation easier (now more magic happens under the hood).
|
||||
* Added `Map` `containerPointToLatLng` and `latLngToContainerPoint` methods. [#474](https://github.com/CloudMade/Leaflet/issues/474)
|
||||
* Added `containerPoint` property to `MouseEvent`.
|
||||
* Added chaining to `DomEvent` methods
|
||||
* Added chaining to `DomEvent` methods.
|
||||
* Fixed a bug where popup size was calculated incorrectly in IE.
|
||||
|
||||
#### Breaking API changes
|
||||
|
28
dist/leaflet-src.js
vendored
28
dist/leaflet-src.js
vendored
@ -1322,6 +1322,7 @@ L.Map = L.Class.extend({
|
||||
},
|
||||
|
||||
unproject: function (point, zoom, unbounded) { // (Point[, Number, Boolean]) -> LatLng
|
||||
// TODO remove unbounded, making it true all the time?
|
||||
zoom = typeof zoom === 'undefined' ? this._zoom : zoom;
|
||||
return this.options.crs.pointToLatLng(point, this.options.scale(zoom), unbounded);
|
||||
},
|
||||
@ -3841,17 +3842,27 @@ L.Circle = L.Path.extend({
|
||||
},
|
||||
|
||||
projectLatlngs: function () {
|
||||
var equatorLength = 40075017,
|
||||
hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
||||
|
||||
var lngSpan = (this._mRadius / hLength) * 360,
|
||||
latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngSpan, true),
|
||||
var lngRadius = this._getLngRadius(),
|
||||
latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngRadius, true),
|
||||
point2 = this._map.latLngToLayerPoint(latlng2);
|
||||
|
||||
this._point = this._map.latLngToLayerPoint(this._latlng);
|
||||
this._radius = Math.round(this._point.x - point2.x);
|
||||
},
|
||||
|
||||
getBounds: function () {
|
||||
var map = this._map,
|
||||
delta = this._radius * Math.cos(Math.PI / 4),
|
||||
point = map.project(this._latlng),
|
||||
swPoint = new L.Point(point.x - delta, point.y + delta),
|
||||
nePoint = new L.Point(point.x + delta, point.y - delta),
|
||||
zoom = map.getZoom(),
|
||||
sw = map.unproject(swPoint, zoom, true),
|
||||
ne = map.unproject(nePoint, zoom, true);
|
||||
|
||||
return new L.LatLngBounds(sw, ne);
|
||||
},
|
||||
|
||||
getPathString: function () {
|
||||
var p = this._point,
|
||||
r = this._radius;
|
||||
@ -3871,6 +3882,13 @@ L.Circle = L.Path.extend({
|
||||
}
|
||||
},
|
||||
|
||||
_getLngRadius: function () {
|
||||
var equatorLength = 40075017,
|
||||
hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
||||
|
||||
return (this._mRadius / hLength) * 360;
|
||||
},
|
||||
|
||||
_checkIfEmpty: function () {
|
||||
var vp = this._map._pathViewport,
|
||||
r = this._radius,
|
||||
|
2
dist/leaflet.js
vendored
2
dist/leaflet.js
vendored
File diff suppressed because one or more lines are too long
@ -27,17 +27,27 @@ L.Circle = L.Path.extend({
|
||||
},
|
||||
|
||||
projectLatlngs: function () {
|
||||
var equatorLength = 40075017,
|
||||
hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
||||
|
||||
var lngSpan = (this._mRadius / hLength) * 360,
|
||||
latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngSpan, true),
|
||||
var lngRadius = this._getLngRadius(),
|
||||
latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngRadius, true),
|
||||
point2 = this._map.latLngToLayerPoint(latlng2);
|
||||
|
||||
this._point = this._map.latLngToLayerPoint(this._latlng);
|
||||
this._radius = Math.round(this._point.x - point2.x);
|
||||
},
|
||||
|
||||
getBounds: function () {
|
||||
var map = this._map,
|
||||
delta = this._radius * Math.cos(Math.PI / 4),
|
||||
point = map.project(this._latlng),
|
||||
swPoint = new L.Point(point.x - delta, point.y + delta),
|
||||
nePoint = new L.Point(point.x + delta, point.y - delta),
|
||||
zoom = map.getZoom(),
|
||||
sw = map.unproject(swPoint, zoom, true),
|
||||
ne = map.unproject(nePoint, zoom, true);
|
||||
|
||||
return new L.LatLngBounds(sw, ne);
|
||||
},
|
||||
|
||||
getPathString: function () {
|
||||
var p = this._point,
|
||||
r = this._radius;
|
||||
@ -57,6 +67,13 @@ L.Circle = L.Path.extend({
|
||||
}
|
||||
},
|
||||
|
||||
_getLngRadius: function () {
|
||||
var equatorLength = 40075017,
|
||||
hLength = equatorLength * Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
||||
|
||||
return (this._mRadius / hLength) * 360;
|
||||
},
|
||||
|
||||
_checkIfEmpty: function () {
|
||||
var vp = this._map._pathViewport,
|
||||
r = this._radius,
|
||||
|
@ -408,6 +408,7 @@ L.Map = L.Class.extend({
|
||||
},
|
||||
|
||||
unproject: function (point, zoom, unbounded) { // (Point[, Number, Boolean]) -> LatLng
|
||||
// TODO remove unbounded, making it true all the time?
|
||||
zoom = typeof zoom === 'undefined' ? this._zoom : zoom;
|
||||
return this.options.crs.pointToLatLng(point, this.options.scale(zoom), unbounded);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user