From 69b925b0576808e5e9b132f7b0e18be2ea475c5b Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 27 Jan 2013 12:12:02 +0100 Subject: [PATCH 1/3] Add LatLngBounds.getLeft/getBottom/getRight/getTop --- spec/suites/geo/LatLngBoundsSpec.js | 35 +++++++++++++++++++++++++++++ src/geo/LatLngBounds.js | 21 +++++++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/spec/suites/geo/LatLngBoundsSpec.js b/spec/suites/geo/LatLngBoundsSpec.js index 384f5ab6..379a73fe 100644 --- a/spec/suites/geo/LatLngBoundsSpec.js +++ b/spec/suites/geo/LatLngBoundsSpec.js @@ -20,4 +20,39 @@ describe('LatLngBounds', function() { expect(c.isValid()).toBeTruthy(); }); }); + + describe('#getLeft', function () { + it('should return a proper bbox left value', function() { + expect(a.getLeft()).toEqual(12); + }); + + }); + + describe('#getBottom', function () { + it('should return a proper bbox bottom value', function() { + expect(a.getBottom()).toEqual(14); + }); + + }); + + describe('#getRight', function () { + it('should return a proper bbox right value', function() { + expect(a.getRight()).toEqual(40); + }); + + }); + + describe('#getTop', function () { + it('should return a proper bbox top value', function() { + expect(a.getTop()).toEqual(30); + }); + + }); + + describe('#toBBoxString', function () { + it('should return a proper left,bottom,right,top bbox', function() { + expect(a.toBBoxString()).toEqual("12,14,40,30"); + }); + + }); }); \ No newline at end of file diff --git a/src/geo/LatLngBounds.js b/src/geo/LatLngBounds.js index bb407069..b19f5101 100644 --- a/src/geo/LatLngBounds.js +++ b/src/geo/LatLngBounds.js @@ -73,6 +73,22 @@ L.LatLngBounds.prototype = { return new L.LatLng(this._southWest.lat, this._northEast.lng); }, + getLeft: function () { + return this._southWest.lng; + }, + + getBottom: function () { + return this._southWest.lat; + }, + + getRight: function () { + return this._northEast.lng; + }, + + getTop: function () { + return this._northEast.lat; + }, + contains: function (obj) { // (LatLngBounds) or (LatLng) -> Boolean if (typeof obj[0] === 'number' || obj instanceof L.LatLng) { obj = L.latLng(obj); @@ -110,10 +126,7 @@ L.LatLngBounds.prototype = { }, toBBoxString: function () { - var sw = this._southWest, - ne = this._northEast; - - return [sw.lng, sw.lat, ne.lng, ne.lat].join(','); + return [this.getLeft(), this.getBottom(), this.getRight(), this.getTop()].join(','); }, equals: function (bounds) { // (LatLngBounds) From 4b5746ffbc57d195a5801d3690ab071e77a06002 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 28 Jan 2013 01:04:09 +0100 Subject: [PATCH 2/3] Use getWest/South/East/North instead of getLeft/Bottom/Right/Top --- spec/suites/geo/LatLngBoundsSpec.js | 24 ++++++++++++------------ src/geo/LatLngBounds.js | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/suites/geo/LatLngBoundsSpec.js b/spec/suites/geo/LatLngBoundsSpec.js index 379a73fe..e9ebe6f1 100644 --- a/spec/suites/geo/LatLngBoundsSpec.js +++ b/spec/suites/geo/LatLngBoundsSpec.js @@ -21,30 +21,30 @@ describe('LatLngBounds', function() { }); }); - describe('#getLeft', function () { - it('should return a proper bbox left value', function() { - expect(a.getLeft()).toEqual(12); + describe('#getWest', function () { + it('should return a proper bbox west value', function() { + expect(a.getWest()).toEqual(12); }); }); - describe('#getBottom', function () { - it('should return a proper bbox bottom value', function() { - expect(a.getBottom()).toEqual(14); + describe('#getSouth', function () { + it('should return a proper bbox south value', function() { + expect(a.getSouth()).toEqual(14); }); }); - describe('#getRight', function () { - it('should return a proper bbox right value', function() { - expect(a.getRight()).toEqual(40); + describe('#getEast', function () { + it('should return a proper bbox east value', function() { + expect(a.getEast()).toEqual(40); }); }); - describe('#getTop', function () { - it('should return a proper bbox top value', function() { - expect(a.getTop()).toEqual(30); + describe('#getNorth', function () { + it('should return a proper bbox north value', function() { + expect(a.getNorth()).toEqual(30); }); }); diff --git a/src/geo/LatLngBounds.js b/src/geo/LatLngBounds.js index b19f5101..6eed97bd 100644 --- a/src/geo/LatLngBounds.js +++ b/src/geo/LatLngBounds.js @@ -73,19 +73,19 @@ L.LatLngBounds.prototype = { return new L.LatLng(this._southWest.lat, this._northEast.lng); }, - getLeft: function () { + getWest: function () { return this._southWest.lng; }, - getBottom: function () { + getSouth: function () { return this._southWest.lat; }, - getRight: function () { + getEast: function () { return this._northEast.lng; }, - getTop: function () { + getNorth: function () { return this._northEast.lat; }, @@ -126,7 +126,7 @@ L.LatLngBounds.prototype = { }, toBBoxString: function () { - return [this.getLeft(), this.getBottom(), this.getRight(), this.getTop()].join(','); + return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(','); }, equals: function (bounds) { // (LatLngBounds) From 4f59140253cae09ecef0cc35265859db79fe72f2 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 28 Jan 2013 01:09:26 +0100 Subject: [PATCH 3/3] Eat our own food --- spec/suites/geo/LatLngBoundsSpec.js | 15 +++++++++++++++ src/geo/LatLngBounds.js | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/suites/geo/LatLngBoundsSpec.js b/spec/suites/geo/LatLngBoundsSpec.js index e9ebe6f1..0172db1e 100644 --- a/spec/suites/geo/LatLngBoundsSpec.js +++ b/spec/suites/geo/LatLngBoundsSpec.js @@ -55,4 +55,19 @@ describe('LatLngBounds', function() { }); }); + + describe('#getNorthWest', function () { + it('should return a proper north-west LatLng', function() { + expect(a.getNorthWest()).toEqual(new L.LatLng(a.getNorth(), a.getWest())); + }); + + }); + + describe('#getSouthEast', function () { + it('should return a proper south-east LatLng', function() { + expect(a.getSouthEast()).toEqual(new L.LatLng(a.getSouth(), a.getEast())); + }); + + }); + }); \ No newline at end of file diff --git a/src/geo/LatLngBounds.js b/src/geo/LatLngBounds.js index 6eed97bd..1018420f 100644 --- a/src/geo/LatLngBounds.js +++ b/src/geo/LatLngBounds.js @@ -66,11 +66,11 @@ L.LatLngBounds.prototype = { }, getNorthWest: function () { - return new L.LatLng(this._northEast.lat, this._southWest.lng); + return new L.LatLng(this.getNorth(), this.getWest()); }, getSouthEast: function () { - return new L.LatLng(this._southWest.lat, this._northEast.lng); + return new L.LatLng(this.getSouth(), this.getEast()); }, getWest: function () {