Merge pull request #1318 from yohanboniface/add_lbrt_getters

Add LatLngBounds.getLeft/getBottom/getRight/getTop
This commit is contained in:
Vladimir Agafonkin 2013-02-04 02:45:06 -08:00
commit 80f107cba3
2 changed files with 69 additions and 6 deletions

View File

@ -20,4 +20,54 @@ describe('LatLngBounds', function() {
expect(c.isValid()).toBeTruthy();
});
});
describe('#getWest', function () {
it('should return a proper bbox west value', function() {
expect(a.getWest()).toEqual(12);
});
});
describe('#getSouth', function () {
it('should return a proper bbox south value', function() {
expect(a.getSouth()).toEqual(14);
});
});
describe('#getEast', function () {
it('should return a proper bbox east value', function() {
expect(a.getEast()).toEqual(40);
});
});
describe('#getNorth', function () {
it('should return a proper bbox north value', function() {
expect(a.getNorth()).toEqual(30);
});
});
describe('#toBBoxString', function () {
it('should return a proper left,bottom,right,top bbox', function() {
expect(a.toBBoxString()).toEqual("12,14,40,30");
});
});
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()));
});
});
});

View File

@ -66,11 +66,27 @@ 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 () {
return this._southWest.lng;
},
getSouth: function () {
return this._southWest.lat;
},
getEast: function () {
return this._northEast.lng;
},
getNorth: function () {
return this._northEast.lat;
},
contains: function (obj) { // (LatLngBounds) or (LatLng) -> Boolean
@ -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.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');
},
equals: function (bounds) { // (LatLngBounds)