Add LatLngBounds.getLeft/getBottom/getRight/getTop

This commit is contained in:
Yohan Boniface 2013-01-27 12:12:02 +01:00
parent 80413f4040
commit 69b925b057
2 changed files with 52 additions and 4 deletions

View File

@ -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");
});
});
});

View File

@ -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)