accept coordinates in form of simple objects, close #1412

This commit is contained in:
Vladimir Agafonkin 2013-02-19 18:01:53 +02:00
parent 5d41efe616
commit a0dd4a60e9
2 changed files with 11 additions and 0 deletions

View File

@ -105,6 +105,14 @@ describe('LatLng', function() {
it('should create a LatLng object from two coordinates', function () {
expect(L.latLng(50, 30)).toEqual(new L.LatLng(50, 30));
});
it('should accept an object with lat/lng', function () {
expect(L.latLng({lat: 50, lng: 30})).toEqual(new L.LatLng(50, 30));
});
it('should accept an object with lat/lon', function () {
expect(L.latLng({lat: 50, lon: 30})).toEqual(new L.LatLng(50, 30));
});
});
});

View File

@ -80,6 +80,9 @@ L.latLng = function (a, b) { // (LatLng) or ([Number, Number]) or (Number, Numbe
if (a === undefined || a === null) {
return a;
}
if (typeof a === 'object' && 'lat' in a) {
return new L.LatLng(a.lat, 'lng' in a ? a.lng : a.lon);
}
return new L.LatLng(a, b);
};