simplify optimized LatLngBounds extend

This commit is contained in:
Vladimir Agafonkin 2014-02-27 19:02:30 +02:00
parent 63e22f0ed0
commit 665e766608

View File

@ -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 (!sw2 || !ne2) { return this; }
if (!newSouthWest || !newNorthEast) {
return this;
}
} else if (obj) {
var latLng = L.latLng(obj);
if (latLng !== null) {
this.extend(latLng);
} else { } else {
var latLngBounds = L.latLngBounds(obj); return obj ? this.extend(L.latLng(obj) || L.latLngBounds(obj)) : this;
if (latLngBounds !== null) {
this.extend(latLngBounds);
}
} }
return this; if (!sw && !ne) {
} this._southWest = new L.LatLng(sw2.lat, sw2.lng);
else { this._northEast = new L.LatLng(ne2.lat, ne2.lng);
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); sw.lat = Math.min(sw2.lat, sw.lat);
southWest.lng = Math.min(newSouthWest.lng, southWest.lng); sw.lng = Math.min(sw2.lng, sw.lng);
northEast.lat = Math.max(newNorthEast.lat, northEast.lat); ne.lat = Math.max(ne2.lat, ne.lat);
northEast.lng = Math.max(newNorthEast.lng, northEast.lng); ne.lng = Math.max(ne2.lng, ne.lng);
} }
return this; return this;