2013-11-08 05:54:33 +08:00
|
|
|
describe('LatLngBounds', function () {
|
2012-09-04 06:22:24 +08:00
|
|
|
var a, c;
|
2013-02-05 21:21:40 +08:00
|
|
|
|
2013-11-08 05:54:33 +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)
|
|
|
|
]);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(b).to.eql(a);
|
|
|
|
expect(b.getNorthWest()).to.eql(new L.LatLng(30, 12));
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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));
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getNorthEast()).to.eql(new L.LatLng(30, 50));
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
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]]);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getSouthEast()).to.eql(new L.LatLng(8, 50));
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2013-05-18 18:27:45 +08:00
|
|
|
|
|
|
|
it('extends the bounds by undefined', function () {
|
|
|
|
expect(a.extend()).to.eql(a);
|
|
|
|
});
|
2013-09-13 06:22:19 +08:00
|
|
|
|
|
|
|
it('extends the bounds by raw object', function () {
|
|
|
|
a.extend({lat: 20, lng: 50});
|
|
|
|
expect(a.getNorthEast()).to.eql(new L.LatLng(30, 50));
|
|
|
|
});
|
2014-01-16 16:58:04 +08:00
|
|
|
|
|
|
|
it('extend the bounds by an empty bounds object', function () {
|
|
|
|
expect(a.extend(new L.LatLngBounds())).to.eql(a);
|
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getCenter', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns the bounds center', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getCenter()).to.eql(new L.LatLng(22, 26));
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(b).to.eql(L.latLngBounds([[6, -2], [38, 54]]));
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#equals', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if bounds equal', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.equals([[14, 12], [30, 40]])).to.eql(true);
|
|
|
|
expect(a.equals([[14, 13], [30, 40]])).to.eql(false);
|
|
|
|
expect(a.equals(null)).to.eql(false);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#isValid', function () {
|
|
|
|
it('returns true if properly set up', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.isValid()).to.be.ok();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns false if is invalid', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(c.isValid()).to.not.be.ok();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns true if extended', function () {
|
2012-09-04 06:22:24 +08:00
|
|
|
c.extend([0, 0]);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(c.isValid()).to.be.ok();
|
2012-09-04 06:22:24 +08:00
|
|
|
});
|
|
|
|
});
|
2013-01-27 19:12:02 +08:00
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getWest', function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns a proper bbox west value', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getWest()).to.eql(12);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getSouth', function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns a proper bbox south value', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getSouth()).to.eql(14);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getEast', function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns a proper bbox east value', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getEast()).to.eql(40);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-01-28 08:04:09 +08:00
|
|
|
describe('#getNorth', function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns a proper bbox north value', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getNorth()).to.eql(30);
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#toBBoxString', function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns a proper left,bottom,right,top bbox', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.toBBoxString()).to.eql("12,14,40,30");
|
2013-01-27 19:12:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2013-01-28 08:09:26 +08:00
|
|
|
|
|
|
|
describe('#getNorthWest', function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns a proper north-west LatLng', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getNorthWest()).to.eql(new L.LatLng(a.getNorth(), a.getWest()));
|
2013-01-28 08:09:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getSouthEast', function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
it('returns a proper south-east LatLng', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.getSouthEast()).to.eql(new L.LatLng(a.getSouth(), a.getEast()));
|
2013-01-28 08:09:26 +08:00
|
|
|
});
|
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-03-02 05:49:20 +08:00
|
|
|
expect(a.contains([16, 20])).to.eql(true);
|
|
|
|
expect(L.latLngBounds(a).contains([5, 20])).to.eql(false);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2013-01-28 08:09:26 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if contains bounds', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.contains([[16, 20], [20, 40]])).to.eql(true);
|
|
|
|
expect(a.contains([[16, 50], [8, 40]])).to.eql(false);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#intersects', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if intersects the given bounds', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.intersects([[16, 20], [50, 60]])).to.eql(true);
|
|
|
|
expect(a.contains([[40, 50], [50, 60]])).to.eql(false);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2015-06-02 18:35:31 +08:00
|
|
|
|
|
|
|
it('returns true if just touches the boundary of the given bounds', function () {
|
|
|
|
expect(a.intersects([[25, 40], [55, 50]])).to.eql(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#overlaps', function () {
|
|
|
|
it('returns true if overlaps the given bounds', function () {
|
|
|
|
expect(a.overlaps([[16, 20], [50, 60]])).to.eql(true);
|
|
|
|
});
|
|
|
|
it('returns false if just touches the boundary of the given bounds', function () {
|
|
|
|
expect(a.overlaps([[25, 40], [55, 50]])).to.eql(false);
|
|
|
|
});
|
2013-01-28 08:09:26 +08:00
|
|
|
});
|
|
|
|
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|