2012-09-04 06:22:24 +08:00
|
|
|
describe('LatLngBounds', function() {
|
|
|
|
var a, c;
|
2013-02-05 21:21:40 +08:00
|
|
|
|
2012-09-04 06:22:24 +08:00
|
|
|
beforeEach(function() {
|
2012-10-07 02:01:17 +08:00
|
|
|
a = new L.LatLngBounds(
|
|
|
|
new L.LatLng(14, 12),
|
|
|
|
new L.LatLng(30, 40));
|
|
|
|
c = new L.LatLngBounds();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
|
|
|
|
describe('constructor', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('instantiates either passing two latlngs or an array of latlngs', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var b = new L.LatLngBounds([
|
|
|
|
new L.LatLng(14, 12),
|
|
|
|
new L.LatLng(30, 40)
|
|
|
|
]);
|
|
|
|
expect(b).toEqual(a);
|
|
|
|
expect(b.getNorthWest()).toEqual(new L.LatLng(30, 12));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#extend', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('extends the bounds by a given point', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
a.extend(new L.LatLng(20, 50));
|
|
|
|
expect(a.getNorthEast()).toEqual(new L.LatLng(30, 50));
|
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('extends the bounds by given bounds', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
a.extend([[20, 50], [8, 40]]);
|
|
|
|
|
|
|
|
expect(a.getSouthEast()).toEqual(new L.LatLng(8, 50));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getCenter', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns the bounds center', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(a.getCenter()).toEqual(new L.LatLng(22, 26));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#pad', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('pads the bounds by a given ratio', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var b = a.pad(0.5);
|
|
|
|
|
|
|
|
expect(b).toEqual(L.latLngBounds([[6, -2], [38, 54]]));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#equals', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if bounds equal', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(a.equals([[14, 12], [30, 40]])).toBe(true);
|
|
|
|
expect(a.equals([[14, 13], [30, 40]])).toBe(false);
|
|
|
|
expect(a.equals(null)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-09-04 06:22:24 +08:00
|
|
|
describe('#isValid', function() {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if properly set up', function() {
|
2012-09-04 06:22:24 +08:00
|
|
|
expect(a.isValid()).toBeTruthy();
|
|
|
|
});
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns false if is invalid', function() {
|
2012-09-04 06:22:24 +08:00
|
|
|
expect(c.isValid()).toBeFalsy();
|
|
|
|
});
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if extended', function() {
|
2012-09-04 06:22:24 +08:00
|
|
|
c.extend([0, 0]);
|
|
|
|
expect(c.isValid()).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2013-01-27 19:12:02 +08:00
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getWest', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a proper bbox west value', function() {
|
2013-01-28 08:04:09 +08:00
|
|
|
expect(a.getWest()).toEqual(12);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getSouth', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a proper bbox south value', function() {
|
2013-01-28 08:04:09 +08:00
|
|
|
expect(a.getSouth()).toEqual(14);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getEast', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a proper bbox east value', function() {
|
2013-01-28 08:04:09 +08:00
|
|
|
expect(a.getEast()).toEqual(40);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getNorth', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a proper bbox north value', function() {
|
2013-01-28 08:04:09 +08:00
|
|
|
expect(a.getNorth()).toEqual(30);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#toBBoxString', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a proper left,bottom,right,top bbox', function() {
|
2013-01-27 19:12:02 +08:00
|
|
|
expect(a.toBBoxString()).toEqual("12,14,40,30");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2013-01-28 08:09:26 +08:00
|
|
|
|
|
|
|
describe('#getNorthWest', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a proper north-west LatLng', function() {
|
2013-01-28 08:09:26 +08:00
|
|
|
expect(a.getNorthWest()).toEqual(new L.LatLng(a.getNorth(), a.getWest()));
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getSouthEast', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns a proper south-east LatLng', function() {
|
2013-01-28 08:09:26 +08:00
|
|
|
expect(a.getSouthEast()).toEqual(new L.LatLng(a.getSouth(), a.getEast()));
|
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#contains', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if contains latlng point', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(a.contains([16, 20])).toBe(true);
|
|
|
|
expect(L.latLngBounds(a).contains([5, 20])).toBe(false);
|
|
|
|
});
|
2013-01-28 08:09:26 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if contains bounds', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(a.contains([[16, 20], [20, 40]])).toBe(true);
|
|
|
|
expect(a.contains([[16, 50], [8, 40]])).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#intersects', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if intersects the given bounds', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(a.intersects([[16, 20], [50, 60]])).toBe(true);
|
|
|
|
expect(a.contains([[40, 50], [50, 60]])).toBe(false);
|
|
|
|
});
|
2013-01-28 08:09:26 +08:00
|
|
|
});
|
|
|
|
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|