simplify optimized LatLngBounds extend
This commit is contained in:
parent
63e22f0ed0
commit
665e766608
@ -13,47 +13,35 @@ L.LatLngBounds = function (southWest, northEast) { // (LatLng, LatLng) or (LatLn
|
|||||||
};
|
};
|
||||||
|
|
||||||
L.LatLngBounds.prototype = {
|
L.LatLngBounds.prototype = {
|
||||||
|
|
||||||
// extend the bounds to contain the given point or bounds
|
// extend the bounds to contain the given point or bounds
|
||||||
extend: function (obj) { // (LatLng) or (LatLngBounds)
|
extend: function (obj) { // (LatLng) or (LatLngBounds)
|
||||||
var southWest = this._southWest,
|
var sw = this._southWest,
|
||||||
northEast = this._northEast,
|
ne = this._northEast,
|
||||||
newSouthWest, newNorthEast;
|
sw2, ne2;
|
||||||
|
|
||||||
if (obj instanceof L.LatLng) {
|
if (obj instanceof L.LatLng) {
|
||||||
newSouthWest = obj;
|
sw2 = obj;
|
||||||
newNorthEast = obj;
|
ne2 = obj;
|
||||||
|
|
||||||
} else if (obj instanceof L.LatLngBounds) {
|
} else if (obj instanceof L.LatLngBounds) {
|
||||||
newSouthWest = obj._southWest;
|
sw2 = obj._southWest;
|
||||||
newNorthEast = obj._northEast;
|
ne2 = obj._northEast;
|
||||||
|
|
||||||
if (!newSouthWest || !newNorthEast) {
|
if (!sw2 || !ne2) { return this; }
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} else if (obj) {
|
|
||||||
var latLng = L.latLng(obj);
|
|
||||||
if (latLng !== null) {
|
|
||||||
this.extend(latLng);
|
|
||||||
} else {
|
|
||||||
var latLngBounds = L.latLngBounds(obj);
|
|
||||||
if (latLngBounds !== null) {
|
|
||||||
this.extend(latLngBounds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!southWest && !northEast) {
|
|
||||||
this._southWest = new L.LatLng(newSouthWest.lat, newSouthWest.lng);
|
|
||||||
this._northEast = new L.LatLng(newNorthEast.lat, newNorthEast.lng);
|
|
||||||
} else {
|
} else {
|
||||||
southWest.lat = Math.min(newSouthWest.lat, southWest.lat);
|
return obj ? this.extend(L.latLng(obj) || L.latLngBounds(obj)) : this;
|
||||||
southWest.lng = Math.min(newSouthWest.lng, southWest.lng);
|
}
|
||||||
northEast.lat = Math.max(newNorthEast.lat, northEast.lat);
|
|
||||||
northEast.lng = Math.max(newNorthEast.lng, northEast.lng);
|
if (!sw && !ne) {
|
||||||
|
this._southWest = new L.LatLng(sw2.lat, sw2.lng);
|
||||||
|
this._northEast = new L.LatLng(ne2.lat, ne2.lng);
|
||||||
|
} else {
|
||||||
|
sw.lat = Math.min(sw2.lat, sw.lat);
|
||||||
|
sw.lng = Math.min(sw2.lng, sw.lng);
|
||||||
|
ne.lat = Math.max(ne2.lat, ne.lat);
|
||||||
|
ne.lng = Math.max(ne2.lng, ne.lng);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user