Merge pull request #2025 from Gnurfos/issue-1915

Accept simple objects in L.latLngBounds(). Fixes #1915.
This commit is contained in:
Vladimir Agafonkin 2013-09-13 02:14:03 -07:00
commit 5841579bb8
3 changed files with 16 additions and 4 deletions

View File

@ -27,13 +27,17 @@ describe('LatLngBounds', function() {
it('extends the bounds by given bounds', function () {
a.extend([[20, 50], [8, 40]]);
expect(a.getSouthEast()).to.eql(new L.LatLng(8, 50));
});
it('extends the bounds by undefined', function () {
expect(a.extend()).to.eql(a);
});
it('extends the bounds by raw object', function () {
a.extend({lat: 20, lng: 50});
expect(a.getNorthEast()).to.eql(new L.LatLng(30, 50));
});
});
describe('#getCenter', function () {

View File

@ -75,7 +75,11 @@ L.latLng = function (a, b) { // (LatLng) or ([Number, Number]) or (Number, Numbe
return a;
}
if (L.Util.isArray(a)) {
return new L.LatLng(a[0], a[1]);
if (typeof a[0] === 'number' || typeof a[0] === 'string') {
return new L.LatLng(a[0], a[1]);
} else {
return null;
}
}
if (a === undefined || a === null) {
return a;
@ -83,6 +87,9 @@ L.latLng = function (a, b) { // (LatLng) or ([Number, Number]) or (Number, Numbe
if (typeof a === 'object' && 'lat' in a) {
return new L.LatLng(a.lat, 'lng' in a ? a.lng : a.lon);
}
if (b === undefined) {
return null;
}
return new L.LatLng(a, b);
};

View File

@ -17,8 +17,9 @@ L.LatLngBounds.prototype = {
extend: function (obj) { // (LatLng) or (LatLngBounds)
if (!obj) { return this; }
if (typeof obj[0] === 'number' || typeof obj[0] === 'string' || obj instanceof L.LatLng) {
obj = L.latLng(obj);
var latLng = L.latLng(obj);
if (latLng !== null) {
obj = latLng;
} else {
obj = L.latLngBounds(obj);
}