[Pkg-javascript-commits] [leaflet] 95/301: Accept simple objects in L.latLngBounds(). Fixes #1915.

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit 16f9c9a3024c95e78add1ad735adae604d707bbf
Author: Seb Emonet <seb at cygnus.(none)>
Date:   Fri Sep 13 00:22:19 2013 +0200

    Accept simple objects in L.latLngBounds(). Fixes #1915.
---
 spec/suites/geo/LatLngBoundsSpec.js | 6 +++++-
 src/geo/LatLng.js                   | 9 ++++++++-
 src/geo/LatLngBounds.js             | 5 +++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/spec/suites/geo/LatLngBoundsSpec.js b/spec/suites/geo/LatLngBoundsSpec.js
index ebfceab..2e81aad 100644
--- a/spec/suites/geo/LatLngBoundsSpec.js
+++ b/spec/suites/geo/LatLngBoundsSpec.js
@@ -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 () {
diff --git a/src/geo/LatLng.js b/src/geo/LatLng.js
index 9e2a453..a7e3336 100644
--- a/src/geo/LatLng.js
+++ b/src/geo/LatLng.js
@@ -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);
 };
 
diff --git a/src/geo/LatLngBounds.js b/src/geo/LatLngBounds.js
index 166af80..6fda3a8 100644
--- a/src/geo/LatLngBounds.js
+++ b/src/geo/LatLngBounds.js
@@ -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);
 		}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list