Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions
+10 -15
View File
@@ -1,7 +1,7 @@
import {Map, View} from '../../../src/ol/index.js';
import MapBrowserEvent from '../../../src/ol/MapBrowserEvent.js';
import Event from '../../../src/ol/events/Event.js';
import {useGeographic, clearUserProjection} from '../../../src/ol/proj.js';
import MapBrowserEvent from '../../../src/ol/MapBrowserEvent.js';
import {Map, View} from '../../../src/ol/index.js';
import {clearUserProjection, useGeographic} from '../../../src/ol/proj.js';
function createMap() {
const size = 256;
@@ -11,7 +11,7 @@ function createMap() {
height: `${size}px`,
position: 'absolute',
top: 0,
left: 0
left: 0,
});
document.body.appendChild(target);
@@ -19,16 +19,14 @@ function createMap() {
target: target,
view: new View({
center: [0, 0],
zoom: 0
})
zoom: 0,
}),
});
return {map, target, size};
}
describe('ol/MapBrowserEvent', function() {
describe('pixel', function() {
describe('ol/MapBrowserEvent', function () {
describe('pixel', function () {
let ref;
beforeEach(() => {
ref = createMap();
@@ -66,10 +64,9 @@ describe('ol/MapBrowserEvent', function() {
mapEvent.pixel = pixel;
expect(mapEvent.pixel).to.eql(pixel);
});
});
describe('coordinate', function() {
describe('coordinate', function () {
let ref;
beforeEach(() => {
ref = createMap();
@@ -108,10 +105,9 @@ describe('ol/MapBrowserEvent', function() {
mapEvent.coordinate = coordinate;
expect(mapEvent.coordinate).to.eql(coordinate);
});
});
describe('coordinate - with useGeographic()', function() {
describe('coordinate - with useGeographic()', function () {
let ref;
beforeEach(() => {
useGeographic();
@@ -138,6 +134,5 @@ describe('ol/MapBrowserEvent', function() {
expect(coord[0]).to.be(-90);
expect(coord[1]).to.roughlyEqual(66.5132, 1e-4);
});
});
});
+36 -39
View File
@@ -1,11 +1,11 @@
import Event from '../../../src/ol/events/Event.js';
import Map from '../../../src/ol/Map.js';
import MapBrowserEventHandler from '../../../src/ol/MapBrowserEventHandler.js';
import {listen} from '../../../src/ol/events.js';
import {DEVICE_PIXEL_RATIO} from '../../../src/ol/has.js';
import Event from '../../../src/ol/events/Event.js';
import {listen} from '../../../src/ol/events.js';
describe('ol/MapBrowserEventHandler', function() {
describe('#emulateClick_', function() {
describe('ol/MapBrowserEventHandler', function () {
describe('#emulateClick_', function () {
let clock;
let handler;
let clickSpy;
@@ -13,12 +13,14 @@ describe('ol/MapBrowserEventHandler', function() {
let dblclickSpy;
let target;
beforeEach(function() {
beforeEach(function () {
clock = sinon.useFakeTimers();
target = document.createElement('div');
handler = new MapBrowserEventHandler(new Map({
target: target
}));
handler = new MapBrowserEventHandler(
new Map({
target: target,
})
);
clickSpy = sinon.spy();
listen(handler, 'click', clickSpy);
@@ -28,24 +30,22 @@ describe('ol/MapBrowserEventHandler', function() {
dblclickSpy = sinon.spy();
listen(handler, 'dblclick', dblclickSpy);
});
afterEach(function() {
afterEach(function () {
clock.restore();
});
it('emulates click', function() {
it('emulates click', function () {
const event = new Event();
event.type = 'pointerdown';
event.target = target,
event.clientX = 0;
(event.target = target), (event.clientX = 0);
event.clientY = 0;
handler.emulateClick_(event);
expect(clickSpy.called).to.be.ok();
});
it('emulates singleclick', function() {
it('emulates singleclick', function () {
const event = new Event();
event.type = 'pointerdown';
event.target = target;
@@ -64,7 +64,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(dblclickSpy.called).to.not.be.ok();
});
it('emulates dblclick', function() {
it('emulates dblclick', function () {
const event = new Event();
event.type = 'pointerdown';
event.target = target;
@@ -82,33 +82,30 @@ describe('ol/MapBrowserEventHandler', function() {
expect(singleclickSpy.called).to.not.be.ok();
expect(dblclickSpy.calledOnce).to.be.ok();
});
});
describe('#down_', function() {
describe('#down_', function () {
let handler;
beforeEach(function() {
beforeEach(function () {
handler = new MapBrowserEventHandler(new Map({}));
});
it('is null if no "down" type event has been handled', function() {
it('is null if no "down" type event has been handled', function () {
expect(handler.down_).to.be(null);
});
it('is an event after handlePointerDown_ has been called', function() {
it('is an event after handlePointerDown_ has been called', function () {
const event = new Event('pointerdown');
handler.handlePointerDown_(event);
expect(handler.down_).to.be(event);
});
});
describe('#isMoving_', function() {
describe('#isMoving_', function () {
let defaultHandler;
let moveToleranceHandler;
let pointerdownAt0;
beforeEach(function() {
beforeEach(function () {
defaultHandler = new MapBrowserEventHandler(new Map({}));
moveToleranceHandler = new MapBrowserEventHandler(new Map({}), 8);
pointerdownAt0 = new Event();
@@ -119,7 +116,7 @@ describe('ol/MapBrowserEventHandler', function() {
moveToleranceHandler.handlePointerDown_(pointerdownAt0);
});
it('is not moving if distance is 0', function() {
it('is not moving if distance is 0', function () {
pointerdownAt0 = new Event();
pointerdownAt0.type = 'pointerdown';
pointerdownAt0.clientX = 0;
@@ -127,7 +124,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(defaultHandler.isMoving_(pointerdownAt0)).to.be(false);
});
it('is moving if distance is 2', function() {
it('is moving if distance is 2', function () {
const pointerdownAt2 = new Event();
pointerdownAt2.type = 'pointerdown';
pointerdownAt2.clientX = DEVICE_PIXEL_RATIO + 1;
@@ -135,7 +132,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(defaultHandler.isMoving_(pointerdownAt2)).to.be(true);
});
it('is moving with negative distance', function() {
it('is moving with negative distance', function () {
const pointerdownAt2 = new Event();
pointerdownAt2.type = 'pointerdown';
pointerdownAt2.clientX = -(DEVICE_PIXEL_RATIO + 1);
@@ -143,7 +140,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(defaultHandler.isMoving_(pointerdownAt2)).to.be(true);
});
it('is not moving if distance is less than move tolerance', function() {
it('is not moving if distance is less than move tolerance', function () {
const pointerdownAt2 = new Event();
pointerdownAt2.type = 'pointerdown';
pointerdownAt2.clientX = DEVICE_PIXEL_RATIO + 1;
@@ -151,19 +148,19 @@ describe('ol/MapBrowserEventHandler', function() {
expect(moveToleranceHandler.isMoving_(pointerdownAt2)).to.be(false);
});
it('is moving if distance is greater than move tolerance', function() {
it('is moving if distance is greater than move tolerance', function () {
const pointerdownAt9 = new Event();
pointerdownAt9.type = 'pointerdown';
pointerdownAt9.clientX = (DEVICE_PIXEL_RATIO * 8) + 1;
pointerdownAt9.clientY = (DEVICE_PIXEL_RATIO * 8) + 1;
pointerdownAt9.clientX = DEVICE_PIXEL_RATIO * 8 + 1;
pointerdownAt9.clientY = DEVICE_PIXEL_RATIO * 8 + 1;
expect(moveToleranceHandler.isMoving_(pointerdownAt9)).to.be(true);
});
it('is moving when moving back close to the down pixel', function() {
it('is moving when moving back close to the down pixel', function () {
const pointermoveAt9 = new Event();
pointermoveAt9.type = 'pointermove';
pointermoveAt9.clientX = (DEVICE_PIXEL_RATIO * 8) + 1;
pointermoveAt9.clientY = (DEVICE_PIXEL_RATIO * 8) + 1;
pointermoveAt9.clientX = DEVICE_PIXEL_RATIO * 8 + 1;
pointermoveAt9.clientY = DEVICE_PIXEL_RATIO * 8 + 1;
moveToleranceHandler.handlePointerMove_(pointermoveAt9);
expect(moveToleranceHandler.isMoving_(pointermoveAt9)).to.be(true);
const pointermoveAt2 = new Event();
@@ -175,17 +172,17 @@ describe('ol/MapBrowserEventHandler', function() {
});
});
describe('handleTouchMove_', function() {
describe('handleTouchMove_', function () {
let handler;
beforeEach(function() {
beforeEach(function () {
handler = new MapBrowserEventHandler(new Map({}));
});
it('prevents default on touchmove event', function() {
it('prevents default on touchmove event', function () {
handler.originalPointerMoveEvent_ = {
defaultPrevented: true
defaultPrevented: true,
};
const event = {
preventDefault: sinon.spy()
preventDefault: sinon.spy(),
};
handler.handleTouchMove_(event);
expect(event.preventDefault.callCount).to.be(1);
+286 -251
View File
@@ -9,365 +9,396 @@ import {
numberSafeCompareFunction,
remove,
reverseSubArray,
stableSort
stableSort,
} from '../../../src/ol/array.js';
describe('ol.array', function() {
describe('binarySearch', function() {
const insertionPoint = function(position) {
describe('ol.array', function () {
describe('binarySearch', function () {
const insertionPoint = function (position) {
return -(position + 1);
};
const revNumCompare = function(a, b) {
const revNumCompare = function (a, b) {
return b - a;
};
describe('default comparison on array of String(s)', function() {
describe('default comparison on array of String(s)', function () {
const a = [
'1000', '9', 'AB', 'ABC', 'ABCABC', 'ABD', 'ABDA', 'B', 'B', 'B',
'C', 'CA', 'CC', 'ZZZ', 'ab', 'abc', 'abcabc', 'abd', 'abda', 'b',
'c', 'ca', 'cc', 'zzz'
'1000',
'9',
'AB',
'ABC',
'ABCABC',
'ABD',
'ABDA',
'B',
'B',
'B',
'C',
'CA',
'CC',
'ZZZ',
'ab',
'abc',
'abcabc',
'abd',
'abda',
'b',
'c',
'ca',
'cc',
'zzz',
];
it('should find \'1000\' at index 0', function() {
it("should find '1000' at index 0", function () {
expect(binarySearch(a, '1000')).to.be(0);
});
it('should find \'zzz\' at index ' + (a.length - 1), function() {
it("should find 'zzz' at index " + (a.length - 1), function () {
expect(binarySearch(a, 'zzz')).to.be(a.length - 1);
});
it('should find \'C\' at index 10', function() {
it("should find 'C' at index 10", function () {
expect(binarySearch(a, 'C')).to.be(10);
});
it('should find \'B\' at index 7 || 8 || 9', function() {
it("should find 'B' at index 7 || 8 || 9", function () {
const pos = binarySearch(a, 'B');
expect(pos == 7 || pos == 8 || pos == 9).to.be.ok();
});
it('should not find \'100\'', function() {
it("should not find '100'", function () {
const pos = binarySearch(a, '100');
expect(pos < 0).to.be.ok();
});
it('should have an insertion point of 0 for \'100\'', function() {
it("should have an insertion point of 0 for '100'", function () {
const pos = binarySearch(a, '100');
expect(insertionPoint(pos)).to.be(0);
});
it('should not find \'zzz0\'', function() {
it("should not find 'zzz0'", function () {
const pos = binarySearch(a, 'zzz0');
expect(pos < 0).to.be.ok();
});
it('should have an insertion point of ' + (a.length) + ' for \'zzz0\'',
function() {
it(
'should have an insertion point of ' + a.length + " for 'zzz0'",
function () {
const pos = binarySearch(a, 'zzz0');
expect(insertionPoint(pos)).to.be(a.length);
}
);
it('should not find \'BA\'', function() {
it("should not find 'BA'", function () {
const pos = binarySearch(a, 'zzz0');
expect(pos < 0).to.be.ok();
});
it('should have an insertion point of 10 for \'BA\'',
function() {
const pos = binarySearch(a, 'BA');
expect(insertionPoint(pos)).to.be(10);
}
);
it("should have an insertion point of 10 for 'BA'", function () {
const pos = binarySearch(a, 'BA');
expect(insertionPoint(pos)).to.be(10);
});
});
describe('0 length array with default comparison', function() {
describe('0 length array with default comparison', function () {
const b = [];
it('should not find \'a\'', function() {
it("should not find 'a'", function () {
expect(binarySearch(b, 'a') < 0).to.be.ok();
});
it('should have an insertion point of 0 for \'a\'',
function() {
const pos = binarySearch(b, 'a');
expect(insertionPoint(pos)).to.be(0);
}
);
it("should have an insertion point of 0 for 'a'", function () {
const pos = binarySearch(b, 'a');
expect(insertionPoint(pos)).to.be(0);
});
});
describe('single element array with default lexiographical comparison',
function() {
const c = ['only item'];
it('should find \'only item\' at index 0', function() {
expect(binarySearch(c, 'only item')).to.be(0);
});
it('should not find \'a\'', function() {
expect(binarySearch(c, 'a') < 0).to.be.ok();
});
it('should have an insertion point of 0 for \'a\'',
function() {
const pos = binarySearch(c, 'a');
expect(insertionPoint(pos)).to.be(0);
}
);
it('should not find \'z\'', function() {
expect(binarySearch(c, 'z') < 0).to.be.ok();
});
it('should have an insertion point of 1 for \'z\'',
function() {
const pos = binarySearch(c, 'z');
expect(insertionPoint(pos)).to.be(1);
}
);
}
);
describe('single element array with default lexiographical comparison', function () {
const c = ['only item'];
it("should find 'only item' at index 0", function () {
expect(binarySearch(c, 'only item')).to.be(0);
});
it("should not find 'a'", function () {
expect(binarySearch(c, 'a') < 0).to.be.ok();
});
it("should have an insertion point of 0 for 'a'", function () {
const pos = binarySearch(c, 'a');
expect(insertionPoint(pos)).to.be(0);
});
it("should not find 'z'", function () {
expect(binarySearch(c, 'z') < 0).to.be.ok();
});
it("should have an insertion point of 1 for 'z'", function () {
const pos = binarySearch(c, 'z');
expect(insertionPoint(pos)).to.be(1);
});
});
describe('default comparison on array of Number(s)', function() {
describe('default comparison on array of Number(s)', function () {
const d = [
-897123.9, -321434.58758, -1321.3124, -324, -9, -3, 0, 0, 0,
0.31255, 5, 142.88888708, 334, 342, 453, 54254
-897123.9,
-321434.58758,
-1321.3124,
-324,
-9,
-3,
0,
0,
0,
0.31255,
5,
142.88888708,
334,
342,
453,
54254,
];
it('should find -897123.9 at index 0', function() {
it('should find -897123.9 at index 0', function () {
expect(binarySearch(d, -897123.9)).to.be(0);
});
it('should find 54254 at index ' + (d.length - 1), function() {
it('should find 54254 at index ' + (d.length - 1), function () {
expect(binarySearch(d, 54254)).to.be(d.length - 1);
});
it('should find -3 at index 5', function() {
it('should find -3 at index 5', function () {
expect(binarySearch(d, -3)).to.be(5);
});
it('should find 0 at index 6 || 7 || 8', function() {
it('should find 0 at index 6 || 7 || 8', function () {
const pos = binarySearch(d, 0);
expect(pos == 6 || pos == 7 || pos == 8).to.be(true);
});
it('should not find -900000', function() {
it('should not find -900000', function () {
const pos = binarySearch(d, -900000);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for -900000', function() {
it('should have an insertion point of 0 for -900000', function () {
const pos = binarySearch(d, -900000);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find 54255', function() {
it('should not find 54255', function () {
const pos = binarySearch(d, 54255);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of ' + (d.length) + ' for 54255',
function() {
it(
'should have an insertion point of ' + d.length + ' for 54255',
function () {
const pos = binarySearch(d, 54255);
expect(insertionPoint(pos)).to.be(d.length);
}
);
it('should not find 1.1', function() {
it('should not find 1.1', function () {
const pos = binarySearch(d, 1.1);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 10 for 1.1', function() {
it('should have an insertion point of 10 for 1.1', function () {
const pos = binarySearch(d, 1.1);
expect(insertionPoint(pos)).to.be(10);
});
});
describe('custom comparison function, which reverse orders numbers',
function() {
const e = [
54254, 453, 342, 334, 142.88888708, 5, 0.31255, 0, 0, 0, -3,
-9, -324, -1321.3124, -321434.58758, -897123.9
];
it('should find 54254 at index 0', function() {
const pos = binarySearch(e, 54254, revNumCompare);
expect(pos).to.be(0);
});
it('should find -897123.9 at index ' + (e.length - 1), function() {
const pos = binarySearch(e, -897123.9, revNumCompare);
expect(pos).to.be(e.length - 1);
});
it('should find -3 at index 10', function() {
const pos = binarySearch(e, -3, revNumCompare);
expect(pos).to.be(10);
});
it('should find 0 at index 7 || 8 || 9', function() {
const pos = binarySearch(e, 0, revNumCompare);
expect(pos == 7 || pos == 8 || pos == 9).to.be(true);
});
it('should not find 54254.1', function() {
const pos = binarySearch(e, 54254.1, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 54254.1', function() {
const pos = binarySearch(e, 54254.1, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find -897124', function() {
describe('custom comparison function, which reverse orders numbers', function () {
const e = [
54254,
453,
342,
334,
142.88888708,
5,
0.31255,
0,
0,
0,
-3,
-9,
-324,
-1321.3124,
-321434.58758,
-897123.9,
];
it('should find 54254 at index 0', function () {
const pos = binarySearch(e, 54254, revNumCompare);
expect(pos).to.be(0);
});
it('should find -897123.9 at index ' + (e.length - 1), function () {
const pos = binarySearch(e, -897123.9, revNumCompare);
expect(pos).to.be(e.length - 1);
});
it('should find -3 at index 10', function () {
const pos = binarySearch(e, -3, revNumCompare);
expect(pos).to.be(10);
});
it('should find 0 at index 7 || 8 || 9', function () {
const pos = binarySearch(e, 0, revNumCompare);
expect(pos == 7 || pos == 8 || pos == 9).to.be(true);
});
it('should not find 54254.1', function () {
const pos = binarySearch(e, 54254.1, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 54254.1', function () {
const pos = binarySearch(e, 54254.1, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find -897124', function () {
const pos = binarySearch(e, -897124, revNumCompare);
expect(pos < 0).to.be(true);
});
it(
'should have an insertion point of ' + e.length + ' for -897124',
function () {
const pos = binarySearch(e, -897124, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of ' + e.length + ' for -897124',
function() {
const pos = binarySearch(e, -897124, revNumCompare);
expect(insertionPoint(pos)).to.be(e.length);
}
);
it('should not find 1.1', function() {
const pos = binarySearch(e, 1.1, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 1.1', function() {
const pos = binarySearch(e, 1.1, revNumCompare);
expect(insertionPoint(pos)).to.be(6);
});
}
);
expect(insertionPoint(pos)).to.be(e.length);
}
);
it('should not find 1.1', function () {
const pos = binarySearch(e, 1.1, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 1.1', function () {
const pos = binarySearch(e, 1.1, revNumCompare);
expect(insertionPoint(pos)).to.be(6);
});
});
describe('0 length array with custom comparison function', function() {
describe('0 length array with custom comparison function', function () {
const f = [];
it('should not find 0', function() {
it('should not find 0', function () {
const pos = binarySearch(f, 0, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 0', function() {
it('should have an insertion point of 0 for 0', function () {
const pos = binarySearch(f, 0, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
});
describe('single element array with custom comparison function',
function() {
const g = [1];
it('should find 1 at index 0', function() {
const pos = binarySearch(g, 1, revNumCompare);
expect(pos).to.be(0);
});
it('should not find 2', function() {
const pos = binarySearch(g, 2, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 2', function() {
const pos = binarySearch(g, 2, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find 0', function() {
const pos = binarySearch(g, 0, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 1 for 0', function() {
const pos = binarySearch(g, 0, revNumCompare);
expect(insertionPoint(pos)).to.be(1);
});
}
);
describe('single element array with custom comparison function', function () {
const g = [1];
it('should find 1 at index 0', function () {
const pos = binarySearch(g, 1, revNumCompare);
expect(pos).to.be(0);
});
it('should not find 2', function () {
const pos = binarySearch(g, 2, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 2', function () {
const pos = binarySearch(g, 2, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find 0', function () {
const pos = binarySearch(g, 0, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 1 for 0', function () {
const pos = binarySearch(g, 0, revNumCompare);
expect(insertionPoint(pos)).to.be(1);
});
});
describe('finding first index when multiple candidates', function() {
it('should find the index of the first 0', function() {
describe('finding first index when multiple candidates', function () {
it('should find the index of the first 0', function () {
expect(binarySearch([0, 0, 1], 0)).to.be(0);
});
it('should find the index of the first 1', function() {
it('should find the index of the first 1', function () {
expect(binarySearch([0, 1, 1], 1)).to.be(1);
});
});
describe('Don\'t use Array#slice, Function#apply and Function#call',
function() {
const a = [1, 5, 7, 11, 13, 16, 19, 24, 28, 31, 33, 36, 40, 50, 52, 55];
const calls = {
'Array#slice': false,
'Function#apply': false,
'Function#call': false
describe("Don't use Array#slice, Function#apply and Function#call", function () {
const a = [1, 5, 7, 11, 13, 16, 19, 24, 28, 31, 33, 36, 40, 50, 52, 55];
const calls = {
'Array#slice': false,
'Function#apply': false,
'Function#call': false,
};
let origArraySlice;
let origFunctionApply;
let origFunctionCall;
it('does not use potentially slow methods (default & custom compare)', function () {
// Mockup (I failed to use sinon.spy and beforeEach-hooks)
origArraySlice = Array.prototype.slice;
origFunctionApply = Function.prototype.apply;
origFunctionCall = Function.prototype.call;
Array.prototype.slice = function () {
calls['Array#slice'] = true;
};
Function.prototype.apply = function () {
calls['Function#apply'] = true;
};
Function.prototype.call = function () {
calls['Function#call'] = true;
};
let origArraySlice;
let origFunctionApply;
let origFunctionCall;
it('does not use potentially slow methods (default & custom compare)',
function() {
// Mockup (I failed to use sinon.spy and beforeEach-hooks)
origArraySlice = Array.prototype.slice;
origFunctionApply = Function.prototype.apply;
origFunctionCall = Function.prototype.call;
Array.prototype.slice = function() {
calls['Array#slice'] = true;
};
Function.prototype.apply = function() {
calls['Function#apply'] = true;
};
Function.prototype.call = function() {
calls['Function#call'] = true;
};
// Now actually call and test the method twice
binarySearch(a, 48);
binarySearch(a, 13, function (a, b) {
return a > b ? 1 : a < b ? -1 : 0;
});
// Now actually call and test the method twice
binarySearch(a, 48);
binarySearch(a, 13, function(a, b) {
return a > b ? 1 : a < b ? -1 : 0;
});
// Restore mocked up methods
Array.prototype.slice = origArraySlice;
Function.prototype.apply = origFunctionApply;
Function.prototype.call = origFunctionCall;
// Restore mocked up methods
Array.prototype.slice = origArraySlice;
Function.prototype.apply = origFunctionApply;
Function.prototype.call = origFunctionCall;
// Expectations
expect(calls['Array#slice']).to.be(false);
expect(calls['Function#apply']).to.be(false);
expect(calls['Function#call']).to.be(false);
});
});
// Expectations
expect(calls['Array#slice']).to.be(false);
expect(calls['Function#apply']).to.be(false);
expect(calls['Function#call']).to.be(false);
}
);
}
);
describe('when items are not found', function() {
describe('when items are not found', function () {
const arr = [1, 2, 2, 2, 3, 5, 9];
it('should return the index of where the item would go plus one, negated, if the item is not found', function() {
it('should return the index of where the item would go plus one, negated, if the item is not found', function () {
expect(binarySearch(arr, 4)).to.equal(-6);
});
it('should work even on empty arrays', function() {
it('should work even on empty arrays', function () {
expect(binarySearch([], 42)).to.equal(-1);
});
it('should work even on arrays of doubles', function() {
it('should work even on arrays of doubles', function () {
expect(binarySearch([0.0, 0.1, 0.2, 0.3, 0.4], 0.25)).to.equal(-4);
});
});
});
describe('equals', function() {
it('returns true for [] == []', function() {
describe('equals', function () {
it('returns true for [] == []', function () {
expect(equals([], [])).to.be(true);
});
it('returns true for [1] == [1]', function() {
it('returns true for [1] == [1]', function () {
expect(equals([1], [1])).to.be(true);
});
it('returns true for [\'1\'] == [\'1\']', function() {
it("returns true for ['1'] == ['1']", function () {
expect(equals(['1'], ['1'])).to.be(true);
});
it('returns false for [1] == [\'1\']', function() {
it("returns false for [1] == ['1']", function () {
expect(equals([1], ['1'])).to.be(false);
});
it('returns true for [null] == [null]', function() {
it('returns true for [null] == [null]', function () {
expect(equals([null], [null])).to.be(true);
});
it('returns false for [null] == [undefined]', function() {
it('returns false for [null] == [undefined]', function () {
expect(equals([null], [undefined])).to.be(false);
});
it('returns true for [1, 2] == [1, 2]', function() {
it('returns true for [1, 2] == [1, 2]', function () {
expect(equals([1, 2], [1, 2])).to.be(true);
});
it('returns false for [1, 2] == [2, 1]', function() {
it('returns false for [1, 2] == [2, 1]', function () {
expect(equals([1, 2], [2, 1])).to.be(false);
});
it('returns false for [1, 2] == [1]', function() {
it('returns false for [1, 2] == [1]', function () {
expect(equals([1, 2], [1])).to.be(false);
});
it('returns false for [1] == [1, 2]', function() {
it('returns false for [1] == [1, 2]', function () {
expect(equals([1], [1, 2])).to.be(false);
});
it('returns false for [{}] == [{}]', function() {
it('returns false for [{}] == [{}]', function () {
expect(equals([{}], [{}])).to.be(false);
});
});
describe('extend', function() {
it('extends an array in place with an array', function() {
describe('extend', function () {
it('extends an array in place with an array', function () {
const a = [0, 1];
extend(a, [2, 3]);
expect(a).to.eql([0, 1, 2, 3]);
});
it('extends an array in place with a number', function() {
it('extends an array in place with a number', function () {
const a = [0, 1];
extend(a, 2);
expect(a).to.eql([0, 1, 2]);
});
it('extends an array in place with a big array', function() {
it('extends an array in place with a big array', function () {
const a = [];
let i = 250000; // original test has 1.000.000, but that was too slow
const bigArray = Array(i);
@@ -379,10 +410,10 @@ describe('ol.array', function() {
});
});
describe('find', function() {
it('finds numbers in an array', function() {
describe('find', function () {
it('finds numbers in an array', function () {
const a = [0, 1, 2, 3];
const b = find(a, function(val, index, a2) {
const b = find(a, function (val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val > 1;
@@ -390,17 +421,17 @@ describe('ol.array', function() {
expect(b).to.be(2);
});
it('returns null when an item in an array is not found', function() {
it('returns null when an item in an array is not found', function () {
const a = [0, 1, 2, 3];
const b = find(a, function(val, index, a2) {
const b = find(a, function (val, index, a2) {
return val > 100;
});
expect(b).to.be(null);
});
it('finds items in an array-like', function() {
it('finds items in an array-like', function () {
const a = 'abCD';
const b = find(a, function(val, index, a2) {
const b = find(a, function (val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val >= 'A' && val <= 'Z';
@@ -408,19 +439,19 @@ describe('ol.array', function() {
expect(b).to.be('C');
});
it('returns null when nothing in an array-like is found', function() {
it('returns null when nothing in an array-like is found', function () {
const a = 'abcd';
const b = find(a, function(val, index, a2) {
const b = find(a, function (val, index, a2) {
return val >= 'A' && val <= 'Z';
});
expect(b).to.be(null);
});
});
describe('findIndex', function() {
it('finds index of numbers in an array', function() {
describe('findIndex', function () {
it('finds index of numbers in an array', function () {
const a = [0, 1, 2, 3];
const b = findIndex(a, function(val, index, a2) {
const b = findIndex(a, function (val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val > 1;
@@ -428,29 +459,29 @@ describe('ol.array', function() {
expect(b).to.be(2);
});
it('returns -1 when an item in an array is not found', function() {
it('returns -1 when an item in an array is not found', function () {
const a = [0, 1, 2, 3];
const b = findIndex(a, function(val, index, a2) {
const b = findIndex(a, function (val, index, a2) {
return val > 100;
});
expect(b).to.be(-1);
});
});
describe('isSorted', function() {
it('works with just an array as argument', function() {
describe('isSorted', function () {
it('works with just an array as argument', function () {
expect(isSorted([1, 2, 3])).to.be(true);
expect(isSorted([1, 2, 2])).to.be(true);
expect(isSorted([1, 2, 1])).to.be(false);
});
it('works with strict comparison without compare function', function() {
it('works with strict comparison without compare function', function () {
expect(isSorted([1, 2, 3], null, true)).to.be(true);
expect(isSorted([1, 2, 2], null, true)).to.be(false);
expect(isSorted([1, 2, 1], null, true)).to.be(false);
});
it('works with a compare function', function() {
it('works with a compare function', function () {
function compare(a, b) {
return b - a;
}
@@ -459,8 +490,8 @@ describe('ol.array', function() {
});
});
describe('linearFindNearest', function() {
it('returns expected value', function() {
describe('linearFindNearest', function () {
it('returns expected value', function () {
const arr = [1000, 500, 100];
expect(linearFindNearest(arr, 10000, 0)).to.eql(0);
@@ -509,8 +540,8 @@ describe('ol.array', function() {
});
});
describe('numberSafeCompareFunction', function() {
it('sorts as expected', function() {
describe('numberSafeCompareFunction', function () {
it('sorts as expected', function () {
const arr = [40, 200, 3000];
// default sort would yield [200, 3000, 40]
arr.sort(numberSafeCompareFunction);
@@ -518,8 +549,8 @@ describe('ol.array', function() {
});
});
describe('remove', function() {
it('removes elements from an array', function() {
describe('remove', function () {
it('removes elements from an array', function () {
const a = ['a', 'b', 'c', 'd'];
remove(a, 'c');
expect(a).to.eql(['a', 'b', 'd']);
@@ -528,8 +559,8 @@ describe('ol.array', function() {
});
});
describe('reverseSubArray', function() {
it('returns expected value', function() {
describe('reverseSubArray', function () {
it('returns expected value', function () {
let arr;
const expected = [1, 2, 3, 4, 5, 6];
@@ -551,16 +582,21 @@ describe('ol.array', function() {
});
});
describe('stableSort', function() {
describe('stableSort', function () {
let arr, wantedSortedValues;
beforeEach(function() {
arr = [{key: 3, val: 'a'}, {key: 2, val: 'b'}, {key: 3, val: 'c'},
{key: 4, val: 'd'}, {key: 3, val: 'e'}];
beforeEach(function () {
arr = [
{key: 3, val: 'a'},
{key: 2, val: 'b'},
{key: 3, val: 'c'},
{key: 4, val: 'd'},
{key: 3, val: 'e'},
];
wantedSortedValues = ['b', 'a', 'c', 'e', 'd'];
});
it('works on an array with custom comparison function', function() {
it('works on an array with custom comparison function', function () {
function comparisonFn(obj1, obj2) {
return obj1.key - obj2.key;
}
@@ -572,5 +608,4 @@ describe('ol.array', function() {
expect(wantedSortedValues).to.eql(sortedValues);
});
});
});
+12 -9
View File
@@ -1,32 +1,35 @@
import {VERSION} from '../../../src/ol/util.js';
import AssertionError from '../../../src/ol/AssertionError.js';
import {VERSION} from '../../../src/ol/util.js';
describe('ol.AssertionError', function() {
it('generates an error', function() {
describe('ol.AssertionError', function () {
it('generates an error', function () {
const error = new AssertionError(42);
expect(error).to.be.an(Error);
});
it('generates a message with a versioned url', function() {
it('generates a message with a versioned url', function () {
const error = new AssertionError(42);
const path = VERSION ? VERSION.split('-')[0] : 'latest';
expect(error.message).to.be('Assertion failed. See https://openlayers.org/en/' + path + '/doc/errors/#42 for details.');
expect(error.message).to.be(
'Assertion failed. See https://openlayers.org/en/' +
path +
'/doc/errors/#42 for details.'
);
});
it('has an error code', function() {
it('has an error code', function () {
const error = new AssertionError(42);
expect(error.code).to.be(42);
});
it('has a name', function() {
it('has a name', function () {
const error = new AssertionError(42);
expect(error.name).to.be('AssertionError');
});
it('is instanceof Error and AssertionError', function() {
it('is instanceof Error and AssertionError', function () {
const error = new AssertionError(42);
expect(error instanceof Error).to.be(true);
expect(error instanceof AssertionError).to.be(true);
});
});
+4 -7
View File
@@ -1,14 +1,11 @@
import {assert} from '../../../src/ol/asserts.js';
describe('ol.asserts', function() {
describe('ol.asserts.assert', function() {
it('throws an exception', function() {
expect(function() {
describe('ol.asserts', function () {
describe('ol.asserts.assert', function () {
it('throws an exception', function () {
expect(function () {
assert(false, 42);
}).to.throwException();
});
});
});
+82 -83
View File
@@ -1,25 +1,24 @@
import {listen} from '../../../src/ol/events.js';
import Collection from '../../../src/ol/Collection.js';
import CollectionEventType from '../../../src/ol/CollectionEventType.js';
import {listen} from '../../../src/ol/events.js';
describe('ol.collection', function() {
describe('ol.collection', function () {
let collection;
beforeEach(function() {
beforeEach(function () {
collection = new Collection();
});
describe('create an empty collection', function() {
it('creates an empty collection', function() {
describe('create an empty collection', function () {
it('creates an empty collection', function () {
expect(collection.getLength()).to.eql(0);
expect(collection.getArray()).to.be.empty();
expect(collection.item(0)).to.be(undefined);
});
});
describe('create a collection from an array', function() {
it('creates the expected collection', function() {
describe('create a collection from an array', function () {
it('creates the expected collection', function () {
const array = [0, 1, 2];
const collection = new Collection(array);
expect(collection.item(0)).to.eql(0);
@@ -28,16 +27,16 @@ describe('ol.collection', function() {
});
});
describe('push to a collection', function() {
it('adds elements to the collection', function() {
describe('push to a collection', function () {
it('adds elements to the collection', function () {
const length = collection.push(1);
expect(collection.getLength()).to.eql(length);
expect(collection.getArray()).to.eql([1]);
expect(collection.item(0)).to.eql(1);
});
it('returns the correct new length of the collection', function() {
it('returns the correct new length of the collection', function () {
let length;
listen(collection, 'add', function(event) {
listen(collection, 'add', function (event) {
if (event.element === 'remove_me') {
collection.remove(event.element);
}
@@ -49,8 +48,8 @@ describe('ol.collection', function() {
});
});
describe('pop from a collection', function() {
it('removes elements from the collection', function() {
describe('pop from a collection', function () {
it('removes elements from the collection', function () {
collection.push(1);
collection.pop();
expect(collection.getLength()).to.eql(0);
@@ -59,8 +58,8 @@ describe('ol.collection', function() {
});
});
describe('insertAt', function() {
it('inserts elements at the correct location', function() {
describe('insertAt', function () {
it('inserts elements at the correct location', function () {
collection = new Collection([0, 2]);
collection.insertAt(1, 1);
expect(collection.item(0)).to.eql(0);
@@ -69,8 +68,8 @@ describe('ol.collection', function() {
});
});
describe('setAt', function() {
it('sets at the correct location', function() {
describe('setAt', function () {
it('sets at the correct location', function () {
collection.setAt(1, 1);
expect(collection.getLength()).to.eql(2);
expect(collection.item(0)).to.be(undefined);
@@ -78,8 +77,8 @@ describe('ol.collection', function() {
});
});
describe('removeAt', function() {
it('removes elements at the correction', function() {
describe('removeAt', function () {
it('removes elements at the correction', function () {
const collection = new Collection([0, 1, 2]);
collection.removeAt(1);
expect(collection.item(0)).to.eql(0);
@@ -87,19 +86,19 @@ describe('ol.collection', function() {
});
});
describe('forEach', function() {
describe('forEach', function () {
let cb;
beforeEach(function() {
beforeEach(function () {
cb = sinon.spy();
});
describe('on an empty collection', function() {
it('does not call the callback', function() {
describe('on an empty collection', function () {
it('does not call the callback', function () {
collection.forEach(cb);
expect(cb.called).to.be(false);
});
});
describe('on a non-empty collection', function() {
it('does call the callback', function() {
describe('on a non-empty collection', function () {
it('does call the callback', function () {
collection.push(1);
collection.push(2);
collection.forEach(cb);
@@ -108,14 +107,14 @@ describe('ol.collection', function() {
});
});
describe('remove', function() {
it('removes the first matching element', function() {
describe('remove', function () {
it('removes the first matching element', function () {
const collection = new Collection([0, 1, 2]);
expect(collection.remove(1)).to.eql(1);
expect(collection.getArray()).to.eql([0, 2]);
expect(collection.getLength()).to.eql(2);
});
it('fires a remove event', function() {
it('fires a remove event', function () {
const collection = new Collection([0, 1, 2]);
const cb = sinon.spy();
listen(collection, CollectionEventType.REMOVE, cb);
@@ -123,13 +122,13 @@ describe('ol.collection', function() {
expect(cb.called).to.be(true);
expect(cb.lastCall.args[0].element).to.eql(1);
});
it('does not remove more than one matching element', function() {
it('does not remove more than one matching element', function () {
const collection = new Collection([0, 1, 1, 2]);
expect(collection.remove(1)).to.eql(1);
expect(collection.getArray()).to.eql([0, 1, 2]);
expect(collection.getLength()).to.eql(3);
});
it('returns undefined if the element is not found', function() {
it('returns undefined if the element is not found', function () {
const collection = new Collection([0, 1, 2]);
expect(collection.remove(3)).to.be(undefined);
expect(collection.getArray()).to.eql([0, 1, 2]);
@@ -137,15 +136,15 @@ describe('ol.collection', function() {
});
});
describe('setAt and event', function() {
it('does dispatch events', function() {
describe('setAt and event', function () {
it('does dispatch events', function () {
const collection = new Collection(['a', 'b']);
let added, removed, addedIndex, removedIndex;
listen(collection, CollectionEventType.ADD, function(e) {
listen(collection, CollectionEventType.ADD, function (e) {
added = e.element;
addedIndex = e.index;
});
listen(collection, CollectionEventType.REMOVE, function(e) {
listen(collection, CollectionEventType.REMOVE, function (e) {
removed = e.element;
removedIndex = e.index;
});
@@ -157,11 +156,11 @@ describe('ol.collection', function() {
});
});
describe('removeAt and event', function() {
it('does dispatch events', function() {
describe('removeAt and event', function () {
it('does dispatch events', function () {
const collection = new Collection(['a']);
let removed, removedIndex;
listen(collection, CollectionEventType.REMOVE, function(e) {
listen(collection, CollectionEventType.REMOVE, function (e) {
removed = e.element;
removedIndex = e.index;
});
@@ -171,11 +170,11 @@ describe('ol.collection', function() {
});
});
describe('insertAt and event', function() {
it('does dispatch events', function() {
describe('insertAt and event', function () {
it('does dispatch events', function () {
const collection = new Collection([0, 2]);
let added, addedIndex;
listen(collection, CollectionEventType.ADD, function(e) {
listen(collection, CollectionEventType.ADD, function (e) {
added = e.element;
addedIndex = e.index;
});
@@ -185,10 +184,11 @@ describe('ol.collection', function() {
});
});
describe('setAt beyond end', function() {
it('triggers events properly', function() {
const added = [], addedIndexes = [];
listen(collection, CollectionEventType.ADD, function(e) {
describe('setAt beyond end', function () {
it('triggers events properly', function () {
const added = [],
addedIndexes = [];
listen(collection, CollectionEventType.ADD, function (e) {
added.push(e.element);
addedIndexes.push(e.index);
});
@@ -205,41 +205,41 @@ describe('ol.collection', function() {
});
});
describe('change:length event', function() {
describe('change:length event', function () {
let collection, cb;
beforeEach(function() {
beforeEach(function () {
collection = new Collection([0, 1, 2]);
cb = sinon.spy();
listen(collection, 'change:length', cb);
});
describe('insertAt', function() {
it('triggers change:length event', function() {
describe('insertAt', function () {
it('triggers change:length event', function () {
collection.insertAt(2, 3);
expect(cb.called).to.be(true);
});
});
describe('removeAt', function() {
it('triggers change:length event', function() {
describe('removeAt', function () {
it('triggers change:length event', function () {
collection.removeAt(0);
expect(cb.called).to.be(true);
});
});
describe('setAt', function() {
it('does not trigger change:length event', function() {
describe('setAt', function () {
it('does not trigger change:length event', function () {
collection.setAt(1, 1);
expect(cb.called).to.be(false);
});
});
});
describe('add event', function() {
it('triggers add when pushing', function() {
describe('add event', function () {
it('triggers add when pushing', function () {
const collection = new Collection();
let elem, addedIndex;
listen(collection, CollectionEventType.ADD, function(e) {
listen(collection, CollectionEventType.ADD, function (e) {
elem = e.element;
addedIndex = e.index;
});
@@ -249,15 +249,15 @@ describe('ol.collection', function() {
});
});
describe('remove event', function() {
describe('remove event', function () {
let collection, cb1, cb2;
beforeEach(function() {
beforeEach(function () {
collection = new Collection([1]);
cb1 = sinon.spy();
cb2 = sinon.spy();
});
describe('setAt', function() {
it('triggers remove', function() {
describe('setAt', function () {
it('triggers remove', function () {
listen(collection, CollectionEventType.ADD, cb1);
listen(collection, CollectionEventType.REMOVE, cb2);
collection.setAt(0, 2);
@@ -265,8 +265,8 @@ describe('ol.collection', function() {
expect(cb1.lastCall.args[0].element).to.eql(2);
});
});
describe('pop', function() {
it('triggers remove', function() {
describe('pop', function () {
it('triggers remove', function () {
listen(collection, CollectionEventType.REMOVE, cb1);
collection.pop();
expect(cb1.lastCall.args[0].element).to.eql(1);
@@ -274,18 +274,19 @@ describe('ol.collection', function() {
});
});
describe('extending a collection', function() {
it('adds elements to end of the collection', function() {
describe('extending a collection', function () {
it('adds elements to end of the collection', function () {
collection.extend([1, 2]);
expect(collection.getLength()).to.eql(2);
expect(collection.getArray()).to.eql([1, 2]);
expect(collection.item(0)).to.eql(1);
expect(collection.item(1)).to.eql(2);
});
it('fires events', function() {
it('fires events', function () {
const collection = new Collection();
const elems = [], addedIndexes = [];
listen(collection, CollectionEventType.ADD, function(e) {
const elems = [],
addedIndexes = [];
listen(collection, CollectionEventType.ADD, function (e) {
elems.push(e.element);
addedIndexes.push(e.index);
});
@@ -295,74 +296,72 @@ describe('ol.collection', function() {
});
});
describe('unique collection', function() {
it('allows unique items in the constructor', function() {
describe('unique collection', function () {
it('allows unique items in the constructor', function () {
new Collection([{}, {}, {}], {unique: true});
});
it('throws if duplicate items are passed to the constructor', function() {
it('throws if duplicate items are passed to the constructor', function () {
const item = {};
const call = function() {
const call = function () {
new Collection([item, item], {unique: true});
};
expect(call).to.throwException();
});
it('allows unique items to be added via push', function() {
it('allows unique items to be added via push', function () {
const unique = new Collection(undefined, {unique: true});
unique.push({});
unique.push({});
});
it('throws if duplicate items are added via push', function() {
it('throws if duplicate items are added via push', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.push(item);
const call = function() {
const call = function () {
unique.push(item);
};
expect(call).to.throwException();
});
it('allows unique items to be added via insertAt', function() {
it('allows unique items to be added via insertAt', function () {
const unique = new Collection(undefined, {unique: true});
unique.insertAt(0, {});
unique.insertAt(0, {});
});
it('throws if duplicate items are added via insertAt', function() {
it('throws if duplicate items are added via insertAt', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.insertAt(0, item);
const call = function() {
const call = function () {
unique.insertAt(0, item);
};
expect(call).to.throwException();
});
it('allows unique items to be added via setAt', function() {
it('allows unique items to be added via setAt', function () {
const unique = new Collection(undefined, {unique: true});
unique.setAt(0, {});
unique.setAt(1, {});
});
it('allows items to be reset via setAt', function() {
it('allows items to be reset via setAt', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.setAt(0, item);
unique.setAt(0, item);
});
it('throws if duplicate items are added via setAt', function() {
it('throws if duplicate items are added via setAt', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.setAt(0, item);
const call = function() {
const call = function () {
unique.setAt(1, item);
};
expect(call).to.throwException();
});
});
});
+62 -67
View File
@@ -4,166 +4,162 @@ import {
fromString,
isStringColor,
normalize,
toString
toString,
} from '../../../src/ol/color.js';
describe('ol.color', function() {
describe('asArray()', function() {
it('returns the same for an array', function() {
describe('ol.color', function () {
describe('asArray()', function () {
it('returns the same for an array', function () {
const color = [1, 2, 3, 0.4];
const got = asArray(color);
expect(got).to.be(color);
});
it('returns an array given an rgba string', function() {
it('returns an array given an rgba string', function () {
const color = asArray('rgba(1,2,3,0.4)');
expect(color).to.eql([1, 2, 3, 0.4]);
});
it('returns an array given an rgb string', function() {
it('returns an array given an rgb string', function () {
const color = asArray('rgb(1,2,3)');
expect(color).to.eql([1, 2, 3, 1]);
});
it('returns an array given a hex string', function() {
it('returns an array given a hex string', function () {
const color = asArray('#00ccff');
expect(color).to.eql([0, 204, 255, 1]);
});
it('returns an array given a hex string with alpha', function() {
it('returns an array given a hex string with alpha', function () {
const color = asArray('#00ccffb0');
expect(color).to.eql([0, 204, 255, 176 / 255]);
});
});
describe('asString()', function() {
it('returns the same for a string', function() {
describe('asString()', function () {
it('returns the same for a string', function () {
const color = 'rgba(0,1,2,0.3)';
const got = asString(color);
expect(got).to.be(color);
});
it('returns a string given an rgba array', function() {
it('returns a string given an rgba array', function () {
const color = asString([1, 2, 3, 0.4]);
expect(color).to.eql('rgba(1,2,3,0.4)');
});
it('returns a string given an rgb array', function() {
it('returns a string given an rgb array', function () {
const color = asString([1, 2, 3]);
expect(color).to.eql('rgba(1,2,3,1)');
});
});
describe('fromString()', function() {
it('can parse 3-digit hex colors', function() {
describe('fromString()', function () {
it('can parse 3-digit hex colors', function () {
expect(fromString('#087')).to.eql([0, 136, 119, 1]);
});
it('can parse 4-digit hex colors', function() {
it('can parse 4-digit hex colors', function () {
expect(fromString('#0876')).to.eql([0, 136, 119, 102 / 255]);
});
it('can parse 6-digit hex colors', function() {
it('can parse 6-digit hex colors', function () {
expect(fromString('#56789a')).to.eql([86, 120, 154, 1]);
});
it('can parse 8-digit hex colors', function() {
it('can parse 8-digit hex colors', function () {
expect(fromString('#56789acc')).to.eql([86, 120, 154, 204 / 255]);
});
it('can parse rgb colors', function() {
it('can parse rgb colors', function () {
expect(fromString('rgb(0, 0, 255)')).to.eql([0, 0, 255, 1]);
});
it('ignores whitespace before, between & after numbers (rgb)', function() {
expect(fromString('rgb( \t 0 , 0 \n , 255 )')).to.eql(
[0, 0, 255, 1]);
it('ignores whitespace before, between & after numbers (rgb)', function () {
expect(fromString('rgb( \t 0 , 0 \n , 255 )')).to.eql([0, 0, 255, 1]);
});
it('can parse rgba colors', function() {
it('can parse rgba colors', function () {
// opacity 0
expect(fromString('rgba(255, 255, 0, 0)')).to.eql(
[255, 255, 0, 0]);
expect(fromString('rgba(255, 255, 0, 0)')).to.eql([255, 255, 0, 0]);
// opacity 0.0 (simple float)
expect(fromString('rgba(255, 255, 0, 0.0)')).to.eql(
[255, 255, 0, 0]);
expect(fromString('rgba(255, 255, 0, 0.0)')).to.eql([255, 255, 0, 0]);
// opacity 0.0000000000000000 (float with 16 digits)
expect(fromString('rgba(255, 255, 0, 0.0000000000000000)')).to.eql(
[255, 255, 0, 0]);
expect(fromString('rgba(255, 255, 0, 0.0000000000000000)')).to.eql([
255,
255,
0,
0,
]);
// opacity 0.1 (simple float)
expect(fromString('rgba(255, 255, 0, 0.1)')).to.eql(
[255, 255, 0, 0.1]);
expect(fromString('rgba(255, 255, 0, 0.1)')).to.eql([255, 255, 0, 0.1]);
// opacity 0.1111111111111111 (float with 16 digits)
expect(fromString('rgba(255, 255, 0, 0.1111111111111111)')).to.eql(
[255, 255, 0, 0.1111111111111111]);
expect(fromString('rgba(255, 255, 0, 0.1111111111111111)')).to.eql([
255,
255,
0,
0.1111111111111111,
]);
// opacity 1
expect(fromString('rgba(255, 255, 0, 1)')).to.eql(
[255, 255, 0, 1]);
expect(fromString('rgba(255, 255, 0, 1)')).to.eql([255, 255, 0, 1]);
// opacity 1.0
expect(fromString('rgba(255, 255, 0, 1.0)')).to.eql(
[255, 255, 0, 1]);
expect(fromString('rgba(255, 255, 0, 1.0)')).to.eql([255, 255, 0, 1]);
// opacity 1.0000000000000000
expect(fromString('rgba(255, 255, 0, 1.0000000000000000)')).to.eql(
[255, 255, 0, 1]);
expect(fromString('rgba(255, 255, 0, 1.0000000000000000)')).to.eql([
255,
255,
0,
1,
]);
// with 30 decimal digits
expect(fromString('rgba(255, 255, 0, 0.123456789012345678901234567890)')).to.eql(
[255, 255, 0, 0.123456789012345678901234567890]);
expect(
fromString('rgba(255, 255, 0, 0.123456789012345678901234567890)')
).to.eql([255, 255, 0, 0.12345678901234567890123456789]);
});
it('ignores whitespace before, between & after numbers (rgba)', function() {
expect(fromString('rgba( \t 0 , 0 \n , 255 , 0.4711 )')).to.eql(
[0, 0, 255, 0.4711]);
it('ignores whitespace before, between & after numbers (rgba)', function () {
expect(
fromString('rgba( \t 0 , 0 \n , 255 , 0.4711 )')
).to.eql([0, 0, 255, 0.4711]);
});
it('throws an error on invalid colors', function() {
it('throws an error on invalid colors', function () {
const invalidColors = ['tuesday', '#12345', '#1234567'];
let i, ii;
for (i = 0, ii = invalidColors.length; i < ii; ++i) {
expect(function() {
expect(function () {
fromString(invalidColors[i]);
}).to.throwException();
}
});
});
describe('normalize()', function() {
it('clamps out-of-range channels', function() {
describe('normalize()', function () {
it('clamps out-of-range channels', function () {
expect(normalize([-1, 256, 0, 2])).to.eql([0, 255, 0, 1]);
});
it('rounds color channels to integers', function() {
it('rounds color channels to integers', function () {
expect(normalize([1.2, 2.5, 3.7, 1])).to.eql([1, 3, 4, 1]);
});
});
describe('toString()', function() {
it('converts valid colors', function() {
describe('toString()', function () {
it('converts valid colors', function () {
expect(toString([1, 2, 3, 0.4])).to.be('rgba(1,2,3,0.4)');
});
it('rounds to integers if needed', function() {
it('rounds to integers if needed', function () {
expect(toString([1.2, 2.5, 3.7, 0.4])).to.be('rgba(1,3,4,0.4)');
});
it('sets default alpha value if undefined', function() {
it('sets default alpha value if undefined', function () {
expect(toString([0, 0, 0])).to.be('rgba(0,0,0,1)');
});
});
describe('isValid()', function() {
it('correctly detects valid colors', function() {
describe('isValid()', function () {
it('correctly detects valid colors', function () {
expect(isStringColor('rgba(1,3,4,0.4)')).to.be(true);
expect(isStringColor('rgb(1,3,4)')).to.be(true);
expect(isStringColor('lightgreen')).to.be(true);
@@ -172,6 +168,5 @@ describe('ol.color', function() {
expect(isStringColor('notacolor')).to.be(false);
expect(isStringColor('red_')).to.be(false);
});
});
});
+44 -36
View File
@@ -1,18 +1,17 @@
import Attribution from '../../../../src/ol/control/Attribution.js';
import Map from '../../../../src/ol/Map.js';
import Tile from '../../../../src/ol/Tile.js';
import View from '../../../../src/ol/View.js';
import Attribution from '../../../../src/ol/control/Attribution.js';
import TileLayer from '../../../../src/ol/layer/Tile.js';
import TileSource from '../../../../src/ol/source/Tile.js';
import View from '../../../../src/ol/View.js';
import {createXYZ} from '../../../../src/ol/tilegrid.js';
describe('ol.control.Attribution', function() {
describe('ol.control.Attribution', function () {
let map;
const tileLoadFunction = function() {
const tileLoadFunction = function () {
const tile = new Tile([0, 0, -1], 2 /* LOADED */);
tile.getImage = function() {
tile.getImage = function () {
const image = new Image();
image.width = 256;
image.height = 256;
@@ -21,98 +20,107 @@ describe('ol.control.Attribution', function() {
return tile;
};
beforeEach(function() {
beforeEach(function () {
const target = document.createElement('div');
target.style.width = '100px';
target.style.height = '100px';
document.body.appendChild(target);
map = new Map({
target: target,
controls: [new Attribution({
collapsed: false,
collapsible: false
})],
controls: [
new Attribution({
collapsed: false,
collapsible: false,
}),
],
layers: [
new TileLayer({
source: new TileSource({
projection: 'EPSG:3857',
tileGrid: createXYZ(),
attributions: 'foo'
})
attributions: 'foo',
}),
}),
new TileLayer({
source: new TileSource({
projection: 'EPSG:3857',
tileGrid: createXYZ(),
attributions: 'bar'
})
attributions: 'bar',
}),
}),
new TileLayer({
source: new TileSource({
projection: 'EPSG:3857',
tileGrid: createXYZ(),
attributions: 'foo'
})
})
attributions: 'foo',
}),
}),
],
view: new View({
center: [0, 0],
zoom: 0
})
zoom: 0,
}),
});
map.getLayers().forEach(function(layer) {
map.getLayers().forEach(function (layer) {
const source = layer.getSource();
source.getTile = tileLoadFunction;
});
});
afterEach(function() {
afterEach(function () {
disposeMap(map);
map = null;
});
it('does not add duplicate attributions', function() {
it('does not add duplicate attributions', function () {
map.renderSync();
const attribution = map.getTarget().querySelectorAll('.ol-attribution li');
expect(attribution.length).to.be(2);
});
it('renders attributions as non-collapsible if source is configured with attributionsCollapsible set to false', function() {
it('renders attributions as non-collapsible if source is configured with attributionsCollapsible set to false', function () {
map.getControls().clear();
map.addControl(new Attribution());
const source = new TileSource({
projection: 'EPSG:3857',
tileGrid: createXYZ(),
attributions: 'foo',
attributionsCollapsible: false
attributionsCollapsible: false,
});
source.getTile = tileLoadFunction;
map.addLayer(new TileLayer({
source: source
}));
map.addLayer(
new TileLayer({
source: source,
})
);
map.renderSync();
const attribution = map.getTarget().querySelectorAll('.ol-attribution.ol-uncollapsible');
const attribution = map
.getTarget()
.querySelectorAll('.ol-attribution.ol-uncollapsible');
expect(attribution.length).to.be(1);
});
it('renders attributions as collapsible if configured with collapsible set to true', function() {
it('renders attributions as collapsible if configured with collapsible set to true', function () {
map.getControls().clear();
map.addControl(new Attribution({collapsible: true}));
const source = new TileSource({
projection: 'EPSG:3857',
tileGrid: createXYZ(),
attributions: 'foo',
attributionsCollapsible: false
attributionsCollapsible: false,
});
source.getTile = tileLoadFunction;
map.addLayer(new TileLayer({
source: source
}));
map.addLayer(
new TileLayer({
source: source,
})
);
map.renderSync();
const attribution = map.getTarget().querySelectorAll('.ol-attribution.ol-uncollapsible');
const attribution = map
.getTarget()
.querySelectorAll('.ol-attribution.ol-uncollapsible');
expect(attribution.length).to.be(0);
});
});
+18 -18
View File
@@ -1,35 +1,35 @@
import Map from '../../../../src/ol/Map.js';
import Control from '../../../../src/ol/control/Control.js';
import Map from '../../../../src/ol/Map.js';
describe('ol.control.Control', function() {
describe('ol.control.Control', function () {
let map, control;
beforeEach(function() {
beforeEach(function () {
map = new Map({
target: document.createElement('div')
target: document.createElement('div'),
});
const element = document.createElement('div');
control = new Control({element: element});
control.setMap(map);
});
afterEach(function() {
afterEach(function () {
disposeMap(map);
map = null;
control = null;
});
describe('dispose', function() {
it('removes the control element from its parent', function() {
describe('dispose', function () {
it('removes the control element from its parent', function () {
control.dispose();
expect(control.element.parentNode).to.be(null);
});
});
});
describe('ol.control.Control\'s target', function() {
describe('target as string or element', function() {
it('transforms target from string to element', function() {
describe("ol.control.Control's target", function () {
describe('target as string or element', function () {
it('transforms target from string to element', function () {
const target = document.createElement('div');
target.id = 'mycontrol';
document.body.appendChild(target);
@@ -38,7 +38,7 @@ describe('ol.control.Control\'s target', function() {
ctrl.dispose();
target.parentNode.removeChild(target);
});
it('accepts element for target', function() {
it('accepts element for target', function () {
const target = document.createElement('div');
target.id = 'mycontrol';
document.body.appendChild(target);
@@ -47,7 +47,7 @@ describe('ol.control.Control\'s target', function() {
ctrl.dispose();
target.parentNode.removeChild(target);
});
it('ignores non-existing target id', function() {
it('ignores non-existing target id', function () {
const ctrl = new Control({target: 'doesnotexist'});
expect(ctrl.target_).to.equal(null);
ctrl.dispose();
@@ -55,22 +55,22 @@ describe('ol.control.Control\'s target', function() {
});
});
describe('ol.control.Control\'s event target', function() {
it('is the Control when the Control uses the default target', function(done) {
describe("ol.control.Control's event target", function () {
it('is the Control when the Control uses the default target', function (done) {
const ctrl = new Control({element: document.createElement('div')});
ctrl.on('test-event', function(e) {
ctrl.on('test-event', function (e) {
expect(e.target).to.be(ctrl);
done();
});
ctrl.dispatchEvent('test-event');
ctrl.dispose();
});
it('is the Control when the Control has a custom target', function(done) {
it('is the Control when the Control has a custom target', function (done) {
const ctrl = new Control({
element: document.createElement('div'),
target: document.createElement('div')
target: document.createElement('div'),
});
ctrl.on('test-event', function(e) {
ctrl.on('test-event', function (e) {
expect(e.target).to.be(ctrl);
done();
});
+3 -7
View File
@@ -1,14 +1,10 @@
import FullScreen from '../../../../src/ol/control/FullScreen.js';
describe('ol.control.FullScreen', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.control.FullScreen', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new FullScreen();
expect(instance).to.be.an(FullScreen);
});
});
});
+30 -24
View File
@@ -1,34 +1,31 @@
import EventType from '../../../../src/ol/pointer/EventType.js';
import Map from '../../../../src/ol/Map.js';
import MousePosition from '../../../../src/ol/control/MousePosition.js';
import View from '../../../../src/ol/View.js';
import EventType from '../../../../src/ol/pointer/EventType.js';
describe('ol/control/MousePosition', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol/control/MousePosition', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new MousePosition();
expect(instance).to.be.an(MousePosition);
expect(instance.element.className).to.be('ol-mouse-position');
});
it('creates the element with the provided class name', function() {
it('creates the element with the provided class name', function () {
const className = 'foobar';
const instance = new MousePosition({
className: className
className: className,
});
expect(instance.element.className).to.be(className);
});
});
describe('configuration options', function() {
describe('configuration options', function () {
let target, map;
const width = 360;
const height = 180;
beforeEach(function() {
beforeEach(function () {
target = document.createElement('div');
const style = target.style;
style.position = 'absolute';
@@ -44,11 +41,11 @@ describe('ol/control/MousePosition', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
});
@@ -59,20 +56,23 @@ describe('ol/control/MousePosition', function() {
const position = viewport.getBoundingClientRect();
const evt = new PointerEvent(type, {
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2
clientY: position.top + y + height / 2,
});
document.querySelector('div.ol-viewport').dispatchEvent(evt);
}
describe('undefinedHTML', function() {
it('renders undefinedHTML when mouse moves out', function() {
describe('undefinedHTML', function () {
it('renders undefinedHTML when mouse moves out', function () {
const ctrl = new MousePosition({
undefinedHTML: 'some text'
undefinedHTML: 'some text',
});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector('.ol-mouse-position', map.getTarget());
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('some text');
@@ -84,12 +84,15 @@ describe('ol/control/MousePosition', function() {
expect(element.innerHTML).to.be('some text');
});
it('clears the mouse position by default when the mouse moves outside the viewport', function() {
it('clears the mouse position by default when the mouse moves outside the viewport', function () {
const ctrl = new MousePosition();
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector('.ol-mouse-position', map.getTarget());
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('&nbsp;');
@@ -102,14 +105,17 @@ describe('ol/control/MousePosition', function() {
expect(element.innerHTML).to.be('&nbsp;');
});
it('retains the mouse position when undefinedHTML is falsey and mouse moves outside the viewport', function() {
it('retains the mouse position when undefinedHTML is falsey and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({
undefinedHTML: ''
undefinedHTML: '',
});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector('.ol-mouse-position', map.getTarget());
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('');
+45 -36
View File
@@ -1,46 +1,45 @@
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import Control from '../../../../src/ol/control/Control.js';
import Map from '../../../../src/ol/Map.js';
import OverviewMap from '../../../../src/ol/control/OverviewMap.js';
import View from '../../../../src/ol/View.js';
describe('ol.control.OverviewMap', function() {
describe('ol.control.OverviewMap', function () {
let map, target;
beforeEach(function() {
beforeEach(function () {
target = document.createElement('div');
document.body.appendChild(target);
map = new Map({
target: target
target: target,
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
map = null;
target = null;
});
describe('constructor', function() {
it('creates an overview map with the default options', function() {
describe('constructor', function () {
it('creates an overview map with the default options', function () {
const control = new OverviewMap();
expect(control).to.be.a(OverviewMap);
expect(control).to.be.a(Control);
});
});
describe('setMap()', function() {
it('keeps ovmap view rotation in sync with map view rotation', function() {
describe('setMap()', function () {
it('keeps ovmap view rotation in sync with map view rotation', function () {
const view = new View({
center: [0, 0],
zoom: 0,
rotation: Math.PI / 2
rotation: Math.PI / 2,
});
map.setView(view);
const control = new OverviewMap({
rotateWithView: true
rotateWithView: true,
});
map.addControl(control);
const ovView = control.ovmap_.getView();
@@ -50,9 +49,9 @@ describe('ol.control.OverviewMap', function() {
expect(ovView.getRotation()).to.be(Math.PI / 4);
});
it('maintains rotation in sync if view added later', function() {
it('maintains rotation in sync if view added later', function () {
const control = new OverviewMap({
rotateWithView: true
rotateWithView: true,
});
map.addControl(control);
const ovInitialView = control.ovmap_.getView();
@@ -61,7 +60,7 @@ describe('ol.control.OverviewMap', function() {
const view = new View({
center: [0, 0],
zoom: 0,
rotation: Math.PI / 2
rotation: Math.PI / 2,
});
map.setView(view);
const ovView = control.ovmap_.getView();
@@ -71,15 +70,15 @@ describe('ol.control.OverviewMap', function() {
expect(ovView.getRotation()).to.be(Math.PI / 4);
});
it('stops listening to old maps', function() {
it('stops listening to old maps', function () {
const control = new OverviewMap({
rotateWithView: true
rotateWithView: true,
});
const view = new View({
center: [0, 0],
zoom: 0,
rotation: 0
rotation: 0,
});
map.setView(view);
map.addControl(control);
@@ -94,39 +93,51 @@ describe('ol.control.OverviewMap', function() {
expect(ovView.getRotation()).to.be(Math.PI / 8);
});
it('reflects projection change of main map', function() {
it('reflects projection change of main map', function () {
const control = new OverviewMap({
rotateWithView: true
rotateWithView: true,
});
map.addControl(control);
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
'EPSG:3857'
);
map.setView(new View({
projection: 'EPSG:4326'
}));
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:4326');
map.setView(
new View({
projection: 'EPSG:4326',
})
);
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
'EPSG:4326'
);
});
it('retains explicitly set view', function() {
it('retains explicitly set view', function () {
const overviewMapView = new View();
const control = new OverviewMap({
rotateWithView: true,
view: overviewMapView
view: overviewMapView,
});
map.addControl(control);
expect(control.ovmap_.getView()).to.be(overviewMapView);
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
'EPSG:3857'
);
map.setView(new View({
projection: 'EPSG:4326'
}));
map.setView(
new View({
projection: 'EPSG:4326',
})
);
expect(control.ovmap_.getView()).to.be(overviewMapView);
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
'EPSG:3857'
);
});
it('set target to null', function() {
it('set target to null', function () {
const control = new OverviewMap();
map.addControl(control);
@@ -137,7 +148,5 @@ describe('ol.control.OverviewMap', function() {
expect(control.ovmap_.getTarget()).to.be(null);
});
});
});
+3 -7
View File
@@ -1,14 +1,10 @@
import Rotate from '../../../../src/ol/control/Rotate.js';
describe('ol.control.Rotate', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.control.Rotate', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new Rotate();
expect(instance).to.be.an(Rotate);
});
});
});
+255 -211
View File
@@ -1,118 +1,133 @@
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import ScaleLine, {render} from '../../../../src/ol/control/ScaleLine.js';
import {fromLonLat, clearAllProjections, addCommon} from '../../../../src/ol/proj.js';
import Projection from '../../../../src/ol/proj/Projection.js';
import ScaleLine, {render} from '../../../../src/ol/control/ScaleLine.js';
import View from '../../../../src/ol/View.js';
import proj4 from 'proj4';
import {
addCommon,
clearAllProjections,
fromLonLat,
} from '../../../../src/ol/proj.js';
import {register} from '../../../../src/ol/proj/proj4.js';
describe('ol.control.ScaleLine', function() {
describe('ol.control.ScaleLine', function () {
let map;
beforeEach(function() {
beforeEach(function () {
const target = document.createElement('div');
target.style.height = '256px';
document.body.appendChild(target);
map = new Map({
target: target
target: target,
});
});
afterEach(function() {
afterEach(function () {
disposeMap(map);
map = null;
});
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const ctrl = new ScaleLine();
expect(ctrl).to.be.an(ScaleLine);
});
});
describe('configuration options', function() {
describe('className', function() {
it('defaults to "ol-scale-line"', function() {
describe('configuration options', function () {
describe('className', function () {
it('defaults to "ol-scale-line"', function () {
const ctrl = new ScaleLine();
ctrl.setMap(map);
const element = document.querySelector('.ol-scale-line', map.getTarget());
const element = document.querySelector(
'.ol-scale-line',
map.getTarget()
);
expect(element).to.not.be(null);
expect(element).to.be.a(HTMLDivElement);
});
it('can be configured', function() {
it('can be configured', function () {
const ctrl = new ScaleLine({
className: 'humpty-dumpty'
className: 'humpty-dumpty',
});
ctrl.setMap(map);
// check that the default was not chosen
const element1 = document.querySelector('.ol-scale-line', map.getTarget());
const element1 = document.querySelector(
'.ol-scale-line',
map.getTarget()
);
expect(element1).to.be(null);
// check if the configured classname was chosen
const element2 = document.querySelector('.humpty-dumpty', map.getTarget());
const element2 = document.querySelector(
'.humpty-dumpty',
map.getTarget()
);
expect(element2).to.not.be(null);
expect(element2).to.be.a(HTMLDivElement);
});
});
describe('minWidth', function() {
it('defaults to 64', function() {
describe('minWidth', function () {
it('defaults to 64', function () {
const ctrl = new ScaleLine();
expect(ctrl.minWidth_).to.be(64);
});
it('can be configured', function() {
it('can be configured', function () {
const ctrl = new ScaleLine({
minWidth: 4711
minWidth: 4711,
});
expect(ctrl.minWidth_).to.be(4711);
});
});
describe('render', function() {
it('defaults to `ol.control.ScaleLine.render`', function() {
describe('render', function () {
it('defaults to `ol.control.ScaleLine.render`', function () {
const ctrl = new ScaleLine();
expect(ctrl.render_).to.be(render);
});
it('can be configured', function() {
const myRender = function() {};
it('can be configured', function () {
const myRender = function () {};
const ctrl = new ScaleLine({
render: myRender
render: myRender,
});
expect(ctrl.render_).to.be(myRender);
});
});
});
describe('synchronisation with map view', function() {
it('calls `render` as soon as the map is rendered', function(done) {
describe('synchronisation with map view', function () {
it('calls `render` as soon as the map is rendered', function (done) {
const renderSpy = sinon.spy();
const ctrl = new ScaleLine({
render: renderSpy
render: renderSpy,
});
expect(renderSpy.called).to.be(false);
ctrl.setMap(map);
expect(renderSpy.called).to.be(false);
map.setView(new View({
center: [0, 0],
zoom: 0
}));
map.setView(
new View({
center: [0, 0],
zoom: 0,
})
);
expect(renderSpy.called).to.be(false);
map.once('postrender', function() {
map.once('postrender', function () {
expect(renderSpy.called).to.be(true);
expect(renderSpy.callCount).to.be(1);
done();
});
});
it('calls `render` as often as the map is rendered', function() {
it('calls `render` as often as the map is rendered', function () {
const renderSpy = sinon.spy();
const ctrl = new ScaleLine({
render: renderSpy
render: renderSpy,
});
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
zoom: 0
}));
map.setView(
new View({
center: [0, 0],
zoom: 0,
})
);
map.renderSync();
expect(renderSpy.callCount).to.be(1);
map.renderSync();
@@ -120,18 +135,20 @@ describe('ol.control.ScaleLine', function() {
map.renderSync();
expect(renderSpy.callCount).to.be(3);
});
it('calls `render` as when the view changes', function(done) {
it('calls `render` as when the view changes', function (done) {
const renderSpy = sinon.spy();
const ctrl = new ScaleLine({
render: renderSpy
render: renderSpy,
});
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
zoom: 0
}));
map.setView(
new View({
center: [0, 0],
zoom: 0,
})
);
map.renderSync();
map.once('postrender', function() {
map.once('postrender', function () {
expect(renderSpy.callCount).to.be(2);
done();
});
@@ -139,47 +156,51 @@ describe('ol.control.ScaleLine', function() {
});
});
describe('static method `render`', function() {
it('updates the rendered text', function() {
describe('static method `render`', function () {
it('updates the rendered text', function () {
const ctrl = new ScaleLine();
expect(ctrl.element.innerText).to.be('');
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
multiWorld: true,
zoom: 0
}));
map.setView(
new View({
center: [0, 0],
multiWorld: true,
zoom: 0,
})
);
map.renderSync();
expect(ctrl.element.innerText).to.be('10000 km');
});
});
describe('#getUnits', function() {
it('returns "metric" by default', function() {
describe('#getUnits', function () {
it('returns "metric" by default', function () {
const ctrl = new ScaleLine();
expect(ctrl.getUnits()).to.be('metric');
});
it('returns what is configured via `units` property', function() {
it('returns what is configured via `units` property', function () {
const ctrl = new ScaleLine({
units: 'nautical'
units: 'nautical',
});
expect(ctrl.getUnits()).to.be('nautical');
});
it('returns what is configured `setUnits` method', function() {
it('returns what is configured `setUnits` method', function () {
const ctrl = new ScaleLine();
ctrl.setUnits('nautical');
expect(ctrl.getUnits()).to.be('nautical');
});
});
describe('#setUnits', function() {
it('triggers rerendering', function() {
describe('#setUnits', function () {
it('triggers rerendering', function () {
const ctrl = new ScaleLine();
map.setView(new View({
center: [0, 0],
multiWorld: true,
zoom: 0
}));
map.setView(
new View({
center: [0, 0],
multiWorld: true,
zoom: 0,
})
);
ctrl.setMap(map);
map.renderSync();
@@ -191,52 +212,54 @@ describe('ol.control.ScaleLine', function() {
});
});
describe('different units result in different contents', function() {
describe('different units result in different contents', function () {
let ctrl;
let metricHtml;
let nauticalHtml;
let degreesHtml;
let imperialHtml;
let usHtml;
beforeEach(function(done) {
beforeEach(function (done) {
ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
zoom: 0
}));
map.once('postrender', function() {
map.setView(
new View({
center: [0, 0],
zoom: 0,
})
);
map.once('postrender', function () {
metricHtml = ctrl.element.innerHTML;
done();
});
});
afterEach(function() {
afterEach(function () {
map.setView(null);
map.removeControl(ctrl);
});
it('renders a scaleline for "metric"', function() {
it('renders a scaleline for "metric"', function () {
expect(metricHtml).to.not.be(undefined);
});
it('renders a different scaleline for "nautical"', function() {
it('renders a different scaleline for "nautical"', function () {
ctrl.setUnits('nautical');
nauticalHtml = ctrl.element.innerHTML;
expect(nauticalHtml).to.not.be(metricHtml);
});
it('renders a different scaleline for "degrees"', function() {
it('renders a different scaleline for "degrees"', function () {
ctrl.setUnits('degrees');
degreesHtml = ctrl.element.innerHTML;
expect(degreesHtml).to.not.be(metricHtml);
expect(degreesHtml).to.not.be(nauticalHtml);
});
it('renders a different scaleline for "imperial"', function() {
it('renders a different scaleline for "imperial"', function () {
ctrl.setUnits('imperial');
imperialHtml = ctrl.element.innerHTML;
expect(imperialHtml).to.not.be(metricHtml);
expect(imperialHtml).to.not.be(nauticalHtml);
expect(imperialHtml).to.not.be(degreesHtml);
});
it('renders a different scaleline for "us"', function() {
it('renders a different scaleline for "us"', function () {
ctrl.setUnits('us');
usHtml = ctrl.element.innerHTML;
expect(usHtml).to.not.be(metricHtml);
@@ -247,94 +270,110 @@ describe('ol.control.ScaleLine', function() {
});
});
describe('projections affect the scaleline', function() {
beforeEach(function() {
proj4.defs('Indiana-East', 'PROJCS["IN83-EF",GEOGCS["LL83",DATUM["NAD83",' +
'SPHEROID["GRS1980",6378137.000,298.25722210]],PRIMEM["Greenwich",0],' +
'UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],' +
'PARAMETER["false_easting",328083.333],' +
'PARAMETER["false_northing",820208.333],' +
'PARAMETER["scale_factor",0.999966666667],' +
'PARAMETER["central_meridian",-85.66666666666670],' +
'PARAMETER["latitude_of_origin",37.50000000000000],' +
'UNIT["Foot_US",0.30480060960122]]');
describe('projections affect the scaleline', function () {
beforeEach(function () {
proj4.defs(
'Indiana-East',
'PROJCS["IN83-EF",GEOGCS["LL83",DATUM["NAD83",' +
'SPHEROID["GRS1980",6378137.000,298.25722210]],PRIMEM["Greenwich",0],' +
'UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],' +
'PARAMETER["false_easting",328083.333],' +
'PARAMETER["false_northing",820208.333],' +
'PARAMETER["scale_factor",0.999966666667],' +
'PARAMETER["central_meridian",-85.66666666666670],' +
'PARAMETER["latitude_of_origin",37.50000000000000],' +
'UNIT["Foot_US",0.30480060960122]]'
);
register(proj4);
});
afterEach(function() {
afterEach(function () {
clearAllProjections();
addCommon();
});
it('is rendered differently for different projections', function() {
it('is rendered differently for different projections', function () {
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: fromLonLat([7, 52]),
zoom: 2,
projection: 'EPSG:3857'
}));
map.setView(
new View({
center: fromLonLat([7, 52]),
zoom: 2,
projection: 'EPSG:3857',
})
);
map.renderSync();
expect(ctrl.element.innerText).to.be('2000 km');
map.setView(new View({
center: [7, 52],
multiWorld: true,
zoom: 2,
projection: 'EPSG:4326'
}));
map.setView(
new View({
center: [7, 52],
multiWorld: true,
zoom: 2,
projection: 'EPSG:4326',
})
);
map.renderSync();
expect(ctrl.element.innerText).to.be('5000 km');
map.setView(new View({
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
zoom: 7,
projection: 'Indiana-East'
}));
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
});
it('shows the same scale for different projections at higher resolutions', function() {
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: fromLonLat([-85.685, 39.891]),
zoom: 7,
projection: 'EPSG:3857'
}));
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
map.setView(new View({
center: [-85.685, 39.891],
zoom: 7,
projection: 'EPSG:4326'
}));
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
map.setView(new View({
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
zoom: 7,
projection: 'Indiana-East'
}));
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
});
it('Projection\'s metersPerUnit affect scale for non-degree units', function() {
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
zoom: 0,
resolutions: [1],
projection: new Projection({
code: 'METERS',
units: 'm',
getPointResolution: function(r) {
return r;
}
map.setView(
new View({
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
zoom: 7,
projection: 'Indiana-East',
})
}));
);
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
});
it('shows the same scale for different projections at higher resolutions', function () {
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(
new View({
center: fromLonLat([-85.685, 39.891]),
zoom: 7,
projection: 'EPSG:3857',
})
);
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
map.setView(
new View({
center: [-85.685, 39.891],
zoom: 7,
projection: 'EPSG:4326',
})
);
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
map.setView(
new View({
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
zoom: 7,
projection: 'Indiana-East',
})
);
map.renderSync();
expect(ctrl.element.innerText).to.be('100 km');
});
it("Projection's metersPerUnit affect scale for non-degree units", function () {
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(
new View({
center: [0, 0],
zoom: 0,
resolutions: [1],
projection: new Projection({
code: 'METERS',
units: 'm',
getPointResolution: function (r) {
return r;
},
}),
})
);
map.renderSync();
ctrl.setUnits('metric');
@@ -349,20 +388,21 @@ describe('ol.control.ScaleLine', function() {
ctrl.setUnits('us');
expect(ctrl.element.innerText).to.be('500 ft');
map.setView(new View({
center: [0, 0],
zoom: 0,
resolutions: [1],
projection: new Projection({
code: 'PIXELS',
units: 'pixels',
metersPerUnit: 1 / 1000,
getPointResolution: function(r) {
return r;
}
map.setView(
new View({
center: [0, 0],
zoom: 0,
resolutions: [1],
projection: new Projection({
code: 'PIXELS',
units: 'pixels',
metersPerUnit: 1 / 1000,
getPointResolution: function (r) {
return r;
},
}),
})
}));
);
map.renderSync();
ctrl.setUnits('metric');
@@ -378,15 +418,17 @@ describe('ol.control.ScaleLine', function() {
expect(ctrl.element.innerText).to.be('5 in');
});
it('Metric display works with Geographic (EPSG:4326) projection', function() {
it('Metric display works with Geographic (EPSG:4326) projection', function () {
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
multiWorld: true,
zoom: 0, /* min zoom */
projection: 'EPSG:4326'
}));
map.setView(
new View({
center: [0, 0],
multiWorld: true,
zoom: 0 /* min zoom */,
projection: 'EPSG:4326',
})
);
map.renderSync();
expect(ctrl.element.innerText).to.be('10000 km');
map.getView().setZoom(28); /* max zoom */
@@ -395,16 +437,17 @@ describe('ol.control.ScaleLine', function() {
});
});
describe('latitude may affect scale line in EPSG:4326', function() {
it('is rendered differently at different latitudes for metric', function() {
describe('latitude may affect scale line in EPSG:4326', function () {
it('is rendered differently at different latitudes for metric', function () {
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: [7, 0],
zoom: 2,
projection: 'EPSG:4326'
}));
map.setView(
new View({
center: [7, 0],
zoom: 2,
projection: 'EPSG:4326',
})
);
map.renderSync();
const innerHtml0 = ctrl.element.innerHTML;
map.getView().setCenter([7, 52]);
@@ -413,17 +456,19 @@ describe('ol.control.ScaleLine', function() {
expect(innerHtml0).to.not.be(innerHtml52);
});
it('is rendered the same at different latitudes for degrees', function() {
it('is rendered the same at different latitudes for degrees', function () {
const ctrl = new ScaleLine({
units: 'degrees'
units: 'degrees',
});
ctrl.setMap(map);
map.setView(new View({
center: [7, 0],
zoom: 2,
projection: 'EPSG:4326',
multiWorld: true
}));
map.setView(
new View({
center: [7, 0],
zoom: 2,
projection: 'EPSG:4326',
multiWorld: true,
})
);
map.renderSync();
const innerHtml0 = ctrl.element.innerHTML;
map.getView().setCenter([7, 52]);
@@ -431,16 +476,15 @@ describe('ol.control.ScaleLine', function() {
const innerHtml52 = ctrl.element.innerHTML;
expect(innerHtml0).to.be(innerHtml52);
});
});
describe('zoom affects the scaleline', function() {
describe('zoom affects the scaleline', function () {
let currentZoom;
let ctrl;
let renderedHtmls;
let mapView;
const getMetricUnit = function(zoom) {
const getMetricUnit = function (zoom) {
if (zoom > 30) {
return 'μm';
} else if (zoom > 20) {
@@ -452,7 +496,7 @@ describe('ol.control.ScaleLine', function() {
}
};
const getImperialUnit = function(zoom) {
const getImperialUnit = function (zoom) {
if (zoom >= 21) {
return 'in';
} else if (zoom >= 10) {
@@ -462,29 +506,30 @@ describe('ol.control.ScaleLine', function() {
}
};
beforeEach(function() {
beforeEach(function () {
currentZoom = 33;
renderedHtmls = {};
ctrl = new ScaleLine({
minWidth: 10
minWidth: 10,
});
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
zoom: currentZoom,
maxZoom: currentZoom,
multiWorld: true
}));
map.setView(
new View({
center: [0, 0],
zoom: currentZoom,
maxZoom: currentZoom,
multiWorld: true,
})
);
mapView = map.getView();
map.renderSync();
});
afterEach(function() {
afterEach(function () {
map.removeControl(ctrl);
map.setView(null);
});
it('metric: is rendered differently for different zoomlevels', function() {
it('metric: is rendered differently for different zoomlevels', function () {
ctrl.setUnits('metric');
map.renderSync();
renderedHtmls[ctrl.element.innerHTML] = true;
@@ -499,7 +544,7 @@ describe('ol.control.ScaleLine', function() {
expect(unit).to.eql(getMetricUnit(currentZoom));
}
});
it('degrees: is rendered differently for different zoomlevels', function() {
it('degrees: is rendered differently for different zoomlevels', function () {
ctrl.setUnits('degrees');
map.renderSync();
renderedHtmls[ctrl.element.innerHTML] = true;
@@ -511,7 +556,7 @@ describe('ol.control.ScaleLine', function() {
renderedHtmls[currentHtml] = true;
}
});
it('imperial: is rendered differently for different zoomlevels', function() {
it('imperial: is rendered differently for different zoomlevels', function () {
ctrl.setUnits('imperial');
map.renderSync();
renderedHtmls[ctrl.element.innerHTML] = true;
@@ -526,7 +571,7 @@ describe('ol.control.ScaleLine', function() {
expect(unit).to.eql(getImperialUnit(currentZoom));
}
});
it('nautical: is rendered differently for different zoomlevels', function() {
it('nautical: is rendered differently for different zoomlevels', function () {
ctrl.setUnits('nautical');
map.renderSync();
renderedHtmls[ctrl.element.innerHTML] = true;
@@ -538,7 +583,7 @@ describe('ol.control.ScaleLine', function() {
renderedHtmls[currentHtml] = true;
}
});
it('us: is rendered differently for different zoomlevels', function() {
it('us: is rendered differently for different zoomlevels', function () {
ctrl.setUnits('us');
map.renderSync();
renderedHtmls[ctrl.element.innerHTML] = true;
@@ -551,5 +596,4 @@ describe('ol.control.ScaleLine', function() {
}
});
});
});
+3 -7
View File
@@ -1,14 +1,10 @@
import Zoom from '../../../../src/ol/control/Zoom.js';
describe('ol.control.Zoom', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.control.Zoom', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new Zoom();
expect(instance).to.be.an(Zoom);
});
});
});
+41 -37
View File
@@ -1,10 +1,10 @@
import Event from '../../../../src/ol/events/Event.js';
import EventTarget from '../../../../src/ol/events/Target.js';
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import ZoomSlider from '../../../../src/ol/control/ZoomSlider.js';
import Event from '../../../../src/ol/events/Event.js';
import EventTarget from '../../../../src/ol/events/Target.js';
describe('ol.control.ZoomSlider', function() {
describe('ol.control.ZoomSlider', function () {
let map, target, zoomslider;
const createElement = document.createElement;
@@ -19,17 +19,17 @@ describe('ol.control.ZoomSlider', function() {
return element;
}
beforeEach(function() {
beforeEach(function () {
target = document.createElement('div');
document.body.appendChild(target);
zoomslider = new ZoomSlider();
map = new Map({
target: target,
controls: [zoomslider]
controls: [zoomslider],
});
});
afterEach(function() {
afterEach(function () {
zoomslider.dispose();
map.dispose();
document.body.removeChild(target);
@@ -38,8 +38,8 @@ describe('ol.control.ZoomSlider', function() {
target = null;
});
describe('DOM creation', function() {
it('creates the expected DOM elements', function() {
describe('DOM creation', function () {
it('creates the expected DOM elements', function () {
const zoomSliderContainers = target.querySelectorAll('.ol-zoomslider');
expect(zoomSliderContainers.length).to.be(1);
@@ -47,31 +47,36 @@ describe('ol.control.ZoomSlider', function() {
const zoomSliderContainer = zoomSliderContainers[0];
expect(zoomSliderContainer instanceof HTMLDivElement).to.be(true);
let hasUnselectableCls = zoomSliderContainer.classList.contains('ol-unselectable');
let hasUnselectableCls = zoomSliderContainer.classList.contains(
'ol-unselectable'
);
expect(hasUnselectableCls).to.be(true);
const zoomSliderThumbs = zoomSliderContainer.querySelectorAll('.ol-zoomslider-thumb');
const zoomSliderThumbs = zoomSliderContainer.querySelectorAll(
'.ol-zoomslider-thumb'
);
expect(zoomSliderThumbs.length).to.be(1);
const zoomSliderThumb = zoomSliderThumbs[0];
expect(zoomSliderThumb instanceof HTMLButtonElement).to.be(true);
hasUnselectableCls = zoomSliderThumb.classList.contains('ol-unselectable');
hasUnselectableCls = zoomSliderThumb.classList.contains(
'ol-unselectable'
);
expect(hasUnselectableCls).to.be(true);
});
});
describe('#initSlider_', function() {
it('sets limits', function() {
describe('#initSlider_', function () {
it('sets limits', function () {
zoomslider.initSlider_();
expect(zoomslider.widthLimit_).not.to.be(0);
expect(zoomslider.heightLimit_).to.be(0);
});
});
describe('#direction_', function() {
it('is horizontal for wide containers', function() {
describe('#direction_', function () {
it('is horizontal for wide containers', function () {
const control = new ZoomSlider({});
control.element.style.width = '1000px';
control.element.style.height = '10px';
@@ -84,7 +89,7 @@ describe('ol.control.ZoomSlider', function() {
control.dispose();
});
it('is vertical for tall containers', function() {
it('is vertical for tall containers', function () {
const control = new ZoomSlider({});
control.element.style.width = '10px';
control.element.style.height = '1000px';
@@ -98,23 +103,23 @@ describe('ol.control.ZoomSlider', function() {
});
});
describe('Pointer event handling', function() {
describe('Pointer event handling', function () {
let map;
beforeEach(function() {
beforeEach(function () {
map = new Map({
target: createMapDiv(500, 100),
view: new View({
center: [0, 0],
resolutions: [16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625]
})
resolutions: [16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625],
}),
});
});
afterEach(function() {
afterEach(function () {
disposeMap(map);
});
it('[horizontal] handles a drag sequence', function() {
it('[horizontal] handles a drag sequence', function () {
document.createElement = createEventElement;
const control = new ZoomSlider();
map.addControl(control);
@@ -126,8 +131,8 @@ describe('ol.control.ZoomSlider', function() {
control.element.firstChild.style.height = '10px';
map.renderSync();
const event = new Event();
event.type = 'pointerdown',
event.target = control.element.firstElementChild;
(event.type = 'pointerdown'),
(event.target = control.element.firstElementChild);
event.clientX = control.widthLimit_;
event.clientY = 0;
control.element.dispatchEvent(event);
@@ -135,12 +140,12 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragging_).to.be(true);
expect(control.dragListenerKeys_.length).to.be(2);
event.type = 'pointermove';
event.clientX = 6 * control.widthLimit_ / 8;
event.clientX = (6 * control.widthLimit_) / 8;
event.clientY = 0;
control.element.dispatchEvent(event);
expect(control.currentResolution_).to.be(4);
event.type = 'pointermove';
event.clientX = 4 * control.widthLimit_ / 8;
event.clientX = (4 * control.widthLimit_) / 8;
event.clientY = 0;
control.element.dispatchEvent(event);
event.type = 'pointerup';
@@ -149,7 +154,7 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragListenerKeys_.length).to.be(0);
expect(control.dragging_).to.be(false);
});
it('[horizontal] handles a drag sequence ending outside its bounds', function() {
it('[horizontal] handles a drag sequence ending outside its bounds', function () {
document.createElement = createEventElement;
const control = new ZoomSlider();
map.addControl(control);
@@ -170,12 +175,12 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragging_).to.be(true);
expect(control.dragListenerKeys_.length).to.be(2);
event.type = 'pointermove';
event.clientX = 6 * control.widthLimit_ / 8;
event.clientX = (6 * control.widthLimit_) / 8;
event.clientY = 0;
control.element.dispatchEvent(event);
expect(control.currentResolution_).to.be(4);
event.type = 'pointermove';
event.clientX = 12 * control.widthLimit_ / 8;
event.clientX = (12 * control.widthLimit_) / 8;
event.clientY = 0;
control.element.dispatchEvent(event);
event.type = 'pointerup';
@@ -185,7 +190,7 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragging_).to.be(false);
expect(control.currentResolution_).to.be(16);
});
it('[vertical] handles a drag sequence', function() {
it('[vertical] handles a drag sequence', function () {
document.createElement = createEventElement;
const control = new ZoomSlider();
control.element.style.width = '10px';
@@ -207,12 +212,12 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragListenerKeys_.length).to.be(2);
event.type = 'pointermove';
event.clientX = 0;
event.clientY = 2 * control.heightLimit_ / 8;
event.clientY = (2 * control.heightLimit_) / 8;
control.element.dispatchEvent(event);
expect(control.currentResolution_).to.be(0.25);
event.type = 'pointermove';
event.clientX = 0;
event.clientY = 4 * control.heightLimit_ / 8;
event.clientY = (4 * control.heightLimit_) / 8;
control.element.dispatchEvent(event);
event.type = 'pointerup';
control.element.dispatchEvent(event);
@@ -220,7 +225,7 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragListenerKeys_.length).to.be(0);
expect(control.dragging_).to.be(false);
});
it('[vertical] handles a drag sequence ending outside its bounds', function() {
it('[vertical] handles a drag sequence ending outside its bounds', function () {
document.createElement = createEventElement;
const control = new ZoomSlider();
control.element.style.width = '10px';
@@ -242,12 +247,12 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragListenerKeys_.length).to.be(2);
event.type = 'pointermove';
event.clientX = 0;
event.clientY = 2 * control.heightLimit_ / 8;
event.clientY = (2 * control.heightLimit_) / 8;
control.element.dispatchEvent(event);
expect(control.currentResolution_).to.be(0.25);
event.type = 'pointermove';
event.clientX = 0;
event.clientY = 12 * control.heightLimit_ / 8;
event.clientY = (12 * control.heightLimit_) / 8;
control.element.dispatchEvent(event);
event.type = 'pointerup';
control.element.dispatchEvent(event);
@@ -256,5 +261,4 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragging_).to.be(false);
});
});
});
+3 -7
View File
@@ -1,14 +1,10 @@
import ZoomToExtent from '../../../../src/ol/control/ZoomToExtent.js';
describe('ol.control.ZoomToExtent', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.control.ZoomToExtent', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new ZoomToExtent();
expect(instance).to.be.an(ZoomToExtent);
});
});
});
+112 -101
View File
@@ -1,51 +1,65 @@
import {add as addCoordinate, scale as scaleCoordinate, rotate as rotateCoordinate, equals as coordinatesEqual, format as formatCoordinate, closestOnCircle, closestOnSegment, createStringXY, squaredDistanceToSegment, toStringXY, toStringHDMS, wrapX} from '../../../src/ol/coordinate.js';
import Circle from '../../../src/ol/geom/Circle.js';
import {
add as addCoordinate,
closestOnCircle,
closestOnSegment,
equals as coordinatesEqual,
createStringXY,
format as formatCoordinate,
rotate as rotateCoordinate,
scale as scaleCoordinate,
squaredDistanceToSegment,
toStringHDMS,
toStringXY,
wrapX,
} from '../../../src/ol/coordinate.js';
import {get} from '../../../src/ol/proj.js';
describe('ol.coordinate', function() {
describe('#add', function() {
describe('ol.coordinate', function () {
describe('#add', function () {
let coordinate, delta;
beforeEach(function() {
beforeEach(function () {
coordinate = [50.73, 7.1];
delta = [-2, 3];
});
it('returns a coordinate', function() {
it('returns a coordinate', function () {
const returnedCoordinate = addCoordinate(coordinate, delta);
expect(returnedCoordinate).to.be.an('array');
expect(returnedCoordinate).to.have.length(2);
});
it('adds the delta', function() {
it('adds the delta', function () {
const returnedCoordinate = addCoordinate(coordinate, delta);
expect(returnedCoordinate[0]).to.eql(48.73);
expect(returnedCoordinate[1]).to.eql(10.1);
});
it('modifies in place', function() {
it('modifies in place', function () {
addCoordinate(coordinate, delta);
expect(coordinate[0]).to.eql(48.73);
expect(coordinate[1]).to.eql(10.1);
});
it('does not produce unexpected results with string delta values', function() {
addCoordinate(coordinate, delta.map(function(n) {
return String(n);
}));
it('does not produce unexpected results with string delta values', function () {
addCoordinate(
coordinate,
delta.map(function (n) {
return String(n);
})
);
expect(coordinate[0]).to.eql(48.73);
expect(coordinate[1]).to.eql(10.1);
});
});
describe('#equals', function() {
describe('#equals', function () {
const cologne = [50.93333, 6.95];
const bonn1 = [50.73, 7.1];
const bonn2 = [50.73000, 7.10000];
const bonn2 = [50.73, 7.1];
it('compares correctly', function() {
it('compares correctly', function () {
const bonnEqualsBonn = coordinatesEqual(bonn1, bonn2);
const bonnEqualsCologne = coordinatesEqual(bonn1, cologne);
expect(bonnEqualsBonn).to.be(true);
@@ -53,32 +67,32 @@ describe('ol.coordinate', function() {
});
});
describe('#format', function() {
describe('#format', function () {
let coordinate;
beforeEach(function() {
beforeEach(function () {
coordinate = [6.6123, 46.7919];
});
it('rounds the values', function() {
it('rounds the values', function () {
const string = formatCoordinate(coordinate, '{x} {y}', 0);
expect(string).to.eql('7 47');
});
it('handles the optional fractionDigits param', function() {
it('handles the optional fractionDigits param', function () {
const string = formatCoordinate(coordinate, '{x} {y}', 3);
expect(string).to.eql('6.612 46.792');
});
});
describe('#createStringXY', function() {
describe('#createStringXY', function () {
let coordinate, created, formatted;
beforeEach(function() {
beforeEach(function () {
coordinate = [6.6123, 46.7919];
created = null;
formatted = null;
});
it('returns a CoordinateFormatType', function() {
it('returns a CoordinateFormatType', function () {
created = createStringXY();
expect(created).to.be.a('function');
@@ -87,7 +101,7 @@ describe('ol.coordinate', function() {
expect(formatted).to.eql('7, 47');
});
it('respects opt_fractionDigits', function() {
it('respects opt_fractionDigits', function () {
created = createStringXY(3);
expect(created).to.be.a('function');
@@ -97,67 +111,65 @@ describe('ol.coordinate', function() {
});
});
describe('#closestOnCircle', function() {
describe('#closestOnCircle', function () {
const center = [5, 10];
const circle = new Circle(center, 10);
it('can find the closest point on circle', function() {
expect(closestOnCircle([-20, 10], circle))
.to.eql([-5, 10]);
it('can find the closest point on circle', function () {
expect(closestOnCircle([-20, 10], circle)).to.eql([-5, 10]);
});
it('can handle coordinate equal circle center', function() {
expect(closestOnCircle(center, circle))
.to.eql([15, 10]);
it('can handle coordinate equal circle center', function () {
expect(closestOnCircle(center, circle)).to.eql([15, 10]);
});
});
describe('#closestOnSegment', function() {
it('can handle points where the foot of the perpendicular is closest',
function() {
const point = [2, 5];
const segment = [[-5, 0], [10, 0]];
expect(closestOnSegment(point, segment))
.to.eql([2, 0]);
});
it('can handle points where the foot of the perpendicular is not closest',
function() {
const point = [0, -6];
const segment = [[-5, 0], [0, -1]];
expect(closestOnSegment(point, segment))
.to.eql([0, -1]);
});
describe('#closestOnSegment', function () {
it('can handle points where the foot of the perpendicular is closest', function () {
const point = [2, 5];
const segment = [
[-5, 0],
[10, 0],
];
expect(closestOnSegment(point, segment)).to.eql([2, 0]);
});
it('can handle points where the foot of the perpendicular is not closest', function () {
const point = [0, -6];
const segment = [
[-5, 0],
[0, -1],
];
expect(closestOnSegment(point, segment)).to.eql([0, -1]);
});
});
describe('#format', function() {
it('can deal with undefined coordinate', function() {
describe('#format', function () {
it('can deal with undefined coordinate', function () {
expect(formatCoordinate()).to.be('');
});
it('formats a coordinate into a template (default precision is 0)',
function() {
const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const got = formatCoordinate(coord, template);
const expected = 'Coordinate is (8|48).';
expect(got).to.be(expected);
});
it('formats a coordinate into a template and respects precision)',
function() {
const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const got = formatCoordinate(coord, template, 2);
const expected = 'Coordinate is (7.85|47.98).';
expect(got).to.be(expected);
});
it('formats a coordinate into a template (default precision is 0)', function () {
const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const got = formatCoordinate(coord, template);
const expected = 'Coordinate is (8|48).';
expect(got).to.be(expected);
});
it('formats a coordinate into a template and respects precision)', function () {
const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const got = formatCoordinate(coord, template, 2);
const expected = 'Coordinate is (7.85|47.98).';
expect(got).to.be(expected);
});
});
describe('#rotate', function() {
it('can rotate point in place', function() {
describe('#rotate', function () {
it('can rotate point in place', function () {
const coord = [7.85, 47.983333];
const rotateRadians = Math.PI / 2; // 90 degrees
rotateCoordinate(coord, rotateRadians);
expect(coord[0].toFixed(6)).to.eql('-47.983333');
expect(coord[1].toFixed(6)).to.eql('7.850000');
});
it('returns the rotated point', function() {
it('returns the rotated point', function () {
const coord = [7.85, 47.983333];
const rotateRadians = Math.PI / 2; // 90 degrees
const rotated = rotateCoordinate(coord, rotateRadians);
@@ -166,15 +178,15 @@ describe('ol.coordinate', function() {
});
});
describe('#scale', function() {
it('can scale point in place', function() {
describe('#scale', function () {
it('can scale point in place', function () {
const coord = [7.85, 47.983333];
const scale = 1.2;
scaleCoordinate(coord, scale);
expect(coord[0].toFixed(7)).to.eql('9.4200000');
expect(coord[1].toFixed(7)).to.eql('57.5799996');
});
it('returns the scaled point', function() {
it('returns the scaled point', function () {
const coord = [7.85, 47.983333];
const scale = 1.2;
const scaledCoord = scaleCoordinate(coord, scale);
@@ -183,37 +195,38 @@ describe('ol.coordinate', function() {
});
});
describe('#squaredDistanceToSegment', function() {
it('can handle points where the foot of the perpendicular is closest',
function() {
const point = [2, 5];
const segment = [[-5, 0], [10, 0]];
expect(squaredDistanceToSegment(point, segment))
.to.eql(25);
});
it('can handle points where the foot of the perpendicular is not closest',
function() {
const point = [0, -6];
const segment = [[-5, 0], [0, -1]];
expect(squaredDistanceToSegment(point, segment))
.to.eql(25);
});
describe('#squaredDistanceToSegment', function () {
it('can handle points where the foot of the perpendicular is closest', function () {
const point = [2, 5];
const segment = [
[-5, 0],
[10, 0],
];
expect(squaredDistanceToSegment(point, segment)).to.eql(25);
});
it('can handle points where the foot of the perpendicular is not closest', function () {
const point = [0, -6];
const segment = [
[-5, 0],
[0, -1],
];
expect(squaredDistanceToSegment(point, segment)).to.eql(25);
});
});
describe('#toStringHDMS', function() {
it('returns the empty string on undefined input', function() {
describe('#toStringHDMS', function () {
it('returns the empty string on undefined input', function () {
const got = toStringHDMS();
const expected = '';
expect(got).to.be(expected);
});
it('formats with zero fractional digits as default', function() {
it('formats with zero fractional digits as default', function () {
const coord = [7.85, 47.983333];
const got = toStringHDMS(coord);
const expected = '47° 59 00″ N 7° 51 00″ E';
expect(got).to.be(expected);
});
it('formats with given fractional digits, if passed', function() {
it('formats with given fractional digits, if passed', function () {
const coord = [7.85, 47.983333];
const got = toStringHDMS(coord, 3);
const expected = '47° 58 59.999″ N 7° 51 00.000″ E';
@@ -221,14 +234,14 @@ describe('ol.coordinate', function() {
});
});
describe('#toStringXY', function() {
it('formats with zero fractional digits as default', function() {
describe('#toStringXY', function () {
it('formats with zero fractional digits as default', function () {
const coord = [7.85, 47.983333];
const got = toStringXY(coord);
const expected = '8, 48';
expect(got).to.be(expected);
});
it('formats with given fractional digits, if passed', function() {
it('formats with given fractional digits, if passed', function () {
const coord = [7.85, 47.983333];
const got = toStringXY(coord, 2);
const expected = '7.85, 47.98';
@@ -236,29 +249,27 @@ describe('ol.coordinate', function() {
});
});
describe('wrapX()', function() {
describe('wrapX()', function () {
const projection = get('EPSG:4326');
it('leaves real world coordinate untouched', function() {
it('leaves real world coordinate untouched', function () {
expect(wrapX([16, 48], projection)).to.eql([16, 48]);
});
it('moves left world coordinate to real world', function() {
it('moves left world coordinate to real world', function () {
expect(wrapX([-344, 48], projection)).to.eql([16, 48]);
});
it('moves right world coordinate to real world', function() {
it('moves right world coordinate to real world', function () {
expect(wrapX([376, 48], projection)).to.eql([16, 48]);
});
it('moves far off left coordinate to real world', function() {
it('moves far off left coordinate to real world', function () {
expect(wrapX([-1064, 48], projection)).to.eql([16, 48]);
});
it('moves far off right coordinate to real world', function() {
it('moves far off right coordinate to real world', function () {
expect(wrapX([1096, 48], projection)).to.eql([16, 48]);
});
});
});
+42 -38
View File
@@ -1,48 +1,54 @@
import {getFontParameters} from '../../../src/ol/css.js';
describe('ol.css', function() {
describe('ol.css', function () {
describe('getFontParameters()', function () {
const cases = [
{
font: '2em "Open Sans"',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"'],
},
{
font: "2em 'Open Sans'",
style: 'normal',
weight: 'normal',
families: ['"Open Sans"'],
},
{
font: '2em "Open Sans", sans-serif',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"', 'sans-serif'],
},
{
font: 'italic small-caps bolder 16px/3 cursive',
style: 'italic',
weight: 'bolder',
families: ['cursive'],
},
{
font: 'garbage 2px input',
families: null,
},
{
font: '100% fantasy',
style: 'normal',
weight: 'normal',
families: ['fantasy'],
},
];
describe('getFontParameters()', function() {
const cases = [{
font: '2em "Open Sans"',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"']
}, {
font: '2em \'Open Sans\'',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"']
}, {
font: '2em "Open Sans", sans-serif',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"', 'sans-serif']
}, {
font: 'italic small-caps bolder 16px/3 cursive',
style: 'italic',
weight: 'bolder',
families: ['cursive']
}, {
font: 'garbage 2px input',
families: null
}, {
font: '100% fantasy',
style: 'normal',
weight: 'normal',
families: ['fantasy']
}];
cases.forEach(function(c, i) {
it('works for ' + c.font, function() {
cases.forEach(function (c, i) {
it('works for ' + c.font, function () {
const font = getFontParameters(c.font);
if (c.families === null) {
expect(font).to.be(null);
return;
}
font.families.forEach(function(family, j) {
font.families.forEach(function (family, j) {
// Safari uses single quotes for font families, so we have to do extra work
if (family.charAt(0) === '\'') {
if (family.charAt(0) === "'") {
// we wouldn't want to do this in the lib since it doesn't properly escape quotes
// but we know that our test cases don't include quotes in font names
font.families[j] = '"' + family.slice(1, -1) + '"';
@@ -53,7 +59,5 @@ describe('ol.css', function() {
expect(font.families).to.eql(c.families);
});
});
});
});
+8 -17
View File
@@ -1,35 +1,28 @@
import Disposable from '../../../src/ol/Disposable.js';
describe('ol.Disposable', function() {
describe('constructor', function() {
it('creates an instance', function() {
describe('ol.Disposable', function () {
describe('constructor', function () {
it('creates an instance', function () {
const disposable = new Disposable();
expect(disposable).to.be.a(Disposable);
});
});
describe('#disposed_', function() {
it('is initially false', function() {
describe('#disposed_', function () {
it('is initially false', function () {
const disposable = new Disposable();
expect(disposable.disposed_).to.be(false);
});
it('is true after a call to dispose', function() {
it('is true after a call to dispose', function () {
const disposable = new Disposable();
disposable.dispose();
expect(disposable.disposed_).to.be(true);
});
});
describe('#dispose()', function() {
it('calls disposeInternal only once', function() {
describe('#dispose()', function () {
it('calls disposeInternal only once', function () {
const disposable = new Disposable();
sinon.spy(disposable, 'disposeInternal');
expect(disposable.disposeInternal.called).to.be(false);
@@ -38,7 +31,5 @@ describe('ol.Disposable', function() {
disposable.dispose();
expect(disposable.disposeInternal.callCount).to.be(1);
});
});
});
+90 -123
View File
@@ -1,14 +1,18 @@
import {createCanvasContext2D, outerWidth, outerHeight, replaceChildren} from '../../../../src/ol/dom.js';
import {
createCanvasContext2D,
outerHeight,
outerWidth,
replaceChildren,
} from '../../../../src/ol/dom.js';
describe('ol.dom', function() {
describe('ol.dom.createCanvasContext2D', function() {
describe('ol.dom', function () {
describe('ol.dom.createCanvasContext2D', function () {
// default values from
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas
const defaultWidth = 300;
const defaultHeight = 150;
it('returns a CanvasRenderingContext2D', function() {
it('returns a CanvasRenderingContext2D', function () {
const ctx = createCanvasContext2D();
expect(ctx).to.be.a(CanvasRenderingContext2D);
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
@@ -16,7 +20,7 @@ describe('ol.dom', function() {
expect(ctx.canvas.height).to.be(defaultHeight);
});
it('has the desired width', function() {
it('has the desired width', function () {
const ctx = createCanvasContext2D(42);
expect(ctx).to.be.a(CanvasRenderingContext2D);
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
@@ -24,7 +28,7 @@ describe('ol.dom', function() {
expect(ctx.canvas.height).to.be(defaultHeight);
});
it('has the desired height', function() {
it('has the desired height', function () {
const ctx = createCanvasContext2D(undefined, 42);
expect(ctx).to.be.a(CanvasRenderingContext2D);
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
@@ -32,19 +36,18 @@ describe('ol.dom', function() {
expect(ctx.canvas.height).to.be(42);
});
it('has the desired height and width', function() {
it('has the desired height and width', function () {
const ctx = createCanvasContext2D(42, 42);
expect(ctx).to.be.a(CanvasRenderingContext2D);
expect(ctx.canvas).to.be.a(HTMLCanvasElement);
expect(ctx.canvas.width).to.be(42);
expect(ctx.canvas.height).to.be(42);
});
});
describe('ol.dom.outerWidth', function() {
describe('ol.dom.outerWidth', function () {
let element = null;
beforeEach(function() {
beforeEach(function () {
element = document.createElement('div');
element.style.padding = 0;
element.style.margin = 0;
@@ -53,126 +56,113 @@ describe('ol.dom', function() {
element.style.height = '10px';
document.body.appendChild(element);
});
afterEach(function() {
afterEach(function () {
element.parentNode.removeChild(element);
element = null;
});
describe('without padding, margin or border', function() {
it('calculates correctly', function() {
describe('without padding, margin or border', function () {
it('calculates correctly', function () {
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(10);
});
});
describe('with padding', function() {
it('calculates correctly (both sides)', function() {
describe('with padding', function () {
it('calculates correctly (both sides)', function () {
element.style.padding = '5px';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(20);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.paddingLeft = '5px';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(15);
});
});
describe('with margin', function() {
it('calculates correctly (both sides)', function() {
describe('with margin', function () {
it('calculates correctly (both sides)', function () {
element.style.margin = '5px';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(20);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.marginLeft = '5px';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(15);
});
});
describe('with border', function() {
it('calculates correctly (both sides)', function() {
describe('with border', function () {
it('calculates correctly (both sides)', function () {
element.style.border = '5px solid chocolate';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(20);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.border = '5px solid chocolate';
element.style.borderRightWidth = '0';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(15);
});
});
describe('with padding and margin', function() {
it('calculates correctly (both sides)', function() {
describe('with padding and margin', function () {
it('calculates correctly (both sides)', function () {
element.style.padding = '5px';
element.style.margin = '5px';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(30);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.paddingLeft = '5px';
element.style.marginLeft = '5px';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(20);
});
});
describe('with padding and border', function() {
it('calculates correctly (both sides)', function() {
describe('with padding and border', function () {
it('calculates correctly (both sides)', function () {
element.style.padding = '5px';
element.style.border = '5px solid chocolate';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(30);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.paddingLeft = '5px';
element.style.border = '5px solid chocolate';
element.style.borderRightWidth = '0';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(20);
});
});
describe('with margin and border', function() {
it('calculates correctly (both sides)', function() {
describe('with margin and border', function () {
it('calculates correctly (both sides)', function () {
element.style.margin = '5px';
element.style.border = '5px solid chocolate';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(30);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.marginLeft = '5px';
element.style.border = '5px solid chocolate';
element.style.borderRightWidth = '0';
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(20);
});
});
describe('with padding, margin and border', function() {
it('calculates correctly (both sides)', function() {
describe('with padding, margin and border', function () {
it('calculates correctly (both sides)', function () {
element.style.margin = '5px';
element.style.padding = '5px';
element.style.border = '5px solid chocolate';
@@ -180,7 +170,7 @@ describe('ol.dom', function() {
expect(calcWidth).to.be(40);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.marginLeft = '5px';
element.style.paddingLeft = '5px';
element.style.border = '5px solid chocolate';
@@ -188,14 +178,12 @@ describe('ol.dom', function() {
const calcWidth = outerWidth(element);
expect(calcWidth).to.be(25);
});
});
});
describe('ol.dom.outerHeight', function() {
describe('ol.dom.outerHeight', function () {
let element = null;
beforeEach(function() {
beforeEach(function () {
element = document.createElement('div');
element.style.padding = 0;
element.style.margin = 0;
@@ -204,126 +192,113 @@ describe('ol.dom', function() {
element.style.height = '10px';
document.body.appendChild(element);
});
afterEach(function() {
afterEach(function () {
element.parentNode.removeChild(element);
element = null;
});
describe('without padding, margin or border', function() {
it('calculates correctly', function() {
describe('without padding, margin or border', function () {
it('calculates correctly', function () {
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(10);
});
});
describe('with padding', function() {
it('calculates correctly (both sides)', function() {
describe('with padding', function () {
it('calculates correctly (both sides)', function () {
element.style.padding = '5px';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(20);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.paddingTop = '5px';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(15);
});
});
describe('with margin', function() {
it('calculates correctly (both sides)', function() {
describe('with margin', function () {
it('calculates correctly (both sides)', function () {
element.style.margin = '5px';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(20);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.marginTop = '5px';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(15);
});
});
describe('with border', function() {
it('calculates correctly (both sides)', function() {
describe('with border', function () {
it('calculates correctly (both sides)', function () {
element.style.border = '5px solid chocolate';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(20);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.border = '5px solid chocolate';
element.style.borderBottomWidth = '0';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(15);
});
});
describe('with padding and margin', function() {
it('calculates correctly (both sides)', function() {
describe('with padding and margin', function () {
it('calculates correctly (both sides)', function () {
element.style.padding = '5px';
element.style.margin = '5px';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(30);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.paddingTop = '5px';
element.style.marginTop = '5px';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(20);
});
});
describe('with padding and border', function() {
it('calculates correctly (both sides)', function() {
describe('with padding and border', function () {
it('calculates correctly (both sides)', function () {
element.style.padding = '5px';
element.style.border = '5px solid chocolate';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(30);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.paddingTop = '5px';
element.style.border = '5px solid chocolate';
element.style.borderBottomWidth = '0';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(20);
});
});
describe('with margin and border', function() {
it('calculates correctly (both sides)', function() {
describe('with margin and border', function () {
it('calculates correctly (both sides)', function () {
element.style.margin = '5px';
element.style.border = '5px solid chocolate';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(30);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.marginTop = '5px';
element.style.border = '5px solid chocolate';
element.style.borderBottomWidth = '0';
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(20);
});
});
describe('with padding, margin and border', function() {
it('calculates correctly (both sides)', function() {
describe('with padding, margin and border', function () {
it('calculates correctly (both sides)', function () {
element.style.margin = '5px';
element.style.padding = '5px';
element.style.border = '5px solid chocolate';
@@ -331,7 +306,7 @@ describe('ol.dom', function() {
expect(calcHeight).to.be(40);
});
it('calculates correctly (one side)', function() {
it('calculates correctly (one side)', function () {
element.style.marginTop = '5px';
element.style.paddingTop = '5px';
element.style.border = '5px solid chocolate';
@@ -339,13 +314,10 @@ describe('ol.dom', function() {
const calcHeight = outerHeight(element);
expect(calcHeight).to.be(25);
});
});
});
describe('replaceChildren()', function() {
describe('replaceChildren()', function () {
function assertChildrenMatch(parent, children) {
const actual = parent.childNodes;
expect(actual).to.have.length(children.length);
@@ -354,26 +326,26 @@ describe('ol.dom', function() {
}
}
it('adds new children to an empty parent', function() {
it('adds new children to an empty parent', function () {
const parent = document.createElement('div');
const children = [
document.createElement('a'),
document.createElement('b'),
document.createElement('c')
document.createElement('c'),
];
replaceChildren(parent, children);
assertChildrenMatch(parent, children);
});
it('removes children', function() {
it('removes children', function () {
const parent = document.createElement('div');
const existingChildren = [
document.createElement('a'),
document.createElement('b'),
document.createElement('c')
document.createElement('c'),
];
existingChildren.forEach(function(child) {
existingChildren.forEach(function (child) {
parent.appendChild(child);
});
@@ -381,42 +353,42 @@ describe('ol.dom', function() {
expect(parent.childNodes).to.have.length(0);
});
it('swaps children', function() {
it('swaps children', function () {
const parent = document.createElement('div');
const existingChildren = [
document.createElement('a'),
document.createElement('b'),
document.createElement('c')
document.createElement('c'),
];
existingChildren.forEach(function(child) {
existingChildren.forEach(function (child) {
parent.appendChild(child);
});
const newChildren = [
document.createElement('d'),
document.createElement('e'),
document.createElement('f')
document.createElement('f'),
];
replaceChildren(parent, newChildren);
assertChildrenMatch(parent, newChildren);
});
it('appends children', function() {
it('appends children', function () {
const parent = document.createElement('div');
const existingChildren = [
document.createElement('a'),
document.createElement('b'),
document.createElement('c')
document.createElement('c'),
];
existingChildren.forEach(function(child) {
existingChildren.forEach(function (child) {
parent.appendChild(child);
});
const newChildren = [
document.createElement('d'),
document.createElement('e'),
document.createElement('f')
document.createElement('f'),
];
const allChildren = existingChildren.concat(newChildren);
@@ -425,38 +397,35 @@ describe('ol.dom', function() {
assertChildrenMatch(parent, allChildren);
});
it('prunes children', function() {
it('prunes children', function () {
const parent = document.createElement('div');
const existingChildren = [
document.createElement('a'),
document.createElement('b'),
document.createElement('c'),
document.createElement('d'),
document.createElement('e')
document.createElement('e'),
];
existingChildren.forEach(function(child) {
existingChildren.forEach(function (child) {
parent.appendChild(child);
});
const desiredChildren = [
existingChildren[1],
existingChildren[3]
];
const desiredChildren = [existingChildren[1], existingChildren[3]];
replaceChildren(parent, desiredChildren);
assertChildrenMatch(parent, desiredChildren);
});
it('reorders children', function() {
it('reorders children', function () {
const parent = document.createElement('div');
const existingChildren = [
document.createElement('a'),
document.createElement('b'),
document.createElement('c'),
document.createElement('d'),
document.createElement('e')
document.createElement('e'),
];
existingChildren.forEach(function(child) {
existingChildren.forEach(function (child) {
parent.appendChild(child);
});
@@ -465,23 +434,23 @@ describe('ol.dom', function() {
existingChildren[3],
existingChildren[0],
existingChildren[4],
existingChildren[2]
existingChildren[2],
];
replaceChildren(parent, desiredChildren);
assertChildrenMatch(parent, desiredChildren);
});
it('reorders, prunes, and appends children', function() {
it('reorders, prunes, and appends children', function () {
const parent = document.createElement('div');
const existingChildren = [
document.createElement('a'),
document.createElement('b'),
document.createElement('c'),
document.createElement('d'),
document.createElement('e')
document.createElement('e'),
];
existingChildren.forEach(function(child) {
existingChildren.forEach(function (child) {
parent.appendChild(child);
});
@@ -490,7 +459,7 @@ describe('ol.dom', function() {
existingChildren[3],
document.createElement('g'),
existingChildren[0],
existingChildren[2]
existingChildren[2],
];
const clone = desiredChildren.slice();
@@ -501,7 +470,5 @@ describe('ol.dom', function() {
// confirm we haven't modified the input
expect(desiredChildren).to.eql(clone);
});
});
});
+26 -30
View File
@@ -1,36 +1,35 @@
import {listen, listenOnce, unlistenByKey} from '../../../src/ol/events.js';
import EventTarget from '../../../src/ol/events/Target.js';
import {listen, listenOnce, unlistenByKey} from '../../../src/ol/events.js';
describe('ol.events', function() {
describe('ol.events', function () {
let add, target;
beforeEach(function() {
beforeEach(function () {
target = new EventTarget();
add = sinon.spy(target, 'addEventListener');
});
afterEach(function() {
afterEach(function () {
target.addEventListener.restore();
});
describe('listen()', function() {
it('calls addEventListener on the target', function() {
listen(target, 'foo', function() {});
describe('listen()', function () {
it('calls addEventListener on the target', function () {
listen(target, 'foo', function () {});
expect(add.callCount).to.be(1);
});
it('returns a key', function() {
const key = listen(target, 'foo', function() {});
it('returns a key', function () {
const key = listen(target, 'foo', function () {});
expect(key).to.be.a(Object);
});
it('does not add the same listener twice', function() {
const listener = function() {};
it('does not add the same listener twice', function () {
const listener = function () {};
listen(target, 'foo', listener);
listen(target, 'foo', listener);
expect(target.listeners_['foo'].length).to.be(1);
});
it('only treats listeners as same when all args are equal', function() {
const listener = function() {};
it('only treats listeners as same when all args are equal', function () {
const listener = function () {};
listen(target, 'foo', listener, {});
listen(target, 'foo', listener, {});
listen(target, 'foo', listener, undefined);
@@ -38,8 +37,8 @@ describe('ol.events', function() {
});
});
describe('listenOnce()', function() {
it('creates a one-off listener', function() {
describe('listenOnce()', function () {
it('creates a one-off listener', function () {
const target = new EventTarget();
const listener = sinon.spy();
listenOnce(target, 'foo', listener);
@@ -48,7 +47,7 @@ describe('ol.events', function() {
target.dispatchEvent('foo');
expect(listener.callCount).to.be(1);
});
it('Adds the same listener twice', function() {
it('Adds the same listener twice', function () {
const listener = sinon.spy();
listenOnce(target, 'foo', listener);
listenOnce(target, 'foo', listener);
@@ -59,40 +58,37 @@ describe('ol.events', function() {
});
});
describe('unlistenByKey()', function() {
it('unregisters previously registered listeners', function() {
const key = listen(target, 'foo', function() {});
describe('unlistenByKey()', function () {
it('unregisters previously registered listeners', function () {
const key = listen(target, 'foo', function () {});
unlistenByKey(key);
expect(target.listeners_['foo']).to.be(undefined);
});
it('works with multiple types', function() {
const key = listen(target, ['foo', 'bar'], function() {});
it('works with multiple types', function () {
const key = listen(target, ['foo', 'bar'], function () {});
unlistenByKey(key);
expect(target.listeners_['foo']).to.be(undefined);
expect(target.listeners_['bar']).to.be(undefined);
});
});
describe('Listener keys', function() {
it('does not register duplicated listeners', function() {
describe('Listener keys', function () {
it('does not register duplicated listeners', function () {
const target = new EventTarget();
const listener = function() {};
const listener = function () {};
const key1 = listen(target, 'foo', listener);
expect(target.listeners_['foo']).to.eql([listener]);
const key2 = listen(target, 'foo', listener);
expect(target.listeners_['foo']).to.eql([listener]);
expect(key1.listener).to.equal(key2.listener);
});
it('registers multiple listeners if this object is different', function() {
it('registers multiple listeners if this object is different', function () {
const target = new EventTarget();
const listener = function() {};
const listener = function () {};
const key1 = listen(target, 'foo', listener, {});
const key2 = listen(target, 'foo', listener, {});
expect(key1.listener).to.not.equal(key2.listener);
expect(target.listeners_['foo']).to.eql([key1.listener, key2.listener]);
});
});
});
+17 -16
View File
@@ -1,48 +1,49 @@
import Event, {preventDefault, stopPropagation} from '../../../../src/ol/events/Event.js';
import Event, {
preventDefault,
stopPropagation,
} from '../../../../src/ol/events/Event.js';
describe('ol.events.Event', function() {
describe('constructor', function() {
it('takes a type as argument', function() {
describe('ol.events.Event', function () {
describe('constructor', function () {
it('takes a type as argument', function () {
const event = new Event('foo');
expect(event.type).to.be('foo');
});
it('does not set the propagationStopped flag', function() {
it('does not set the propagationStopped flag', function () {
const event = new Event('foo');
expect(event.propagationStopped).to.be(undefined);
});
});
describe('#preventDefault', function() {
it('sets the propagationStopped flag', function() {
describe('#preventDefault', function () {
it('sets the propagationStopped flag', function () {
const event = new Event('foo');
event.preventDefault();
expect(event.propagationStopped).to.be(true);
});
it('does the same as #stopPropagation', function() {
it('does the same as #stopPropagation', function () {
const event = new Event('foo');
expect(event.stopPropagation()).to.equal(event.preventDefault());
});
});
describe('ol.events.Event.preventDefault', function() {
it('calls preventDefault on the event object', function() {
describe('ol.events.Event.preventDefault', function () {
it('calls preventDefault on the event object', function () {
const event = {
preventDefault: sinon.spy()
preventDefault: sinon.spy(),
};
preventDefault(event);
expect(event.preventDefault.called).to.be(true);
});
});
describe('ol.events.Event.stopPropagation', function() {
it('calls preventDefault on the event object', function() {
describe('ol.events.Event.stopPropagation', function () {
it('calls preventDefault on the event object', function () {
const event = {
stopPropagation: sinon.spy()
stopPropagation: sinon.spy(),
};
stopPropagation(event);
expect(event.stopPropagation.called).to.be(true);
});
});
});
+42 -39
View File
@@ -1,13 +1,12 @@
import Disposable from '../../../../src/ol/Disposable.js';
import {listen} from '../../../../src/ol/events.js';
import Event from '../../../../src/ol/events/Event.js';
import EventTarget from '../../../../src/ol/events/Target.js';
import {listen} from '../../../../src/ol/events.js';
describe('ol.events.EventTarget', function() {
describe('ol.events.EventTarget', function () {
let called, events, eventTarget, spy1, spy2, spy3;
beforeEach(function() {
beforeEach(function () {
called = [];
events = [];
function spy(evt) {
@@ -20,18 +19,18 @@ describe('ol.events.EventTarget', function() {
eventTarget = new EventTarget();
});
describe('constructor', function() {
it('creates an instance', function() {
describe('constructor', function () {
it('creates an instance', function () {
expect(eventTarget).to.be.a(EventTarget);
expect(eventTarget).to.be.a(Disposable);
});
it('creates an empty listeners_ object', function() {
it('creates an empty listeners_ object', function () {
expect(Object.keys(eventTarget.listeners_)).to.have.length(0);
});
it('accepts a default target', function(done) {
it('accepts a default target', function (done) {
const defaultTarget = {};
const target = new EventTarget(defaultTarget);
target.addEventListener('my-event', function(event) {
target.addEventListener('my-event', function (event) {
expect(event.target).to.eql(defaultTarget);
done();
});
@@ -39,21 +38,21 @@ describe('ol.events.EventTarget', function() {
});
});
describe('#hasListener', function() {
it('reports any listeners when called without argument', function() {
describe('#hasListener', function () {
it('reports any listeners when called without argument', function () {
expect(eventTarget.hasListener()).to.be(false);
eventTarget.listeners_['foo'] = [function() {}];
eventTarget.listeners_['foo'] = [function () {}];
expect(eventTarget.hasListener()).to.be(true);
});
it('reports listeners for the type passed as argument', function() {
eventTarget.listeners_['foo'] = [function() {}];
it('reports listeners for the type passed as argument', function () {
eventTarget.listeners_['foo'] = [function () {}];
expect(eventTarget.hasListener('foo')).to.be(true);
expect(eventTarget.hasListener('bar')).to.be(false);
});
});
describe('#addEventListener()', function() {
it('has listeners for each registered type', function() {
describe('#addEventListener()', function () {
it('has listeners for each registered type', function () {
eventTarget.addEventListener('foo', spy1);
eventTarget.addEventListener('bar', spy2);
expect(eventTarget.hasListener('foo')).to.be(true);
@@ -61,19 +60,19 @@ describe('ol.events.EventTarget', function() {
});
});
describe('#removeEventListener()', function() {
it('keeps the listeners registry clean', function() {
describe('#removeEventListener()', function () {
it('keeps the listeners registry clean', function () {
eventTarget.addEventListener('foo', spy1);
eventTarget.removeEventListener('foo', spy1);
expect(eventTarget.hasListener('foo')).to.be(false);
});
it('removes added listeners from the listeners registry', function() {
it('removes added listeners from the listeners registry', function () {
eventTarget.addEventListener('foo', spy1);
eventTarget.addEventListener('foo', spy2);
eventTarget.removeEventListener('foo', spy1, false);
expect(eventTarget.listeners_['foo']).to.have.length(1);
});
it('does not remove listeners when the specified listener is not found', function() {
it('does not remove listeners when the specified listener is not found', function () {
eventTarget.addEventListener('foo', spy1);
eventTarget.addEventListener('foo', spy2);
eventTarget.removeEventListener('foo', undefined);
@@ -83,25 +82,29 @@ describe('ol.events.EventTarget', function() {
});
});
describe('#dispatchEvent()', function() {
it('calls listeners in the correct order', function() {
describe('#dispatchEvent()', function () {
it('calls listeners in the correct order', function () {
eventTarget.addEventListener('foo', spy1);
eventTarget.addEventListener('foo', spy2);
eventTarget.dispatchEvent('foo');
expect(called).to.eql([1, 2]);
});
it('stops propagation when listeners return false', function() {
it('stops propagation when listeners return false', function () {
eventTarget.addEventListener('foo', spy1);
eventTarget.addEventListener('foo', function(evt) {
spy2();
return false;
}, false);
eventTarget.addEventListener(
'foo',
function (evt) {
spy2();
return false;
},
false
);
eventTarget.addEventListener('foo', spy3);
eventTarget.dispatchEvent('foo');
expect(called).to.eql([1, 2]);
});
it('stops propagation when listeners call preventDefault()', function() {
eventTarget.addEventListener('foo', function(evt) {
it('stops propagation when listeners call preventDefault()', function () {
eventTarget.addEventListener('foo', function (evt) {
spy2();
evt.preventDefault();
});
@@ -109,38 +112,38 @@ describe('ol.events.EventTarget', function() {
eventTarget.dispatchEvent('foo');
expect(called).to.eql([2]);
});
it('passes a default ol.events.Event object to listeners', function() {
it('passes a default ol.events.Event object to listeners', function () {
eventTarget.addEventListener('foo', spy1);
eventTarget.dispatchEvent('foo');
expect(events[0]).to.be.a(Event);
expect(events[0].type).to.be('foo');
expect(events[0].target).to.equal(eventTarget);
});
it('passes a custom event object with target to listeners', function() {
it('passes a custom event object with target to listeners', function () {
eventTarget.addEventListener('foo', spy1);
const event = {
type: 'foo'
type: 'foo',
};
eventTarget.dispatchEvent(event);
expect(events[0]).to.equal(event);
expect(events[0].target).to.equal(eventTarget);
});
it('is safe to remove listeners in listeners', function() {
it('is safe to remove listeners in listeners', function () {
eventTarget.addEventListener('foo', spy3);
eventTarget.addEventListener('foo', function() {
eventTarget.addEventListener('foo', function () {
eventTarget.removeEventListener('foo', spy1);
eventTarget.removeEventListener('foo', spy2);
eventTarget.removeEventListener('foo', spy3);
});
eventTarget.addEventListener('foo', spy1);
eventTarget.addEventListener('foo', spy2);
expect(function() {
expect(function () {
eventTarget.dispatchEvent('foo');
}).not.to.throwException();
expect(called).to.eql([3]);
expect(eventTarget.listeners_['foo']).to.have.length(1);
});
it('is safe to do weird things in listeners', function() {
it('is safe to do weird things in listeners', function () {
eventTarget.addEventListener('foo', spy2);
eventTarget.addEventListener('foo', function weird(evt) {
eventTarget.removeEventListener('foo', weird);
@@ -151,7 +154,7 @@ describe('ol.events.EventTarget', function() {
evt.preventDefault();
});
eventTarget.addEventListener('foo', spy1);
expect(function() {
expect(function () {
eventTarget.dispatchEvent('foo');
}).not.to.throwException();
expect(called).to.eql([2, 2]);
@@ -159,8 +162,8 @@ describe('ol.events.EventTarget', function() {
});
});
describe('#dispose()', function() {
it('cleans up foreign references', function() {
describe('#dispose()', function () {
it('cleans up foreign references', function () {
listen(eventTarget, 'foo', spy1, document);
expect(eventTarget.hasListener('foo')).to.be(true);
eventTarget.dispose();
+42 -43
View File
@@ -1,77 +1,76 @@
describe('expect.js', function() {
describe('roughlyEqual', function() {
it('can tell the difference between 1 and 3', function() {
describe('expect.js', function () {
describe('roughlyEqual', function () {
it('can tell the difference between 1 and 3', function () {
expect(1).not.to.roughlyEqual(3, 1);
});
it('really can tell the difference between 1 and 3', function() {
expect(function() {
it('really can tell the difference between 1 and 3', function () {
expect(function () {
expect(1).to.roughlyEqual(3, 0.5);
}).to.throwException();
});
it('thinks that 1 ain\'t so different from 2', function() {
it("thinks that 1 ain't so different from 2", function () {
expect(1).to.roughlyEqual(2, 1);
});
it('knows that, like, 1 and 2 would, like, totally dig each other',
function() {
expect(function() {
expect(1).to.roughlyEqual(2, 1);
}).not.to.throwException();
});
it('knows that, like, 1 and 2 would, like, totally dig each other', function () {
expect(function () {
expect(1).to.roughlyEqual(2, 1);
}).not.to.throwException();
});
});
describe('Test equality of XML documents - xmleql', function() {
it('Test XML document with single root, different prefix', function() {
describe('Test equality of XML documents - xmleql', function () {
it('Test XML document with single root, different prefix', function () {
const doc1 = '<bar:foo xmlns:bar="http://foo"></bar:foo>';
const doc2 = '<foo xmlns="http://foo"></foo>';
expect(new DOMParser().parseFromString(doc1, 'application/xml')).to.xmleql(
new DOMParser().parseFromString(doc2, 'application/xml'));
expect(
new DOMParser().parseFromString(doc1, 'application/xml')
).to.xmleql(new DOMParser().parseFromString(doc2, 'application/xml'));
});
it('Test XML document with single root, different prefix, prefix true',
function() {
const doc1 = '<bar:foo xmlns:bar="http://foo"></bar:foo>';
const doc2 = '<foo xmlns="http://foo"></foo>';
expect(new DOMParser().parseFromString(doc1, 'application/xml')).to.not.xmleql(
new DOMParser().parseFromString(doc2, 'application/xml'), {prefix: true});
});
it('Test XML document with single root, different prefix, prefix true', function () {
const doc1 = '<bar:foo xmlns:bar="http://foo"></bar:foo>';
const doc2 = '<foo xmlns="http://foo"></foo>';
expect(
new DOMParser().parseFromString(doc1, 'application/xml')
).to.not.xmleql(
new DOMParser().parseFromString(doc2, 'application/xml'),
{prefix: true}
);
});
it('Test XML document with different root', function() {
it('Test XML document with different root', function () {
const doc1 = '<foo></foo>';
const doc2 = '<bar></bar>';
expect(new DOMParser().parseFromString(doc1, 'application/xml')).to.not.xmleql(
new DOMParser().parseFromString(doc2, 'application/xml'));
expect(
new DOMParser().parseFromString(doc1, 'application/xml')
).to.not.xmleql(new DOMParser().parseFromString(doc2, 'application/xml'));
});
it('Test different number of attributes', function() {
it('Test different number of attributes', function () {
const doc1 = '<foo attr="bla"></foo>';
const doc2 = '<foo></foo>';
expect(new DOMParser().parseFromString(doc1, 'application/xml')).to.not.xmleql(
new DOMParser().parseFromString(doc2, 'application/xml'));
expect(
new DOMParser().parseFromString(doc1, 'application/xml')
).to.not.xmleql(new DOMParser().parseFromString(doc2, 'application/xml'));
});
it('Test different attribute value', function() {
it('Test different attribute value', function () {
const doc1 = '<foo attr="bla"></foo>';
const doc2 = '<foo attr="foo"></foo>';
expect(new DOMParser().parseFromString(doc1, 'application/xml')).to.not.xmleql(
new DOMParser().parseFromString(doc2, 'application/xml'));
expect(
new DOMParser().parseFromString(doc1, 'application/xml')
).to.not.xmleql(new DOMParser().parseFromString(doc2, 'application/xml'));
});
it('Test different number of children', function() {
it('Test different number of children', function () {
const doc1 = '<foo><mynode></mynode></foo>';
const doc2 = '<foo></foo>';
expect(new DOMParser().parseFromString(doc1, 'application/xml')).to.not.xmleql(
new DOMParser().parseFromString(doc2, 'application/xml'));
expect(
new DOMParser().parseFromString(doc1, 'application/xml')
).to.not.xmleql(new DOMParser().parseFromString(doc2, 'application/xml'));
});
});
});
File diff suppressed because it is too large Load Diff
+84 -117
View File
@@ -1,75 +1,68 @@
import Feature, {createStyleFunction} from '../../../src/ol/Feature.js';
import Point from '../../../src/ol/geom/Point.js';
import {isEmpty} from '../../../src/ol/obj.js';
import Style from '../../../src/ol/style/Style.js';
import {isEmpty} from '../../../src/ol/obj.js';
describe('ol.Feature', function() {
describe('constructor', function() {
it('creates a new feature', function() {
describe('ol.Feature', function () {
describe('constructor', function () {
it('creates a new feature', function () {
const feature = new Feature();
expect(feature).to.be.a(Feature);
});
it('takes properties', function() {
it('takes properties', function () {
const feature = new Feature({
foo: 'bar'
foo: 'bar',
});
expect(feature.get('foo')).to.be('bar');
});
it('can store the feature\'s commonly used id', function() {
it("can store the feature's commonly used id", function () {
const feature = new Feature();
feature.setId('foo');
expect(feature.getId()).to.be('foo');
});
it('will set the default geometry', function() {
it('will set the default geometry', function () {
const feature = new Feature({
geometry: new Point([10, 20]),
foo: 'bar'
foo: 'bar',
});
const geometry = feature.getGeometry();
expect(geometry).to.be.a(Point);
expect(feature.get('geometry')).to.be(geometry);
});
});
describe('#get()', function() {
it('returns values set at construction', function() {
describe('#get()', function () {
it('returns values set at construction', function () {
const feature = new Feature({
a: 'first',
b: 'second'
b: 'second',
});
expect(feature.get('a')).to.be('first');
expect(feature.get('b')).to.be('second');
});
it('returns undefined for unset attributes', function() {
it('returns undefined for unset attributes', function () {
const feature = new Feature();
expect(feature.get('a')).to.be(undefined);
});
it('returns values set by set', function() {
it('returns values set by set', function () {
const feature = new Feature();
feature.set('a', 'b');
expect(feature.get('a')).to.be('b');
});
});
describe('#getProperties()', function() {
it('returns an object with all attributes', function() {
describe('#getProperties()', function () {
it('returns an object with all attributes', function () {
const point = new Point([15, 30]);
const feature = new Feature({
foo: 'bar',
ten: 10,
geometry: point
geometry: point,
});
const attributes = feature.getProperties();
@@ -82,43 +75,40 @@ describe('ol.Feature', function() {
expect(attributes.ten).to.be(10);
});
it('is empty by default', function() {
it('is empty by default', function () {
const feature = new Feature();
const properties = feature.getProperties();
expect(isEmpty(properties)).to.be(true);
});
});
describe('#getGeometry()', function() {
describe('#getGeometry()', function () {
const point = new Point([15, 30]);
it('returns undefined for unset geometry', function() {
it('returns undefined for unset geometry', function () {
const feature = new Feature();
expect(feature.getGeometry()).to.be(undefined);
});
it('returns null for null geometry (constructor)', function() {
it('returns null for null geometry (constructor)', function () {
const feature = new Feature(null);
expect(feature.getGeometry()).to.be(undefined);
});
it('returns null for null geometry (setGeometry())', function() {
it('returns null for null geometry (setGeometry())', function () {
const feature = new Feature();
feature.setGeometry(null);
expect(feature.getGeometry()).to.be(null);
});
it('gets the geometry set at construction', function() {
it('gets the geometry set at construction', function () {
const feature = new Feature({
geometry: point
geometry: point,
});
expect(feature.getGeometry()).to.be(point);
});
it('gets any geometry set by setGeometry', function() {
it('gets any geometry set by setGeometry', function () {
const feature = new Feature();
feature.setGeometry(point);
expect(feature.getGeometry()).to.be(point);
@@ -127,32 +117,29 @@ describe('ol.Feature', function() {
feature.setGeometry(point2);
expect(feature.getGeometry()).to.be(point2);
});
});
describe('#set()', function() {
it('sets values', function() {
describe('#set()', function () {
it('sets values', function () {
const feature = new Feature({
a: 'first',
b: 'second'
b: 'second',
});
feature.set('a', 'new');
expect(feature.get('a')).to.be('new');
});
it('can be used to set the geometry', function() {
it('can be used to set the geometry', function () {
const point = new Point([3, 4]);
const feature = new Feature({
geometry: new Point([1, 2])
geometry: new Point([1, 2]),
});
feature.set('geometry', point);
expect(feature.get('geometry')).to.be(point);
expect(feature.getGeometry()).to.be(point);
});
it('can be used to set attributes with arbitrary names', function() {
it('can be used to set attributes with arbitrary names', function () {
const feature = new Feature();
feature.set('toString', 'string');
@@ -164,24 +151,21 @@ describe('ol.Feature', function() {
feature.set('geometry', new Point([1, 2]));
expect(feature.getGeometry()).to.be.a(Point);
});
});
describe('#setGeometry()', function() {
describe('#setGeometry()', function () {
const point = new Point([15, 30]);
it('sets the default geometry', function() {
it('sets the default geometry', function () {
const feature = new Feature();
feature.setGeometry(point);
expect(feature.get('geometry')).to.be(point);
});
it('replaces previous default geometry', function() {
it('replaces previous default geometry', function () {
const feature = new Feature({
geometry: point
geometry: point,
});
expect(feature.getGeometry()).to.be(point);
@@ -189,14 +173,12 @@ describe('ol.Feature', function() {
feature.setGeometry(point2);
expect(feature.getGeometry()).to.be(point2);
});
});
describe('#setGeometryName()', function() {
describe('#setGeometryName()', function () {
const point = new Point([15, 30]);
it('sets property where to to look at geometry', function() {
it('sets property where to to look at geometry', function () {
const feature = new Feature();
feature.setGeometry(point);
expect(feature.getGeometry()).to.be(point);
@@ -207,13 +189,13 @@ describe('ol.Feature', function() {
feature.setGeometryName('altGeometry');
expect(feature.getGeometry()).to.be(point2);
feature.on('change', function() {
feature.on('change', function () {
expect().fail();
});
point.setCoordinates([0, 2]);
});
it('changes property listener', function() {
it('changes property listener', function () {
const feature = new Feature();
feature.setGeometry(point);
const point2 = new Point([1, 2]);
@@ -226,26 +208,24 @@ describe('ol.Feature', function() {
expect(spy.callCount).to.be(1);
});
it('can use a different geometry name', function() {
it('can use a different geometry name', function () {
const feature = new Feature();
feature.setGeometryName('foo');
const point = new Point([10, 20]);
feature.setGeometry(point);
expect(feature.getGeometry()).to.be(point);
});
});
describe('#setId()', function() {
it('sets the feature identifier', function() {
describe('#setId()', function () {
it('sets the feature identifier', function () {
const feature = new Feature();
expect(feature.getId()).to.be(undefined);
feature.setId('foo');
expect(feature.getId()).to.be('foo');
});
it('accepts a string or number', function() {
it('accepts a string or number', function () {
const feature = new Feature();
feature.setId('foo');
expect(feature.getId()).to.be('foo');
@@ -253,79 +233,75 @@ describe('ol.Feature', function() {
expect(feature.getId()).to.be(2);
});
it('dispatches the "change" event', function(done) {
it('dispatches the "change" event', function (done) {
const feature = new Feature();
feature.on('change', function() {
feature.on('change', function () {
expect(feature.getId()).to.be('foo');
done();
});
feature.setId('foo');
});
});
describe('#getStyleFunction()', function() {
const styleFunction = function(feature, resolution) {
describe('#getStyleFunction()', function () {
const styleFunction = function (feature, resolution) {
return null;
};
it('returns undefined after construction', function() {
it('returns undefined after construction', function () {
const feature = new Feature();
expect(feature.getStyleFunction()).to.be(undefined);
});
it('returns the function passed to setStyle', function() {
it('returns the function passed to setStyle', function () {
const feature = new Feature();
feature.setStyle(styleFunction);
expect(feature.getStyleFunction()).to.be(styleFunction);
});
it('does not get confused with user "styleFunction" property', function() {
it('does not get confused with user "styleFunction" property', function () {
const feature = new Feature();
feature.set('styleFunction', 'foo');
expect(feature.getStyleFunction()).to.be(undefined);
});
it('does not get confused with "styleFunction" option', function() {
it('does not get confused with "styleFunction" option', function () {
const feature = new Feature({
styleFunction: 'foo'
styleFunction: 'foo',
});
expect(feature.getStyleFunction()).to.be(undefined);
});
});
describe('#setStyle()', function() {
describe('#setStyle()', function () {
const style = new Style();
const styleFunction = function(feature, resolution) {
const styleFunction = function (feature, resolution) {
return resolution;
};
it('accepts a single style', function() {
it('accepts a single style', function () {
const feature = new Feature();
feature.setStyle(style);
const func = feature.getStyleFunction();
expect(func()).to.eql([style]);
});
it('accepts an array of styles', function() {
it('accepts an array of styles', function () {
const feature = new Feature();
feature.setStyle([style]);
const func = feature.getStyleFunction();
expect(func()).to.eql([style]);
});
it('accepts a style function', function() {
it('accepts a style function', function () {
const feature = new Feature();
feature.setStyle(styleFunction);
expect(feature.getStyleFunction()).to.be(styleFunction);
expect(feature.getStyleFunction()(feature, 42)).to.be(42);
});
it('accepts null', function() {
it('accepts null', function () {
const feature = new Feature();
feature.setStyle(style);
feature.setStyle(null);
@@ -333,25 +309,23 @@ describe('ol.Feature', function() {
expect(feature.getStyleFunction()).to.be(undefined);
});
it('dispatches a change event', function() {
it('dispatches a change event', function () {
const feature = new Feature();
const spy = sinon.spy();
feature.on('change', spy);
feature.setStyle(style);
expect(spy.callCount).to.be(1);
});
});
describe('#getStyle()', function() {
describe('#getStyle()', function () {
const style = new Style();
const styleFunction = function(feature, resolution) {
const styleFunction = function (feature, resolution) {
return null;
};
it('returns what is passed to setStyle', function() {
it('returns what is passed to setStyle', function () {
const feature = new Feature();
expect(feature.getStyle()).to.be(null);
@@ -364,29 +338,26 @@ describe('ol.Feature', function() {
feature.setStyle(styleFunction);
expect(feature.getStyle()).to.be(styleFunction);
});
it('does not get confused with "style" option to constructor', function() {
it('does not get confused with "style" option to constructor', function () {
const feature = new Feature({
style: 'foo'
style: 'foo',
});
expect(feature.getStyle()).to.be(null);
});
it('does not get confused with user set "style" property', function() {
it('does not get confused with user set "style" property', function () {
const feature = new Feature();
feature.set('style', 'foo');
expect(feature.getStyle()).to.be(null);
});
});
describe('#clone', function() {
it('correctly clones features', function() {
describe('#clone', function () {
it('correctly clones features', function () {
const feature = new Feature();
feature.setProperties({'fookey': 'fooval'});
feature.setId(1);
@@ -410,7 +381,7 @@ describe('ol.Feature', function() {
expect(clone.get('barkey')).to.be('barval');
});
it('correctly clones features with no geometry and no style', function() {
it('correctly clones features with no geometry and no style', function () {
const feature = new Feature();
feature.set('fookey', 'fooval');
@@ -421,47 +392,43 @@ describe('ol.Feature', function() {
});
});
describe('#setGeometry()', function() {
it('dispatches a change event when geometry is set to null',
function() {
const feature = new Feature({
geometry: new Point([0, 0])
});
const spy = sinon.spy();
feature.on('change', spy);
feature.setGeometry(null);
expect(spy.callCount).to.be(1);
describe('#setGeometry()', function () {
it('dispatches a change event when geometry is set to null', function () {
const feature = new Feature({
geometry: new Point([0, 0]),
});
const spy = sinon.spy();
feature.on('change', spy);
feature.setGeometry(null);
expect(spy.callCount).to.be(1);
});
});
});
describe('ol.Feature.createStyleFunction()', function() {
describe('ol.Feature.createStyleFunction()', function () {
const style = new Style();
it('creates a feature style function from a single style', function() {
it('creates a feature style function from a single style', function () {
const styleFunction = createStyleFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a feature style function from an array of styles', function() {
it('creates a feature style function from an array of styles', function () {
const styleFunction = createStyleFunction([style]);
expect(styleFunction()).to.eql([style]);
});
it('passes through a function', function() {
const original = function(feature, resolution) {
it('passes through a function', function () {
const original = function (feature, resolution) {
return [style];
};
const styleFunction = createStyleFunction(original);
expect(styleFunction).to.be(original);
});
it('throws on (some) unexpected input', function() {
expect(function() {
it('throws on (some) unexpected input', function () {
expect(function () {
createStyleFunction({bogus: 'input'});
}).to.throwException();
});
});
+12 -16
View File
@@ -1,51 +1,49 @@
import {xhr} from '../../../src/ol/featureloader.js';
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
import VectorSource from '../../../src/ol/source/Vector.js';
import {xhr} from '../../../src/ol/featureloader.js';
describe('ol.featureloader', function() {
describe('ol.featureloader.xhr', function() {
describe('ol.featureloader', function () {
describe('ol.featureloader.xhr', function () {
let loader;
let source;
let url;
let format;
beforeEach(function() {
beforeEach(function () {
url = 'spec/ol/data/point.json';
format = new GeoJSON();
source = new VectorSource();
});
it('adds features to the source', function(done) {
it('adds features to the source', function (done) {
loader = xhr(url, format);
source.on('addfeature', function(e) {
source.on('addfeature', function (e) {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
});
loader.call(source, [], 1, 'EPSG:3857');
});
describe('when called with urlFunction', function() {
it('adds features to the source', function(done) {
url = function(extent, resolution, projection) {
describe('when called with urlFunction', function () {
it('adds features to the source', function (done) {
url = function (extent, resolution, projection) {
return 'spec/ol/data/point.json';
};
loader = xhr(url, format);
source.on('addfeature', function(e) {
source.on('addfeature', function (e) {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
});
loader.call(source, [], 1, 'EPSG:3857');
});
it('sends the correct arguments to the urlFunction', function(done) {
it('sends the correct arguments to the urlFunction', function (done) {
const extent = [];
const resolution = 1;
const projection = 'EPSG:3857';
url = function(extent_, resolution_, projection_) {
url = function (extent_, resolution_, projection_) {
expect(extent_).to.eql(extent);
expect(resolution_).to.eql(resolution);
expect(projection_).to.eql(projection);
@@ -56,7 +54,5 @@ describe('ol.featureloader', function() {
loader.call(source, [], 1, 'EPSG:3857');
});
});
});
});
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+344 -343
View File
@@ -7,32 +7,30 @@ import Polygon from '../../../../src/ol/geom/Polygon.js';
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
import {parse} from '../../../../src/ol/xml.js';
describe('ol.format.GPX', function() {
describe('ol.format.GPX', function () {
let format;
beforeEach(function() {
beforeEach(function () {
format = new GPX();
});
describe('#readProjection', function() {
it('returns the default projection from document', function() {
describe('#readProjection', function () {
it('returns the default projection from document', function () {
const projection = format.readProjectionFromDocument();
expect(projection).to.eql(getProjection('EPSG:4326'));
});
it('returns the default projection from node', function() {
it('returns the default projection from node', function () {
const projection = format.readProjectionFromNode();
expect(projection).to.eql(getProjection('EPSG:4326'));
});
});
describe('rte', function() {
it('can read an empty rte', function() {
describe('rte', function () {
it('can read an empty rte', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <rte/>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <rte/>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -43,25 +41,25 @@ describe('ol.format.GPX', function() {
expect(g.getLayout()).to.be('XY');
});
it('can read and write various rte attributes', function() {
it('can read and write various rte attributes', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <name>Name</name>' +
' <cmt>Comment</cmt>' +
' <desc>Description</desc>' +
' <src>Source</src>' +
' <link href="http://example.com/">' +
' <text>Link text</text>' +
' <type>Link type</type>' +
' </link>' +
' <number>1</number>' +
' <type>Type</type>' +
' </rte>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <name>Name</name>' +
' <cmt>Comment</cmt>' +
' <desc>Description</desc>' +
' <src>Source</src>' +
' <link href="http://example.com/">' +
' <text>Link text</text>' +
' <type>Link type</type>' +
' </link>' +
' <number>1</number>' +
' <type>Type</type>' +
' </rte>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -79,42 +77,45 @@ describe('ol.format.GPX', function() {
expect(serialized).to.xmleql(parse(text));
});
it('can read and write a rte with multiple rtepts', function() {
it('can read and write a rte with multiple rtepts', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <rtept lat="1" lon="2"/>' +
' <rtept lat="3" lon="4"/>' +
' </rte>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <rtept lat="1" lon="2"/>' +
' <rtept lat="3" lon="4"/>' +
' </rte>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
expect(f).to.be.an(Feature);
const g = f.getGeometry();
expect(g).to.be.an(LineString);
expect(g.getCoordinates()).to.eql([[2, 1], [4, 3]]);
expect(g.getCoordinates()).to.eql([
[2, 1],
[4, 3],
]);
expect(g.getLayout()).to.be('XY');
const serialized = format.writeFeaturesNode(fs);
expect(serialized).to.xmleql(parse(text));
});
it('can transform, read and write a rte', function() {
it('can transform, read and write a rte', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <rtept lat="1" lon="2"/>' +
' <rtept lat="5" lon="6"/>' +
' </rte>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <rtept lat="1" lon="2"/>' +
' <rtept lat="5" lon="6"/>' +
' </rte>' +
'</gpx>';
const fs = format.readFeatures(text, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(fs).to.have.length(1);
const f = fs[0];
@@ -126,37 +127,35 @@ describe('ol.format.GPX', function() {
expect(g.getCoordinates()).to.eql([p1, p2]);
expect(g.getLayout()).to.be('XY');
const serialized = format.writeFeaturesNode(fs, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(serialized).to.xmleql(parse(text));
});
it('does not write rte attributes in rtepts', function() {
it('does not write rte attributes in rtepts', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <name>Name</name>' +
' <rtept lat="1" lon="2"/>' +
' <rtept lat="3" lon="4"/>' +
' </rte>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <rte>' +
' <name>Name</name>' +
' <rtept lat="1" lon="2"/>' +
' <rtept lat="3" lon="4"/>' +
' </rte>' +
'</gpx>';
const fs = format.readFeatures(text);
const serialized = format.writeFeaturesNode(fs);
expect(serialized).to.xmleql(parse(text));
});
});
describe('trk', function() {
it('can read an empty trk', function() {
describe('trk', function () {
it('can read an empty trk', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <trk/>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <trk/>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -167,25 +166,25 @@ describe('ol.format.GPX', function() {
expect(g.getLayout()).to.be('XY');
});
it('can read and write various trk attributes', function() {
it('can read and write various trk attributes', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <name>Name</name>' +
' <cmt>Comment</cmt>' +
' <desc>Description</desc>' +
' <src>Source</src>' +
' <link href="http://example.com/">' +
' <text>Link text</text>' +
' <type>Link type</type>' +
' </link>' +
' <number>1</number>' +
' <type>Type</type>' +
' </trk>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <name>Name</name>' +
' <cmt>Comment</cmt>' +
' <desc>Description</desc>' +
' <src>Source</src>' +
' <link href="http://example.com/">' +
' <text>Link text</text>' +
' <type>Link type</type>' +
' </link>' +
' <number>1</number>' +
' <type>Type</type>' +
' </trk>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -203,16 +202,16 @@ describe('ol.format.GPX', function() {
expect(serialized).to.xmleql(parse(text));
});
it('can read and write a trk with an empty trkseg', function() {
it('can read and write a trk with an empty trkseg', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg/>' +
' </trk>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg/>' +
' </trk>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -225,25 +224,25 @@ describe('ol.format.GPX', function() {
expect(serialized).to.xmleql(parse(text));
});
it('can read/write a trk with a trkseg with multiple trkpts', function() {
it('can read/write a trk with a trkseg with multiple trkpts', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -251,34 +250,37 @@ describe('ol.format.GPX', function() {
const g = f.getGeometry();
expect(g).to.be.an(MultiLineString);
expect(g.getCoordinates()).to.eql([
[[2, 1, 3, 1263115752], [6, 5, 7, 1263115812]]
[
[2, 1, 3, 1263115752],
[6, 5, 7, 1263115812],
],
]);
expect(g.getLayout()).to.be('XYZM');
const serialized = format.writeFeaturesNode(fs);
expect(serialized).to.xmleql(parse(text));
});
it('can transform, read and write a trk with a trkseg', function() {
it('can transform, read and write a trk with a trkseg', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
const fs = format.readFeatures(text, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(fs).to.have.length(1);
const f = fs[0];
@@ -292,40 +294,40 @@ describe('ol.format.GPX', function() {
expect(g.getCoordinates()).to.eql([[p1, p2]]);
expect(g.getLayout()).to.be('XYZM');
const serialized = format.writeFeaturesNode(fs, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(serialized).to.xmleql(parse(text));
});
it('can read and write a trk with multiple trksegs', function() {
it('can read and write a trk with multiple trksegs', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' <trkseg>' +
' <trkpt lat="8" lon="9">' +
' <ele>10</ele>' +
' <time>2010-01-10T09:31:12Z</time>' +
' </trkpt>' +
' <trkpt lat="11" lon="12">' +
' <ele>13</ele>' +
' <time>2010-01-10T09:32:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' <trkseg>' +
' <trkpt lat="8" lon="9">' +
' <ele>10</ele>' +
' <time>2010-01-10T09:31:12Z</time>' +
' </trkpt>' +
' <trkpt lat="11" lon="12">' +
' <ele>13</ele>' +
' <time>2010-01-10T09:32:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -333,61 +335,65 @@ describe('ol.format.GPX', function() {
const g = f.getGeometry();
expect(g).to.be.an(MultiLineString);
expect(g.getCoordinates()).to.eql([
[[2, 1, 3, 1263115752], [6, 5, 7, 1263115812]],
[[9, 8, 10, 1263115872], [12, 11, 13, 1263115932]]
[
[2, 1, 3, 1263115752],
[6, 5, 7, 1263115812],
],
[
[9, 8, 10, 1263115872],
[12, 11, 13, 1263115932],
],
]);
expect(g.getLayout()).to.be('XYZM');
const serialized = format.writeFeaturesNode(fs);
expect(serialized).to.xmleql(parse(text));
});
it('does not write trk attributes in trkpts', function() {
it('does not write trk attributes in trkpts', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <name>Name</name>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' <trkseg>' +
' <trkpt lat="8" lon="9">' +
' <ele>10</ele>' +
' <time>2010-01-10T09:31:12Z</time>' +
' </trkpt>' +
' <trkpt lat="11" lon="12">' +
' <ele>13</ele>' +
' <time>2010-01-10T09:32:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <trk>' +
' <name>Name</name>' +
' <trkseg>' +
' <trkpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </trkpt>' +
' <trkpt lat="5" lon="6">' +
' <ele>7</ele>' +
' <time>2010-01-10T09:30:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' <trkseg>' +
' <trkpt lat="8" lon="9">' +
' <ele>10</ele>' +
' <time>2010-01-10T09:31:12Z</time>' +
' </trkpt>' +
' <trkpt lat="11" lon="12">' +
' <ele>13</ele>' +
' <time>2010-01-10T09:32:12Z</time>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
const fs = format.readFeatures(text);
const serialized = format.writeFeaturesNode(fs);
expect(serialized).to.xmleql(parse(text));
});
});
describe('wpt', function() {
it('can read and write a wpt', function() {
describe('wpt', function () {
it('can read and write a wpt', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2"/>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2"/>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -400,16 +406,16 @@ describe('ol.format.GPX', function() {
expect(serialized).to.xmleql(parse(text));
});
it('can transform, read and write a wpt', function() {
it('can transform, read and write a wpt', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2"/>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2"/>' +
'</gpx>';
const fs = format.readFeatures(text, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(fs).to.have.length(1);
const f = fs[0];
@@ -420,21 +426,21 @@ describe('ol.format.GPX', function() {
expect(g.getCoordinates()).to.eql(expectedPoint);
expect(g.getLayout()).to.be('XY');
const serialized = format.writeFeaturesNode(fs, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(serialized).to.xmleql(parse(text));
});
it('can read and write a wpt with ele', function() {
it('can read and write a wpt with ele', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <ele>3</ele>' +
' </wpt>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <ele>3</ele>' +
' </wpt>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -447,16 +453,16 @@ describe('ol.format.GPX', function() {
expect(serialized).to.xmleql(parse(text));
});
it('can read and write a wpt with time', function() {
it('can read and write a wpt with time', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <time>2010-01-10T09:29:12Z</time>' +
' </wpt>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <time>2010-01-10T09:29:12Z</time>' +
' </wpt>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -469,17 +475,17 @@ describe('ol.format.GPX', function() {
expect(serialized).to.xmleql(parse(text));
});
it('can read and write a wpt with ele and time', function() {
it('can read and write a wpt with ele and time', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </wpt>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <ele>3</ele>' +
' <time>2010-01-10T09:29:12Z</time>' +
' </wpt>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -492,34 +498,34 @@ describe('ol.format.GPX', function() {
expect(serialized).to.xmleql(parse(text));
});
it('can read and write various wpt attributes', function() {
it('can read and write various wpt attributes', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <magvar>11</magvar>' +
' <geoidheight>4</geoidheight>' +
' <name>Name</name>' +
' <cmt>Comment</cmt>' +
' <desc>Description</desc>' +
' <src>Source</src>' +
' <link href="http://example.com/">' +
' <text>Link text</text>' +
' <type>Link type</type>' +
' </link>' +
' <sym>Symbol</sym>' +
' <type>Type</type>' +
' <fix>2d</fix>' +
' <sat>5</sat>' +
' <hdop>6</hdop>' +
' <vdop>7</vdop>' +
' <pdop>8</pdop>' +
' <ageofdgpsdata>9</ageofdgpsdata>' +
' <dgpsid>10</dgpsid>' +
' </wpt>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="OpenLayers">' +
' <wpt lat="1" lon="2">' +
' <magvar>11</magvar>' +
' <geoidheight>4</geoidheight>' +
' <name>Name</name>' +
' <cmt>Comment</cmt>' +
' <desc>Description</desc>' +
' <src>Source</src>' +
' <link href="http://example.com/">' +
' <text>Link text</text>' +
' <type>Link type</type>' +
' </link>' +
' <sym>Symbol</sym>' +
' <type>Type</type>' +
' <fix>2d</fix>' +
' <sat>5</sat>' +
' <hdop>6</hdop>' +
' <vdop>7</vdop>' +
' <pdop>8</pdop>' +
' <ageofdgpsdata>9</ageofdgpsdata>' +
' <dgpsid>10</dgpsid>' +
' </wpt>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const f = fs[0];
@@ -544,136 +550,131 @@ describe('ol.format.GPX', function() {
const serialized = format.writeFeaturesNode(fs);
expect(serialized).to.xmleql(parse(text));
});
});
describe('XML namespace support', function() {
beforeEach(function() {
describe('XML namespace support', function () {
beforeEach(function () {
format = new GPX();
});
it('can read features with a version 1.0 namespace', function() {
it('can read features with a version 1.0 namespace', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/0">' +
' <wpt/>' +
' <rte/>' +
' <trk/>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/0">' +
' <wpt/>' +
' <rte/>' +
' <trk/>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(3);
});
it('can read features with a version 1.1 namespace', function() {
it('can read features with a version 1.1 namespace', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <wpt/>' +
' <rte/>' +
' <trk/>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <wpt/>' +
' <rte/>' +
' <trk/>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(3);
});
it('can read features with no namespace', function() {
const text =
'<gpx>' +
' <wpt/>' +
' <rte/>' +
' <trk/>' +
'</gpx>';
it('can read features with no namespace', function () {
const text = '<gpx>' + ' <wpt/>' + ' <rte/>' + ' <trk/>' + '</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(3);
});
});
describe('extensions support', function() {
beforeEach(function() {
describe('extensions support', function () {
beforeEach(function () {
format = new GPX({
readExtensions: function(feature, extensionsNode) {
readExtensions: function (feature, extensionsNode) {
const nodes = extensionsNode.getElementsByTagName('id');
const id = nodes.item(0).textContent;
feature.setId(id);
}
},
});
});
it('can process extensions from wpt', function() {
it('can process extensions from wpt', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <wpt>' +
' <extensions>' +
' <id>feature-id</id>' +
' </extensions>' +
' </wpt>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <wpt>' +
' <extensions>' +
' <id>feature-id</id>' +
' </extensions>' +
' </wpt>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const feature = fs[0];
expect(feature.getId()).to.be('feature-id');
});
it('can process extensions from rte', function() {
it('can process extensions from rte', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <rte>' +
' <extensions>' +
' <foo>bar</foo>' +
' <id>feature-id</id>' +
' </extensions>' +
' </rte>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <rte>' +
' <extensions>' +
' <foo>bar</foo>' +
' <id>feature-id</id>' +
' </extensions>' +
' </rte>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const feature = fs[0];
expect(feature.getId()).to.be('feature-id');
});
it('can process extensions from trk, not trkpt', function() {
it('can process extensions from trk, not trkpt', function () {
const text =
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <trk>' +
' <extensions>' +
' <id>feature-id</id>' +
' </extensions>' +
' <trkseg>' +
' <trkpt>' +
' <extensions>' +
' <id>another-feature-id</id>' +
' </extensions>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
' <trk>' +
' <extensions>' +
' <id>feature-id</id>' +
' </extensions>' +
' <trkseg>' +
' <trkpt>' +
' <extensions>' +
' <id>another-feature-id</id>' +
' </extensions>' +
' </trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(1);
const feature = fs[0];
expect(feature.getId()).to.be('feature-id');
});
});
describe('write unsupported geometries', function() {
beforeEach(function() {
describe('write unsupported geometries', function () {
beforeEach(function () {
format = new GPX();
});
it('does not fail', function() {
const polygon = new Polygon(
[[[0, 0], [2, 2], [4, 0], [0, 0]]]);
it('does not fail', function () {
const polygon = new Polygon([
[
[0, 0],
[2, 2],
[4, 0],
[0, 0],
],
]);
const feature = new Feature(polygon);
const features = [feature];
const gpx = format.writeFeaturesNode(features);
const expected =
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" ' +
'creator="OpenLayers"></gpx>';
'<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" ' +
'creator="OpenLayers"></gpx>';
expect(gpx).to.xmleql(parse(expected));
});
});
});
+83 -54
View File
@@ -1,50 +1,48 @@
import IGC from '../../../../src/ol/format/IGC.js';
import Feature from '../../../../src/ol/Feature.js';
import IGC from '../../../../src/ol/format/IGC.js';
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
describe('ol.format.IGC', function() {
describe('ol.format.IGC', function () {
let format;
const igc =
'AFLY05094\n' +
'HFDTE190411\n' +
'HFFXA100\n' +
'HFPLTPILOT:Tom Payne\n' +
'HFGTYGLIDERTYPE:Axis Mercury\n' +
'HFGIDGLIDERID:\n' +
'HFDTM100GPSDATUM:WGS84\n' +
'HFGPSGPS:FURUNO GH-80\n' +
'HFRFWFIRMWAREVERSION:1.22\n' +
'HFRHWHARDWAREVERSION:1.00\n' +
'HFFTYFRTYPE:FLYTEC,5020\n' +
'I013638TAS\n' +
'B0848484556256N00651095EA0205102039000\n' +
'B0855534556037N00651011EA0259302513000\n' +
'B0903354554964N00648049EA0272402758000\n' +
'B0848484556256N00651095EA0205102039000\n' +
'GAB890A77AFE5CE63979AF6B1BED7F07D\n' +
'G62BB282E44D63A1149EF2F5E8AF6F2F1\n' +
'GEC14381987B15F81003EDE1E01A47843\n' +
'G60189641B00B00800019000000000000';
'AFLY05094\n' +
'HFDTE190411\n' +
'HFFXA100\n' +
'HFPLTPILOT:Tom Payne\n' +
'HFGTYGLIDERTYPE:Axis Mercury\n' +
'HFGIDGLIDERID:\n' +
'HFDTM100GPSDATUM:WGS84\n' +
'HFGPSGPS:FURUNO GH-80\n' +
'HFRFWFIRMWAREVERSION:1.22\n' +
'HFRHWHARDWAREVERSION:1.00\n' +
'HFFTYFRTYPE:FLYTEC,5020\n' +
'I013638TAS\n' +
'B0848484556256N00651095EA0205102039000\n' +
'B0855534556037N00651011EA0259302513000\n' +
'B0903354554964N00648049EA0272402758000\n' +
'B0848484556256N00651095EA0205102039000\n' +
'GAB890A77AFE5CE63979AF6B1BED7F07D\n' +
'G62BB282E44D63A1149EF2F5E8AF6F2F1\n' +
'GEC14381987B15F81003EDE1E01A47843\n' +
'G60189641B00B00800019000000000000';
beforeEach(function() {
beforeEach(function () {
format = new IGC();
});
describe('#readProjectionFromText', function() {
it('returns the default projection', function() {
describe('#readProjectionFromText', function () {
it('returns the default projection', function () {
const projection = format.readProjectionFromText(igc);
expect(projection).to.eql(getProjection('EPSG:4326'));
});
});
describe('#readFeature', function() {
it('does not read invalid features', function() {
describe('#readFeature', function () {
it('does not read invalid features', function () {
expect(format.readFeature('invalid')).to.be(null);
});
it('does read a feature', function() {
it('does read a feature', function () {
const feature = format.readFeature(igc);
expect(feature).to.be.an(Feature);
const geom = feature.getGeometry();
@@ -53,43 +51,58 @@ describe('ol.format.IGC', function() {
[6.851583333333333, 45.9376, 1303202928],
[6.850183333333334, 45.93395, 1303203353],
[6.800816666666667, 45.916066666666666, 1303203815],
[6.851583333333333, 45.9376, 1303289328]]);
[6.851583333333333, 45.9376, 1303289328],
]);
});
it('does transform and read a feature', function() {
it('does transform and read a feature', function () {
const feature = format.readFeature(igc, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(feature).to.be.an(Feature);
const geom = feature.getGeometry();
expect(geom.getType()).to.eql('LineString');
const expectedPoint1 = transform(
[6.851583333333333, 45.9376], 'EPSG:4326', 'EPSG:3857');
[6.851583333333333, 45.9376],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint1.push(1303202928);
const expectedPoint2 = transform(
[6.850183333333334, 45.93395], 'EPSG:4326', 'EPSG:3857');
[6.850183333333334, 45.93395],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint2.push(1303203353);
const expectedPoint3 = transform(
[6.800816666666667, 45.916066666666666], 'EPSG:4326', 'EPSG:3857');
[6.800816666666667, 45.916066666666666],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint3.push(1303203815);
const expectedPoint4 = transform(
[6.851583333333333, 45.9376], 'EPSG:4326', 'EPSG:3857');
[6.851583333333333, 45.9376],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint4.push(1303289328);
expect(geom.getCoordinates()).to.eql(
[expectedPoint1, expectedPoint2, expectedPoint3, expectedPoint4]);
expect(geom.getCoordinates()).to.eql([
expectedPoint1,
expectedPoint2,
expectedPoint3,
expectedPoint4,
]);
});
});
describe('#readFeatures', function() {
it('does not read invalid features', function() {
describe('#readFeatures', function () {
it('does not read invalid features', function () {
expect(format.readFeatures('invalid')).to.be.empty();
});
it('does read features', function() {
it('does read features', function () {
const features = format.readFeatures(igc);
expect(features.length).to.eql(1);
const feature = features[0];
@@ -100,12 +113,13 @@ describe('ol.format.IGC', function() {
[6.851583333333333, 45.9376, 1303202928],
[6.850183333333334, 45.93395, 1303203353],
[6.800816666666667, 45.916066666666666, 1303203815],
[6.851583333333333, 45.9376, 1303289328]]);
[6.851583333333333, 45.9376, 1303289328],
]);
});
it('does transform and read features', function() {
it('does transform and read features', function () {
const features = format.readFeatures(igc, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(features.length).to.eql(1);
const feature = features[0];
@@ -114,21 +128,36 @@ describe('ol.format.IGC', function() {
expect(geom.getType()).to.eql('LineString');
const expectedPoint1 = transform(
[6.851583333333333, 45.9376], 'EPSG:4326', 'EPSG:3857');
[6.851583333333333, 45.9376],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint1.push(1303202928);
const expectedPoint2 = transform(
[6.850183333333334, 45.93395], 'EPSG:4326', 'EPSG:3857');
[6.850183333333334, 45.93395],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint2.push(1303203353);
const expectedPoint3 = transform(
[6.800816666666667, 45.916066666666666], 'EPSG:4326', 'EPSG:3857');
[6.800816666666667, 45.916066666666666],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint3.push(1303203815);
const expectedPoint4 = transform(
[6.851583333333333, 45.9376], 'EPSG:4326', 'EPSG:3857');
[6.851583333333333, 45.9376],
'EPSG:4326',
'EPSG:3857'
);
expectedPoint4.push(1303289328);
expect(geom.getCoordinates()).to.eql(
[expectedPoint1, expectedPoint2, expectedPoint3, expectedPoint4]);
expect(geom.getCoordinates()).to.eql([
expectedPoint1,
expectedPoint2,
expectedPoint3,
expectedPoint4,
]);
});
});
});
+148 -151
View File
@@ -1,169 +1,163 @@
import IIIFInfo from '../../../../src/ol/format/IIIFInfo.js';
import {Versions} from '../../../../src/ol/format/IIIFInfo.js';
describe('ol.format.IIIFInfo', function() {
describe('ol.format.IIIFInfo', function () {
const iiifInfo = new IIIFInfo();
describe('setImageInfo', function() {
it('can handle image info JSON as object or as string serialization', function() {
describe('setImageInfo', function () {
it('can handle image info JSON as object or as string serialization', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION3);
iiifInfo.setImageInfo('{"@context": "http://iiif.io/api/image/2/context.json","@id":"http://iiif.test/id"}');
iiifInfo.setImageInfo(
'{"@context": "http://iiif.io/api/image/2/context.json","@id":"http://iiif.test/id"}'
);
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION2);
});
});
describe('getImageApiVersion', function() {
it('provides the correct Image API version', function() {
describe('getImageApiVersion', function () {
it('provides the correct Image API version', function () {
iiifInfo.setImageInfo({
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(function() {
expect(function () {
iiifInfo.getImageApiVersion();
}).to.throwException();
iiifInfo.setImageInfo({
identifier: 'http://iiif.test/id',
profile: 'this is no valid profile'
profile: 'this is no valid profile',
});
expect(function() {
expect(function () {
iiifInfo.getImageApiVersion();
}).to.throwException();
iiifInfo.setImageInfo({
'@context': 'this is no valid context',
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(function() {
expect(function () {
iiifInfo.getImageApiVersion();
}).to.throwException();
iiifInfo.setImageInfo({
identifier: 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION1);
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION1);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/1/context.json',
identifier: 'http://iiif.test/id'
identifier: 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION1);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION2);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
id: 'http://iiif.test/id'
id: 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION3);
});
});
describe('getComplianceLevelFromProfile', function() {
it('detects the correct compliance level', function() {
describe('getComplianceLevelFromProfile', function () {
it('detects the correct compliance level', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'level0'
profile: 'level0',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/level3.json'
profile: 'http://iiif.io/api/image/level3.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'level1'
profile: 'level1',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level2.json'
profile: 'http://iiif.io/api/image/2/level2.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level2');
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: ['http://iiif.io/api/image/2/level1.json']
profile: ['http://iiif.io/api/image/2/level1.json'],
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level1');
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level4'
profile: 'level4',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'http://iiif.io/api/image/3/level3.json'
profile: 'http://iiif.io/api/image/3/level3.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'http://iiif.io/api/image/2/level1.json'
profile: 'http://iiif.io/api/image/2/level1.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level2'
profile: 'level2',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level2');
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'http://iiif.io/api/image/3/level1.json'
profile: 'http://iiif.io/api/image/3/level1.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level1');
});
});
describe('getComplianceLevelSupportedFeatures', function() {
it('provides the correct features for given versions and compliance levels', function() {
describe('getComplianceLevelSupportedFeatures', function () {
it('provides the correct features for given versions and compliance levels', function () {
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
let level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.be.empty();
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level1'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level1',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(4);
@@ -173,8 +167,10 @@ describe('ol.format.IIIFInfo', function() {
expect(level.supports).to.contain('sizeByPct');
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level2'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level2',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(7);
@@ -188,14 +184,14 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level0.json'
profile: 'http://iiif.io/api/image/2/level0.json',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.be.empty();
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level1.json'
profile: 'http://iiif.io/api/image/2/level1.json',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(4);
@@ -206,7 +202,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level2.json'
profile: 'http://iiif.io/api/image/2/level2.json',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(8);
@@ -221,14 +217,14 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level0'
profile: 'level0',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.be.empty();
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level1'
profile: 'level1',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(5);
@@ -240,7 +236,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level2'
profile: 'level2',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(8);
@@ -252,26 +248,23 @@ describe('ol.format.IIIFInfo', function() {
expect(level.supports).to.contain('sizeByWh');
expect(level.supports).to.contain('sizeByConfinedWh');
expect(level.supports).to.contain('sizeByPct');
});
});
describe('getTileSourceOptions', function() {
it('produces options from minimal information responses', function() {
expect(function() {
describe('getTileSourceOptions', function () {
it('produces options from minimal information responses', function () {
expect(function () {
iiifInfo.setImageInfo({
width: 2000,
height: 1500
height: 1500,
});
iiifInfo.getTileSourceOptions();
}).to.throwException();
iiifInfo.setImageInfo({
identifier: 'id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
let options = iiifInfo.getTileSourceOptions();
@@ -282,7 +275,8 @@ describe('ol.format.IIIFInfo', function() {
identifier: 'identifier-version-1.0',
width: 2000,
height: 1500,
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
options = iiifInfo.getTileSourceOptions();
@@ -303,7 +297,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/version2/id'
'@id': 'http://iiif.test/version2/id',
});
options = iiifInfo.getTileSourceOptions();
@@ -311,21 +305,19 @@ describe('ol.format.IIIFInfo', function() {
expect(options).to.have.property('version', Versions.VERSION2);
expect(options).to.have.property('url', 'http://iiif.test/version2/id');
expect(options).to.have.property('format', 'jpg');
});
it('uses preferred options if applicable', function() {
it('uses preferred options if applicable', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/version2/id',
width: 2000,
height: 1500,
profile: ['http://iiif.io/api/image/2/level2.json']
profile: ['http://iiif.io/api/image/2/level2.json'],
});
let options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'bitonal');
expect(options).to.have.property('format', 'png');
@@ -336,29 +328,27 @@ describe('ol.format.IIIFInfo', function() {
width: 2000,
height: 1500,
profile: 'level2',
extraQualities: ['gray', 'bitonal']
extraQualities: ['gray', 'bitonal'],
});
options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'bitonal');
expect(options).to.have.property('format', 'png');
});
it('ignores preferred options that are not supported', function() {
it('ignores preferred options that are not supported', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/version2/id',
width: 2000,
height: 1500,
profile: ['http://iiif.io/api/image/2/level1.json']
profile: ['http://iiif.io/api/image/2/level1.json'],
});
let options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'default');
expect(options).to.have.property('format', 'jpg');
@@ -368,25 +358,26 @@ describe('ol.format.IIIFInfo', function() {
'@id': 'http://iiif.test/version3/id',
width: 2000,
height: 1500,
profile: 'level1'
profile: 'level1',
});
options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'default');
expect(options).to.have.property('format', 'jpg');
});
it('combines supported features indicated by compliance level and explicitly stated in image info', function() {
it('combines supported features indicated by compliance level and explicitly stated in image info', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: ['http://iiif.io/api/image/2/level1.json', {
supports: ['regionByPct', 'sizeByWh']
}]
profile: [
'http://iiif.io/api/image/2/level1.json',
{
supports: ['regionByPct', 'sizeByWh'],
},
],
});
let options = iiifInfo.getTileSourceOptions();
@@ -402,7 +393,7 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
id: 'http://iiif.test/id',
profile: 'level1',
extraFeatures: ['regionByPct', 'sizeByPct']
extraFeatures: ['regionByPct', 'sizeByPct'],
});
options = iiifInfo.getTileSourceOptions();
@@ -414,26 +405,28 @@ describe('ol.format.IIIFInfo', function() {
expect(options.supports).to.contain('sizeByH');
expect(options.supports).to.contain('sizeByWh');
expect(options.supports).to.have.length(7);
});
it('uses the first available scale factors and tile sizes', function() {
it('uses the first available scale factors and tile sizes', function () {
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
let options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.be(undefined);
expect(options.tileSize).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
scale_factors: [1, 2, 4],
tile_width: 512
tile_width: 512,
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -445,12 +438,14 @@ describe('ol.format.IIIFInfo', function() {
expect(options.tileSize[1]).to.be(512);
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
scale_factors: [1, 2, 4],
tile_width: 512,
tile_height: 1024
tile_height: 1024,
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -464,7 +459,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://iiif.io/api/image/2/level0.json'
profile: 'http://iiif.io/api/image/2/level0.json',
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.be(undefined);
@@ -474,14 +469,16 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://iiif.io/api/image/2/level0.json',
tiles: [{
scaleFactors: [1, 2, 4],
width: 512
},
{
scaleFactors: [1, 2, 4, 8, 16],
width: 256
}]
tiles: [
{
scaleFactors: [1, 2, 4],
width: 512,
},
{
scaleFactors: [1, 2, 4, 8, 16],
width: 256,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -496,11 +493,13 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://iiif.io/api/image/2/level0.json',
tiles: [{
scaleFactors: [1, 2, 4],
width: 512,
height: 1024
}]
tiles: [
{
scaleFactors: [1, 2, 4],
width: 512,
height: 1024,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -515,11 +514,13 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
'@id': 'http://iiif.test/id',
profile: 'level0',
tiles: [{
scaleFactors: [1, 2, 4, 8],
width: 512,
height: 256
}]
tiles: [
{
scaleFactors: [1, 2, 4, 8],
width: 512,
height: 256,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(4);
@@ -530,28 +531,27 @@ describe('ol.format.IIIFInfo', function() {
expect(options.tileSize).to.have.length(2);
expect(options.tileSize[0]).to.be(512);
expect(options.tileSize[1]).to.be(256);
});
});
it('provides each given size in sizes as OpenLayers Size', function() {
it('provides each given size in sizes as OpenLayers Size', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
'sizes': [{
width: 2000,
height: 1000
},
{
width: 1000,
height: 500
},
{
width: 500,
height: 250
}]
'sizes': [
{
width: 2000,
height: 1000,
},
{
width: 1000,
height: 500,
},
{
width: 500,
height: 250,
},
],
});
let options = iiifInfo.getTileSourceOptions();
expect(options.sizes).to.have.length(3);
@@ -568,26 +568,26 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
'@id': 'http://iiif.test/id',
'sizes': [{
width: 1500,
height: 800
}]
'sizes': [
{
width: 1500,
height: 800,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.sizes).to.have.length(1);
expect(options.sizes[0]).to.have.length(2);
expect(options.sizes[0][0]).to.be(1500);
expect(options.sizes[0][1]).to.be(800);
});
it('respects the preferred image formats', function() {
it('respects the preferred image formats', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
'id': 'http://iiif.test/id',
'profile': 'level0',
'preferredFormats': ['png', 'gif']
'preferredFormats': ['png', 'gif'],
});
let options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('jpg');
@@ -596,7 +596,7 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
'id': 'http://iiif.test/id',
'profile': 'level1',
'preferredFormats': ['png', 'gif']
'preferredFormats': ['png', 'gif'],
});
options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('jpg');
@@ -606,7 +606,7 @@ describe('ol.format.IIIFInfo', function() {
'id': 'http://iiif.test/id',
'profile': 'level1',
'extraFormats': ['webp', 'gif'],
'preferredFormats': ['webp', 'png', 'gif']
'preferredFormats': ['webp', 'png', 'gif'],
});
options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('gif');
@@ -615,12 +615,9 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
'id': 'http://iiif.test/id',
'profile': 'level2',
'preferredFormats': ['png', 'gif']
'preferredFormats': ['png', 'gif'],
});
options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('png');
});
});
File diff suppressed because it is too large Load Diff
+78 -51
View File
@@ -1,47 +1,50 @@
import Feature from '../../../../src/ol/Feature.js';
import MVT from '../../../../src/ol/format/MVT.js';
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
import Point from '../../../../src/ol/geom/Point.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
import RenderFeature from '../../../../src/ol/render/Feature.js';
where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
where('ArrayBuffer.isView').describe('ol.format.MVT', function () {
let data;
beforeEach(function(done) {
beforeEach(function (done) {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'spec/ol/data/14-8938-5680.vector.pbf');
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
xhr.onload = function () {
data = xhr.response;
done();
};
xhr.send();
});
describe('#readFeatures', function() {
describe('#readFeatures', function () {
const options = {
featureProjection: 'EPSG:3857',
extent: [1824704.739223726, 6141868.096770482, 1827150.7241288517, 6144314.081675608]
extent: [
1824704.739223726,
6141868.096770482,
1827150.7241288517,
6144314.081675608,
],
};
it('uses ol.render.Feature as feature class by default', function() {
it('uses ol.render.Feature as feature class by default', function () {
const format = new MVT({layers: ['water']});
const features = format.readFeatures(data, options);
expect(features[0]).to.be.a(RenderFeature);
});
it('parses only specified layers', function() {
it('parses only specified layers', function () {
const format = new MVT({layers: ['water']});
const features = format.readFeatures(data, options);
expect(features.length).to.be(10);
});
it('parses geometries correctly', function() {
it('parses geometries correctly', function () {
const format = new MVT({
featureClass: Feature,
layers: ['poi_label']
layers: ['poi_label'],
});
let geometry;
@@ -62,27 +65,27 @@ where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
expect(geometry.getCoordinates()[1][0]).to.eql([4160, 3489]);
});
it('parses id property', function() {
it('parses id property', function () {
// ol.Feature
let format = new MVT({
featureClass: Feature,
layers: ['building']
layers: ['building'],
});
let features = format.readFeatures(data, options);
expect(features[0].getId()).to.be(2);
// ol.render.Feature
format = new MVT({
layers: ['building']
layers: ['building'],
});
features = format.readFeatures(data, options);
expect(features[0].getId()).to.be(2);
});
it('accepts custom idProperty', function() {
it('accepts custom idProperty', function () {
const format = new MVT({
featureClass: Feature,
layers: ['poi_label'],
idProperty: 'osm_id'
idProperty: 'osm_id',
});
const features = format.readFeatures(data, options);
@@ -91,10 +94,10 @@ where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
expect(first.get('osm_id')).to.be(undefined);
});
it('accepts custom idProperty (render features)', function() {
it('accepts custom idProperty (render features)', function () {
const format = new MVT({
layers: ['poi_label'],
idProperty: 'osm_id'
idProperty: 'osm_id',
});
const features = format.readFeatures(data, options);
@@ -104,10 +107,10 @@ where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
expect(first.get('osm_id')).to.be(undefined);
});
it('works if you provide a bogus idProperty', function() {
it('works if you provide a bogus idProperty', function () {
const format = new MVT({
layers: ['poi_label'],
idProperty: 'bogus'
idProperty: 'bogus',
});
const features = format.readFeatures(data, options);
@@ -115,35 +118,42 @@ where('ArrayBuffer.isView').describe('ol.format.MVT', function() {
const first = features[0];
expect(first.getId()).to.be(undefined);
});
});
});
describe('ol.format.MVT', function() {
describe('ol.format.MVT', function () {
const options = {
featureProjection: 'EPSG:3857',
extent: [1824704.739223726, 6141868.096770482, 1827150.7241288517, 6144314.081675608]
extent: [
1824704.739223726,
6141868.096770482,
1827150.7241288517,
6144314.081675608,
],
};
describe('#createFeature_', function() {
it('accepts a geometryName', function() {
describe('#createFeature_', function () {
it('accepts a geometryName', function () {
const format = new MVT({
featureClass: Feature,
geometryName: 'myGeom'
geometryName: 'myGeom',
});
const rawFeature = {
id: 1,
properties: {
geometry: 'foo'
geometry: 'foo',
},
type: 1,
layer: {
name: 'layer1'
}
name: 'layer1',
},
};
format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) {
format.readRawGeometry_ = function (
{},
rawFeature,
flatCoordinates,
ends
) {
flatCoordinates.push(0, 0);
ends.push(2);
};
@@ -154,18 +164,23 @@ describe('ol.format.MVT', function() {
expect(feature.get('geometry')).to.be('foo');
});
it('detects a Polygon', function() {
it('detects a Polygon', function () {
const format = new MVT({
featureClass: Feature
featureClass: Feature,
});
const rawFeature = {
type: 3,
properties: {},
layer: {
name: 'layer1'
}
name: 'layer1',
},
};
format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) {
format.readRawGeometry_ = function (
{},
rawFeature,
flatCoordinates,
ends
) {
flatCoordinates.push(0, 0, 3, 0, 3, 3, 3, 0, 0, 0);
flatCoordinates.push(1, 1, 1, 2, 2, 2, 2, 1, 1, 1);
ends.push(10, 20);
@@ -175,18 +190,23 @@ describe('ol.format.MVT', function() {
expect(geometry).to.be.a(Polygon);
});
it('detects a MultiPolygon', function() {
it('detects a MultiPolygon', function () {
const format = new MVT({
featureClass: Feature
featureClass: Feature,
});
const rawFeature = {
type: 3,
properties: {},
layer: {
name: 'layer1'
}
name: 'layer1',
},
};
format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) {
format.readRawGeometry_ = function (
{},
rawFeature,
flatCoordinates,
ends
) {
flatCoordinates.push(0, 0, 1, 0, 1, 1, 1, 0, 0, 0);
flatCoordinates.push(1, 1, 2, 1, 2, 2, 2, 1, 1, 1);
ends.push(10, 20);
@@ -196,20 +216,25 @@ describe('ol.format.MVT', function() {
expect(geometry).to.be.a(MultiPolygon);
});
it('creates ol.render.Feature instances', function() {
it('creates ol.render.Feature instances', function () {
const format = new MVT();
const rawFeature = {
type: 3,
properties: {
foo: 'bar'
foo: 'bar',
},
layer: {
name: 'layer1'
}
name: 'layer1',
},
};
let createdFlatCoordinates;
let createdEnds;
format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) {
format.readRawGeometry_ = function (
{},
rawFeature,
flatCoordinates,
ends
) {
flatCoordinates.push(0, 0, 1, 0, 1, 1, 1, 0, 0, 0);
flatCoordinates.push(1, 1, 2, 1, 2, 2, 2, 1, 1, 1);
createdFlatCoordinates = flatCoordinates;
@@ -218,14 +243,16 @@ describe('ol.format.MVT', function() {
};
format.dataProjection.setExtent([0, 0, 4096, 4096]);
format.dataProjection.setWorldExtent(options.extent);
const feature = format.createFeature_({}, rawFeature, format.adaptOptions(options));
const feature = format.createFeature_(
{},
rawFeature,
format.adaptOptions(options)
);
expect(feature).to.be.a(RenderFeature);
expect(feature.getType()).to.be('Polygon');
expect(feature.getFlatCoordinates()).to.equal(createdFlatCoordinates);
expect(feature.getEnds()).to.equal(createdEnds);
expect(feature.get('foo')).to.be('bar');
});
});
});
+72 -72
View File
@@ -1,51 +1,48 @@
import Feature from '../../../../src/ol/Feature.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import OSMXML from '../../../../src/ol/format/OSMXML.js';
import Point from '../../../../src/ol/geom/Point.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
describe('ol.format.OSMXML', function() {
describe('ol.format.OSMXML', function () {
let format;
beforeEach(function() {
beforeEach(function () {
format = new OSMXML();
});
describe('#readProjection', function() {
it('returns the default projection from document', function() {
describe('#readProjection', function () {
it('returns the default projection from document', function () {
const projection = format.readProjectionFromDocument();
expect(projection).to.eql(getProjection('EPSG:4326'));
});
it('returns the default projection from node', function() {
it('returns the default projection from node', function () {
const projection = format.readProjectionFromNode();
expect(projection).to.eql(getProjection('EPSG:4326'));
});
});
describe('#readFeatures', function() {
it('can read an empty document', function() {
describe('#readFeatures', function () {
it('can read an empty document', function () {
const text =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
'</osm>';
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
'</osm>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(0);
});
it('can read nodes', function() {
it('can read nodes', function () {
const text =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
'</osm>';
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
'</osm>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(2);
const f = fs[0];
@@ -55,22 +52,22 @@ describe('ol.format.OSMXML', function() {
expect(g.getCoordinates()).to.eql([2, 1]);
});
it('can read nodes and ways', function() {
it('can read nodes and ways', function () {
const text =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
' <way id="3">' +
' <tag k="name" v="3"/>' +
' <nd ref="1" />' +
' <nd ref="2" />' +
' </way>' +
'</osm>';
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
' <way id="3">' +
' <tag k="name" v="3"/>' +
' <nd ref="1" />' +
' <nd ref="2" />' +
' </way>' +
'</osm>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(3);
const point = fs[0];
@@ -82,49 +79,53 @@ describe('ol.format.OSMXML', function() {
expect(line).to.be.an(Feature);
g = line.getGeometry();
expect(g).to.be.an(LineString);
expect(g.getCoordinates()).to.eql([[2, 1], [4, 3]]);
expect(g.getCoordinates()).to.eql([
[2, 1],
[4, 3],
]);
});
it('can read ways before nodes', function() {
it('can read ways before nodes', function () {
const text =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <way id="3">' +
' <tag k="name" v="3"/>' +
' <nd ref="1" />' +
' <nd ref="2" />' +
' </way>' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
'</osm>';
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <way id="3">' +
' <tag k="name" v="3"/>' +
' <nd ref="1" />' +
' <nd ref="2" />' +
' </way>' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
'</osm>';
const fs = format.readFeatures(text);
expect(fs).to.have.length(3);
const line = fs[2];
expect(line).to.be.an(Feature);
const g = line.getGeometry();
expect(g).to.be.an(LineString);
expect(g.getCoordinates()).to.eql([[2, 1], [4, 3]]);
expect(g.getCoordinates()).to.eql([
[2, 1],
[4, 3],
]);
});
it('can transform and read nodes', function() {
it('can transform and read nodes', function () {
const text =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
'</osm>';
'<?xml version="1.0" encoding="UTF-8"?>' +
'<osm version="0.6" generator="my hand">' +
' <node id="1" lat="1" lon="2">' +
' <tag k="name" v="1"/>' +
' </node>' +
' <node id="2" lat="3" lon="4">' +
' <tag k="name" v="2"/>' +
' </node>' +
'</osm>';
const fs = format.readFeatures(text, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(fs).to.have.length(2);
const f = fs[0];
@@ -132,9 +133,8 @@ describe('ol.format.OSMXML', function() {
const g = f.getGeometry();
expect(g).to.be.an(Point);
expect(g.getCoordinates()).to.eql(
transform([2, 1], 'EPSG:4326', 'EPSG:3857'));
transform([2, 1], 'EPSG:4326', 'EPSG:3857')
);
});
});
});
+79 -82
View File
@@ -1,45 +1,43 @@
import OWS from '../../../../src/ol/format/OWS.js';
import {parse} from '../../../../src/ol/xml.js';
describe('ol.format.OWS 1.1', function() {
describe('ol.format.OWS 1.1', function () {
const parser = new OWS();
it('should read ServiceProvider tag properly', function() {
it('should read ServiceProvider tag properly', function () {
const doc = parse(
'<ows:GetCapabilities xmlns:ows="http://www.opengis.net/ows/1.1" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink" >' +
'<ows:ServiceProvider>' +
'<ows:ProviderName>MiraMon</ows:ProviderName>' +
'<ows:ProviderSite ' +
'xlink:href="http://www.creaf.uab.es/miramon"/>' +
'<ows:ServiceContact>' +
'<ows:IndividualName>Joan Maso Pau' +
'</ows:IndividualName>' +
'<ows:PositionName>Senior Software Engineer' +
'</ows:PositionName>' +
'<ows:ContactInfo>' +
'<ows:Phone>' +
'<ows:Voice>+34 93 581 1312</ows:Voice>' +
'<ows:Facsimile>+34 93 581 4151' +
'</ows:Facsimile>' +
'</ows:Phone>' +
'<ows:Address>' +
'<ows:DeliveryPoint>Fac Ciencies UAB' +
'</ows:DeliveryPoint>' +
'<ows:City>Bellaterra</ows:City>' +
'<ows:AdministrativeArea>Barcelona' +
'</ows:AdministrativeArea>' +
'<ows:PostalCode>08193</ows:PostalCode>' +
'<ows:Country>Spain</ows:Country>' +
'<ows:ElectronicMailAddress>joan.maso@uab.es' +
'</ows:ElectronicMailAddress>' +
'</ows:Address>' +
'</ows:ContactInfo>' +
'</ows:ServiceContact>' +
'</ows:ServiceProvider>' +
'</ows:GetCapabilities>'
'<ows:ProviderSite ' +
'xlink:href="http://www.creaf.uab.es/miramon"/>' +
'<ows:ServiceContact>' +
'<ows:IndividualName>Joan Maso Pau' +
'</ows:IndividualName>' +
'<ows:PositionName>Senior Software Engineer' +
'</ows:PositionName>' +
'<ows:ContactInfo>' +
'<ows:Phone>' +
'<ows:Voice>+34 93 581 1312</ows:Voice>' +
'<ows:Facsimile>+34 93 581 4151' +
'</ows:Facsimile>' +
'</ows:Phone>' +
'<ows:Address>' +
'<ows:DeliveryPoint>Fac Ciencies UAB' +
'</ows:DeliveryPoint>' +
'<ows:City>Bellaterra</ows:City>' +
'<ows:AdministrativeArea>Barcelona' +
'</ows:AdministrativeArea>' +
'<ows:PostalCode>08193</ows:PostalCode>' +
'<ows:Country>Spain</ows:Country>' +
'<ows:ElectronicMailAddress>joan.maso@uab.es' +
'</ows:ElectronicMailAddress>' +
'</ows:Address>' +
'</ows:ContactInfo>' +
'</ows:ServiceContact>' +
'</ows:ServiceProvider>' +
'</ows:GetCapabilities>'
);
const obj = parser.read(doc);
@@ -55,23 +53,23 @@ describe('ol.format.OWS 1.1', function() {
expect(serviceProvider.ServiceContact.PositionName).to.eql(position);
});
it('should read ServiceIdentification tag properly', function() {
it('should read ServiceIdentification tag properly', function () {
const doc = parse(
'<ows:GetCapabilities xmlns:ows="http://www.opengis.net/ows/1.1" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink" >' +
'<ows:ServiceIdentification>' +
'<ows:Title>Web Map Tile Service</ows:Title>' +
'<ows:Abstract>Service that contrains the map access interface ' +
'to some TileMatrixSets</ows:Abstract>' +
'<ows:Keywords>' +
'<ows:Keyword>tile</ows:Keyword>' +
'<ows:Keyword>tile matrix set</ows:Keyword>' +
'<ows:Keyword>map</ows:Keyword>' +
'</ows:Keywords>' +
'<ows:ServiceType>OGC WMTS</ows:ServiceType>' +
'<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>' +
'<ows:Fees>none</ows:Fees>' +
'<ows:AccessConstraints>none</ows:AccessConstraints>' +
'<ows:Title>Web Map Tile Service</ows:Title>' +
'<ows:Abstract>Service that contrains the map access interface ' +
'to some TileMatrixSets</ows:Abstract>' +
'<ows:Keywords>' +
'<ows:Keyword>tile</ows:Keyword>' +
'<ows:Keyword>tile matrix set</ows:Keyword>' +
'<ows:Keyword>map</ows:Keyword>' +
'</ows:Keywords>' +
'<ows:ServiceType>OGC WMTS</ows:ServiceType>' +
'<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>' +
'<ows:Fees>none</ows:Fees>' +
'<ows:AccessConstraints>none</ows:AccessConstraints>' +
'</ows:ServiceIdentification>' +
'</ows:GetCapabilities>'
);
@@ -90,46 +88,46 @@ describe('ol.format.OWS 1.1', function() {
expect(serviceIdentification.ServiceType).to.eql('OGC WMTS');
});
it('should read OperationsMetadata tag properly', function() {
it('should read OperationsMetadata tag properly', function () {
const doc = parse(
'<ows:GetCapabilities xmlns:ows="http://www.opengis.net/ows/1.1" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink" >' +
'<ows:OperationsMetadata>' +
'<ows:Operation name="GetCapabilities">' +
'<ows:DCP>' +
'<ows:HTTP>' +
'<ows:Get xlink:href=' +
'"http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?">' +
'<ows:Constraint name="GetEncoding">' +
'<ows:AllowedValues>' +
'<ows:Value>KVP</ows:Value>' +
'<ows:Value>SOAP</ows:Value>' +
'</ows:AllowedValues>' +
'</ows:Constraint>' +
'</ows:Get>' +
'</ows:HTTP>' +
'</ows:DCP>' +
'</ows:Operation>' +
'<ows:Operation name="GetTile">' +
'<ows:DCP>' +
'<ows:HTTP>' +
'<ows:Get xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon5_0.cgi?"/>' +
'<ows:Get xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon6_0.cgi?"/>' +
'<ows:Post xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon7_0.cgi?"/>' +
'</ows:HTTP>' +
'</ows:DCP>' +
'</ows:Operation>' +
'<ows:Operation name="GetFeatureInfo">' +
'<ows:DCP>' +
'<ows:HTTP>' +
'<ows:Get xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon5_0.cgi?"/>' +
'</ows:HTTP>' +
'</ows:DCP>' +
'</ows:Operation>' +
'<ows:Operation name="GetCapabilities">' +
'<ows:DCP>' +
'<ows:HTTP>' +
'<ows:Get xlink:href=' +
'"http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?">' +
'<ows:Constraint name="GetEncoding">' +
'<ows:AllowedValues>' +
'<ows:Value>KVP</ows:Value>' +
'<ows:Value>SOAP</ows:Value>' +
'</ows:AllowedValues>' +
'</ows:Constraint>' +
'</ows:Get>' +
'</ows:HTTP>' +
'</ows:DCP>' +
'</ows:Operation>' +
'<ows:Operation name="GetTile">' +
'<ows:DCP>' +
'<ows:HTTP>' +
'<ows:Get xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon5_0.cgi?"/>' +
'<ows:Get xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon6_0.cgi?"/>' +
'<ows:Post xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon7_0.cgi?"/>' +
'</ows:HTTP>' +
'</ows:DCP>' +
'</ows:Operation>' +
'<ows:Operation name="GetFeatureInfo">' +
'<ows:DCP>' +
'<ows:HTTP>' +
'<ows:Get xlink:href="http://www.miramon.uab.es/cgi-' +
'bin/MiraMon5_0.cgi?"/>' +
'</ows:HTTP>' +
'</ows:DCP>' +
'</ows:Operation>' +
'</ows:OperationsMetadata>' +
'</ows:GetCapabilities>'
);
@@ -155,5 +153,4 @@ describe('ol.format.OWS 1.1', function() {
expect(dcp.HTTP.Get[0].href).to.eql(url);
expect(dcp.HTTP.Get[0].Constraint).to.be(undefined);
});
});
+107 -128
View File
@@ -1,10 +1,9 @@
import Feature from '../../../../src/ol/Feature.js';
import Polyline, * as polyline from '../../../../src/ol/format/Polyline.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Polyline, * as polyline from '../../../../src/ol/format/Polyline.js';
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
describe('ol.format.Polyline', function() {
describe('ol.format.Polyline', function () {
let format;
let points;
let flatPoints, encodedFlatPoints, flippedFlatPoints;
@@ -16,29 +15,21 @@ describe('ol.format.Polyline', function() {
function resetTestingData() {
format = new Polyline();
points = [
[-120.20000, 38.50000],
[-120.95000, 40.70000],
[-126.45300, 43.25200]
];
flatPoints = [
-120.20000, 38.50000,
-120.95000, 40.70000,
-126.45300, 43.25200
];
flippedFlatPoints = [
38.50000, -120.20000,
40.70000, -120.95000,
43.25200, -126.45300
[-120.2, 38.5],
[-120.95, 40.7],
[-126.453, 43.252],
];
flatPoints = [-120.2, 38.5, -120.95, 40.7, -126.453, 43.252];
flippedFlatPoints = [38.5, -120.2, 40.7, -120.95, 43.252, -126.453];
encodedFlatPoints = '_p~iF~ps|U_ulLnnqC_mqNvxq`@';
points3857 = [
transform([-120.20000, 38.50000], 'EPSG:4326', 'EPSG:3857'),
transform([-120.95000, 40.70000], 'EPSG:4326', 'EPSG:3857'),
transform([-126.45300, 43.25200], 'EPSG:4326', 'EPSG:3857')
transform([-120.2, 38.5], 'EPSG:4326', 'EPSG:3857'),
transform([-120.95, 40.7], 'EPSG:4326', 'EPSG:3857'),
transform([-126.453, 43.252], 'EPSG:4326', 'EPSG:3857'),
];
floats = [0.00, 0.15, -0.01, -0.16, 0.16, 0.01];
smallFloats = [0.00000, 0.00015, -0.00001, -0.00016, 0.00016, 0.00001];
floats = [0.0, 0.15, -0.01, -0.16, 0.16, 0.01];
smallFloats = [0.0, 0.00015, -0.00001, -0.00016, 0.00016, 0.00001];
encodedFloats = '?]@^_@A';
signedIntegers = [0, 15, -1, -16, 16, 1];
@@ -51,32 +42,31 @@ describe('ol.format.Polyline', function() {
// Reset testing data
beforeEach(resetTestingData);
describe('#readProjectionFromText', function() {
it('returns the default projection', function() {
describe('#readProjectionFromText', function () {
it('returns the default projection', function () {
const projection = format.readProjectionFromText(encodedFlatPoints);
expect(projection).to.eql(getProjection('EPSG:4326'));
});
});
describe('encodeDeltas', function() {
it('returns expected value', function() {
describe('encodeDeltas', function () {
it('returns expected value', function () {
const encodeDeltas = polyline.encodeDeltas;
expect(encodeDeltas(flippedFlatPoints, 2)).to.eql(encodedFlatPoints);
});
});
describe('decodeDeltas', function() {
it('returns expected value', function() {
describe('decodeDeltas', function () {
it('returns expected value', function () {
const decodeDeltas = polyline.decodeDeltas;
expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flippedFlatPoints);
});
});
describe('encodeFloats', function() {
it('returns expected value', function() {
describe('encodeFloats', function () {
it('returns expected value', function () {
const encodeFloats = polyline.encodeFloats;
expect(encodeFloats(smallFloats)).to.eql(encodedFloats);
@@ -88,8 +78,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('decodeFloats', function() {
it('returns expected value', function() {
describe('decodeFloats', function () {
it('returns expected value', function () {
const decodeFloats = polyline.decodeFloats;
expect(decodeFloats(encodedFloats)).to.eql(smallFloats);
@@ -98,50 +88,51 @@ describe('ol.format.Polyline', function() {
});
});
describe('encodeSignedIntegers', function() {
it('returns expected value', function() {
describe('encodeSignedIntegers', function () {
it('returns expected value', function () {
const encodeSignedIntegers = polyline.encodeSignedIntegers;
expect(encodeSignedIntegers(
signedIntegers)).to.eql(encodedSignedIntegers);
expect(encodeSignedIntegers(signedIntegers)).to.eql(
encodedSignedIntegers
);
});
});
describe('decodeSignedIntegers', function() {
it('returns expected value', function() {
describe('decodeSignedIntegers', function () {
it('returns expected value', function () {
const decodeSignedIntegers = polyline.decodeSignedIntegers;
expect(decodeSignedIntegers(
encodedSignedIntegers)).to.eql(signedIntegers);
expect(decodeSignedIntegers(encodedSignedIntegers)).to.eql(
signedIntegers
);
});
});
describe('encodeUnsignedIntegers', function() {
it('returns expected value', function() {
describe('encodeUnsignedIntegers', function () {
it('returns expected value', function () {
const encodeUnsignedIntegers = polyline.encodeUnsignedIntegers;
expect(encodeUnsignedIntegers(
unsignedIntegers)).to.eql(encodedUnsignedIntegers);
expect(encodeUnsignedIntegers(unsignedIntegers)).to.eql(
encodedUnsignedIntegers
);
});
});
describe('decodeUnsignedIntegers', function() {
it('returns expected value', function() {
describe('decodeUnsignedIntegers', function () {
it('returns expected value', function () {
const decodeUnsignedIntegers = polyline.decodeUnsignedIntegers;
expect(decodeUnsignedIntegers(
encodedUnsignedIntegers)).to.eql(unsignedIntegers);
expect(decodeUnsignedIntegers(encodedUnsignedIntegers)).to.eql(
unsignedIntegers
);
});
});
describe('encodeFloat', function() {
it('returns expected value', function() {
describe('encodeFloat', function () {
it('returns expected value', function () {
const encodeFloats = polyline.encodeFloats;
expect(encodeFloats([0.00000])).to.eql('?');
expect(encodeFloats([0.0])).to.eql('?');
expect(encodeFloats([-0.00001])).to.eql('@');
expect(encodeFloats([0.00001])).to.eql('A');
expect(encodeFloats([-0.00002])).to.eql('B');
@@ -152,19 +143,19 @@ describe('ol.format.Polyline', function() {
expect(encodeFloats([-0.1], 10)).to.eql('@');
expect(encodeFloats([0.1], 10)).to.eql('A');
expect(encodeFloats([16 * 32 / 1e5])).to.eql('__@');
expect(encodeFloats([16 * 32 * 32 / 1e5])).to.eql('___@');
expect(encodeFloats([(16 * 32) / 1e5])).to.eql('__@');
expect(encodeFloats([(16 * 32 * 32) / 1e5])).to.eql('___@');
// from the "Encoded Polyline Algorithm Format" page at Google
expect(encodeFloats([-179.9832104])).to.eql('`~oia@');
});
});
describe('decodeFloat', function() {
it('returns expected value', function() {
describe('decodeFloat', function () {
it('returns expected value', function () {
const decodeFloats = polyline.decodeFloats;
expect(decodeFloats('?')).to.eql([0.00000]);
expect(decodeFloats('?')).to.eql([0.0]);
expect(decodeFloats('@')).to.eql([-0.00001]);
expect(decodeFloats('A')).to.eql([0.00001]);
expect(decodeFloats('B')).to.eql([-0.00002]);
@@ -175,17 +166,16 @@ describe('ol.format.Polyline', function() {
expect(decodeFloats('@', 10)).to.eql([-0.1]);
expect(decodeFloats('A', 10)).to.eql([0.1]);
expect(decodeFloats('__@')).to.eql([16 * 32 / 1e5]);
expect(decodeFloats('___@')).to.eql([16 * 32 * 32 / 1e5]);
expect(decodeFloats('__@')).to.eql([(16 * 32) / 1e5]);
expect(decodeFloats('___@')).to.eql([(16 * 32 * 32) / 1e5]);
// from the "Encoded Polyline Algorithm Format" page at Google
expect(decodeFloats('`~oia@')).to.eql([-179.98321]);
});
});
describe('encodeSignedInteger', function() {
it('returns expected value', function() {
describe('encodeSignedInteger', function () {
it('returns expected value', function () {
const encodeSignedIntegers = polyline.encodeSignedIntegers;
expect(encodeSignedIntegers([0])).to.eql('?');
@@ -202,8 +192,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('decodeSignedInteger', function() {
it('returns expected value', function() {
describe('decodeSignedInteger', function () {
it('returns expected value', function () {
const decodeSignedIntegers = polyline.decodeSignedIntegers;
expect(decodeSignedIntegers('?')).to.eql([0]);
@@ -220,9 +210,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('encodeUnsignedInteger', function() {
it('returns expected value', function() {
describe('encodeUnsignedInteger', function () {
it('returns expected value', function () {
const encodeUnsignedInteger = polyline.encodeUnsignedInteger;
expect(encodeUnsignedInteger(0)).to.eql('?');
@@ -241,8 +230,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('decodeUnsignedInteger', function() {
it('returns expected value', function() {
describe('decodeUnsignedInteger', function () {
it('returns expected value', function () {
const decodeUnsignedIntegers = polyline.decodeUnsignedIntegers;
expect(decodeUnsignedIntegers('?')).to.eql([0]);
@@ -261,9 +250,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('#readFeature', function() {
it('returns the expected feature', function() {
describe('#readFeature', function () {
it('returns the expected feature', function () {
const feature = format.readFeature(encodedFlatPoints);
expect(feature).to.be.an(Feature);
const geometry = feature.getGeometry();
@@ -271,21 +259,19 @@ describe('ol.format.Polyline', function() {
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
it('transforms and returns the expected feature', function() {
it('transforms and returns the expected feature', function () {
const feature = format.readFeature(encodedFlatPoints, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(feature).to.be.an(Feature);
const geometry = feature.getGeometry();
expect(geometry).to.be.an(LineString);
expect(geometry.getCoordinates()).to.eql(points3857);
});
});
describe('#readFeatures', function() {
it('returns the expected feature', function() {
describe('#readFeatures', function () {
it('returns the expected feature', function () {
const features = format.readFeatures(encodedFlatPoints);
expect(features).to.be.an(Array);
expect(features).to.have.length(1);
@@ -296,9 +282,9 @@ describe('ol.format.Polyline', function() {
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
it('transforms and returns the expected features', function() {
it('transforms and returns the expected features', function () {
const features = format.readFeatures(encodedFlatPoints, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(features).to.be.an(Array);
expect(features).to.have.length(1);
@@ -308,101 +294,94 @@ describe('ol.format.Polyline', function() {
expect(geometry).to.be.an(LineString);
expect(geometry.getCoordinates()).to.eql(points3857);
});
});
describe('#readGeometry', function() {
it('returns the expected geometry', function() {
describe('#readGeometry', function () {
it('returns the expected geometry', function () {
const geometry = format.readGeometry(encodedFlatPoints);
expect(geometry).to.be.an(LineString);
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
it('parses XYZ linestring', function() {
const xyz = polyline.encodeDeltas([
38.500, -120.200, 100,
40.700, -120.950, 200,
43.252, -126.453, 20
], 3);
it('parses XYZ linestring', function () {
const xyz = polyline.encodeDeltas(
[38.5, -120.2, 100, 40.7, -120.95, 200, 43.252, -126.453, 20],
3
);
const format = new Polyline({
geometryLayout: 'XYZ'
geometryLayout: 'XYZ',
});
const geometry = format.readGeometry(xyz);
expect(geometry.getLayout()).to.eql('XYZ');
expect(geometry.getCoordinates()).to.eql([
[-120.200, 38.500, 100],
[-120.950, 40.700, 200],
[-126.453, 43.252, 20]
[-120.2, 38.5, 100],
[-120.95, 40.7, 200],
[-126.453, 43.252, 20],
]);
});
it('transforms and returns the expected geometry', function() {
it('transforms and returns the expected geometry', function () {
const geometry = format.readGeometry(encodedFlatPoints, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(geometry).to.be.an(LineString);
expect(geometry.getCoordinates()).to.eql(points3857);
});
});
describe('#readProjection', function() {
it('returns the expected projection', function() {
describe('#readProjection', function () {
it('returns the expected projection', function () {
const projection = format.readProjection(encodedFlatPoints);
expect(projection).to.be(getProjection('EPSG:4326'));
});
});
describe('#writeFeature', function() {
it('returns the expected text', function() {
describe('#writeFeature', function () {
it('returns the expected text', function () {
const feature = new Feature(new LineString(points));
expect(format.writeFeature(feature)).to.be(encodedFlatPoints);
});
it('transforms and returns the expected text', function() {
it('transforms and returns the expected text', function () {
const feature = new Feature(new LineString(points3857));
expect(format.writeFeature(feature, {
featureProjection: 'EPSG:3857'
})).to.be(encodedFlatPoints);
expect(
format.writeFeature(feature, {
featureProjection: 'EPSG:3857',
})
).to.be(encodedFlatPoints);
});
});
describe('#writeFeature', function() {
it('returns the expected text', function() {
describe('#writeFeature', function () {
it('returns the expected text', function () {
const features = [new Feature(new LineString(points))];
expect(format.writeFeatures(features)).to.be(encodedFlatPoints);
});
it('transforms and returns the expected text', function() {
it('transforms and returns the expected text', function () {
const features = [new Feature(new LineString(points3857))];
expect(format.writeFeatures(features, {
featureProjection: 'EPSG:3857'
})).to.be(encodedFlatPoints);
expect(
format.writeFeatures(features, {
featureProjection: 'EPSG:3857',
})
).to.be(encodedFlatPoints);
});
});
describe('#writeGeometry', function() {
it('returns the expected text', function() {
describe('#writeGeometry', function () {
it('returns the expected text', function () {
const geometry = new LineString(points);
expect(format.writeGeometry(geometry)).to.be(encodedFlatPoints);
});
it('transforms and returns the expected text', function() {
it('transforms and returns the expected text', function () {
const geometry = new LineString(points3857);
expect(format.writeGeometry(geometry, {
featureProjection: 'EPSG:3857'
})).to.be(encodedFlatPoints);
expect(
format.writeGeometry(geometry, {
featureProjection: 'EPSG:3857',
})
).to.be(encodedFlatPoints);
});
});
});
+87 -57
View File
@@ -1,30 +1,40 @@
import Feature from '../../../../src/ol/Feature.js';
import FeatureFormat from '../../../../src/ol/format/Feature.js';
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
import FeatureFormat from '../../../../src/ol/format/Feature.js';
import {transform} from '../../../../src/ol/proj.js';
import TopoJSON from '../../../../src/ol/format/TopoJSON.js';
import {transform} from '../../../../src/ol/proj.js';
const aruba = {
type: 'Topology',
transform: {
scale: [0.036003600360036005, 0.017361589674592462],
translate: [-180, -89.99892578124998]
translate: [-180, -89.99892578124998],
},
objects: {
aruba: {
type: 'Polygon',
properties: {
prop0: 'value0'
prop0: 'value0',
},
arcs: [[0]],
id: 533
}
id: 533,
},
},
arcs: [
[[3058, 5901], [0, -2], [-2, 1], [-1, 3], [-2, 3], [0, 3], [1, 1], [1, -3],
[2, -5], [1, -1]]
]
[
[3058, 5901],
[0, -2],
[-2, 1],
[-1, 3],
[-2, 3],
[0, 3],
[1, 1],
[1, -3],
[2, -5],
[1, -1],
],
],
};
const zeroId = {
@@ -33,28 +43,26 @@ const zeroId = {
foobar: {
type: 'Point',
id: 0,
coordinates: [0, 42]
}
}
coordinates: [0, 42],
},
},
};
describe('ol.format.TopoJSON', function() {
describe('ol.format.TopoJSON', function () {
let format;
before(function() {
before(function () {
format = new TopoJSON();
});
describe('constructor', function() {
it('creates a new format', function() {
describe('constructor', function () {
it('creates a new format', function () {
expect(format).to.be.a(FeatureFormat);
expect(format).to.be.a(TopoJSON);
});
});
describe('#readFeaturesFromTopology_()', function() {
it('creates an array of features from a topology', function() {
describe('#readFeaturesFromTopology_()', function () {
it('creates an array of features from a topology', function () {
const features = format.readFeaturesFromObject(aruba);
expect(features).to.have.length(1);
@@ -70,12 +78,14 @@ describe('ol.format.TopoJSON', function() {
expect(feature.get('prop0')).to.be('value0');
expect(geometry.getExtent()).to.eql([
-70.08100810081008, 12.417091709170947,
-69.9009900990099, 12.608069195591469
-70.08100810081008,
12.417091709170947,
-69.9009900990099,
12.608069195591469,
]);
});
it('can read a feature with id equal to 0', function() {
it('can read a feature with id equal to 0', function () {
const features = format.readFeaturesFromObject(zeroId);
expect(features).to.have.length(1);
@@ -83,13 +93,11 @@ describe('ol.format.TopoJSON', function() {
expect(feature).to.be.a(Feature);
expect(feature.getId()).to.be(0);
});
});
describe('#readFeatures()', function() {
it('parses simple.json', function(done) {
afterLoadText('spec/ol/format/topojson/simple.json', function(text) {
describe('#readFeatures()', function () {
it('parses simple.json', function (done) {
afterLoadText('spec/ol/format/topojson/simple.json', function (text) {
const features = format.readFeatures(text);
expect(features.length).to.be(3);
@@ -100,30 +108,47 @@ describe('ol.format.TopoJSON', function() {
const line = features[1].getGeometry();
expect(line.getType()).to.be('LineString');
expect(line.getFlatCoordinates()).to.eql([
102, 0, 103, 1, 104, 0, 105, 1
102,
0,
103,
1,
104,
0,
105,
1,
]);
const polygon = features[2].getGeometry();
expect(polygon.getType()).to.be('Polygon');
expect(polygon.getFlatCoordinates()).to.eql([
100, 0, 100, 1, 101, 1, 101, 0, 100, 0
100,
0,
100,
1,
101,
1,
101,
0,
100,
0,
]);
done();
});
});
it('parses simple.json and transforms', function(done) {
afterLoadText('spec/ol/format/topojson/simple.json', function(text) {
it('parses simple.json and transforms', function (done) {
afterLoadText('spec/ol/format/topojson/simple.json', function (text) {
const features = format.readFeatures(text, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(features.length).to.be(3);
const point = features[0].getGeometry();
expect(point.getType()).to.be('Point');
expect(features[0].getGeometry().getCoordinates()).to.eql(
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857')
);
const line = features[1].getGeometry();
expect(line.getType()).to.be('LineString');
@@ -131,26 +156,27 @@ describe('ol.format.TopoJSON', function() {
transform([102.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([103.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([104.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([105.0, 1.0], 'EPSG:4326', 'EPSG:3857')
transform([105.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
]);
const polygon = features[2].getGeometry();
expect(polygon.getType()).to.be('Polygon');
expect(polygon.getCoordinates()).to.eql([[
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857')
]]);
expect(polygon.getCoordinates()).to.eql([
[
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
],
]);
done();
});
});
it('parses world-110m.json', function(done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
it('parses world-110m.json', function (done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function (text) {
const features = format.readFeatures(text);
expect(features.length).to.be(178);
@@ -158,26 +184,32 @@ describe('ol.format.TopoJSON', function() {
expect(first).to.be.a(Feature);
const firstGeom = first.getGeometry();
expect(firstGeom).to.be.a(MultiPolygon);
expect(firstGeom.getExtent()).to.eql(
[-180, -85.60903777459777, 180, 83.64513000000002]);
expect(firstGeom.getExtent()).to.eql([
-180,
-85.60903777459777,
180,
83.64513000000002,
]);
const last = features[177];
expect(last).to.be.a(Feature);
const lastGeom = last.getGeometry();
expect(lastGeom).to.be.a(Polygon);
expect(lastGeom.getExtent()).to.eql([
25.26325263252633, -22.271802279310577,
32.848528485284874, -15.50833810039586
25.26325263252633,
-22.271802279310577,
32.848528485284874,
-15.50833810039586,
]);
done();
});
});
it('sets the topology\'s child names as feature property', function(done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
it("sets the topology's child names as feature property", function (done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function (text) {
const format = new TopoJSON({
layerName: 'layer'
layerName: 'layer',
});
const features = format.readFeatures(text);
expect(features[0].get('layer')).to.be('land');
@@ -186,17 +218,15 @@ describe('ol.format.TopoJSON', function() {
});
});
it('only parses features from specified topology\'s children', function(done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
it("only parses features from specified topology's children", function (done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function (text) {
const format = new TopoJSON({
layers: ['land']
layers: ['land'],
});
const features = format.readFeatures(text);
expect(features.length).to.be(1);
done();
});
});
});
});
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+75 -59
View File
@@ -1,13 +1,11 @@
import WMSCapabilities from '../../../../src/ol/format/WMSCapabilities.js';
describe('ol.format.WMSCapabilities', function() {
describe('when parsing ogcsample.xml', function() {
describe('ol.format.WMSCapabilities', function () {
describe('when parsing ogcsample.xml', function () {
const parser = new WMSCapabilities();
let capabilities;
before(function(done) {
afterLoadText('spec/ol/format/wms/ogcsample.xml', function(xml) {
before(function (done) {
afterLoadText('spec/ol/format/wms/ogcsample.xml', function (xml) {
try {
capabilities = parser.read(xml);
} catch (e) {
@@ -17,11 +15,11 @@ describe('ol.format.WMSCapabilities', function() {
});
});
it('can read version', function() {
it('can read version', function () {
expect(capabilities.version).to.eql('1.3.0');
});
it('can read Service section', function() {
it('can read Service section', function () {
// FIXME not all fields are tested
const service = capabilities.Service;
const contact = service.ContactInformation;
@@ -39,17 +37,17 @@ describe('ol.format.WMSCapabilities', function() {
expect(contact.ContactPosition).to.eql('Computer Scientist');
expect(contact.ContactPersonPrimary).to.eql({
ContactPerson: 'Jeff Smith',
ContactOrganization: 'NASA'
ContactOrganization: 'NASA',
});
});
it('can read Capability.Exception', function() {
it('can read Capability.Exception', function () {
const exception = capabilities.Capability.Exception;
expect(exception).to.eql(['XML', 'INIMAGE', 'BLANK']);
});
it('can read Capability.Request.GetCapabilities', function() {
it('can read Capability.Request.GetCapabilities', function () {
const getCapabilities = capabilities.Capability.Request.GetCapabilities;
expect(getCapabilities.Format).to.eql(['text/xml']);
@@ -59,17 +57,20 @@ describe('ol.format.WMSCapabilities', function() {
expect(http.Post.OnlineResource).to.eql('http://hostname/path?');
});
it('can read Capability.Request.GetFeatureInfo', function() {
it('can read Capability.Request.GetFeatureInfo', function () {
const getFeatureInfo = capabilities.Capability.Request.GetFeatureInfo;
expect(getFeatureInfo.Format).to.eql(
['text/xml', 'text/plain', 'text/html']);
expect(getFeatureInfo.Format).to.eql([
'text/xml',
'text/plain',
'text/html',
]);
expect(getFeatureInfo.DCPType.length).to.eql(1);
const http = getFeatureInfo.DCPType[0].HTTP;
expect(http.Get.OnlineResource).to.eql('http://hostname/path?');
});
it('can read Capability.Request.GetMap', function() {
it('can read Capability.Request.GetMap', function () {
const getMap = capabilities.Capability.Request.GetMap;
expect(getMap.Format).to.eql(['image/gif', 'image/png', 'image/jpeg']);
@@ -78,69 +79,84 @@ describe('ol.format.WMSCapabilities', function() {
expect(http.Get.OnlineResource).to.eql('http://hostname/path?');
});
it('can read Capability.Layer', function() {
it('can read Capability.Layer', function () {
const layer = capabilities.Capability.Layer;
expect(layer.Title).to.eql('Acme Corp. Map Server');
expect(layer.Name).to.be(undefined);
expect(layer.CRS).to.eql(['CRS:84']);
expect(layer.AuthorityURL).to.eql([{
name: 'DIF_ID',
OnlineResource: 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html'
}]);
expect(layer.BoundingBox).to.eql([{
crs: 'CRS:84',
extent: [-1, -1, 1, 1],
res: [0, 0]
}]);
expect(layer.AuthorityURL).to.eql([
{
name: 'DIF_ID',
OnlineResource: 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html',
},
]);
expect(layer.BoundingBox).to.eql([
{
crs: 'CRS:84',
extent: [-1, -1, 1, 1],
res: [0, 0],
},
]);
expect(layer.Layer.length).to.eql(4);
expect(layer.Layer[0].Name).to.eql('ROADS_RIVERS');
expect(layer.Layer[0].Title).to.eql('Roads and Rivers');
expect(layer.Layer[0].CRS).to.eql(['EPSG:26986', 'CRS:84']);
expect(layer.Layer[0].Identifier).to.eql(['123456']);
expect(layer.Layer[0].BoundingBox).to.eql([{
crs: 'CRS:84',
extent: [-71.63, 41.75, -70.78, 42.9],
res: [0.01, 0.01]
}, {
crs: 'EPSG:26986',
extent: [189000, 834000, 285000, 962000],
res: [1, 1]
}]);
expect(layer.Layer[0].EX_GeographicBoundingBox).to.eql(
[-71.63, 41.75, -70.78, 42.9]);
expect(layer.Layer[0].Style).to.eql([{
Name: 'USGS',
Title: 'USGS Topo Map Style',
Abstract: 'Features are shown in a style like that used in USGS ' +
'topographic maps.',
StyleSheetURL: {
Format: 'text/xsl',
OnlineResource: 'http://www.university.edu/stylesheets/usgs.xsl'
expect(layer.Layer[0].BoundingBox).to.eql([
{
crs: 'CRS:84',
extent: [-71.63, 41.75, -70.78, 42.9],
res: [0.01, 0.01],
},
LegendURL: [{
Format: 'image/gif',
OnlineResource: 'http://www.university.edu/legends/usgs.gif',
size: [72, 72]
}]
}]);
expect(layer.Layer[0].FeatureListURL).to.eql([{
Format: 'XML',
OnlineResource: 'http://www.university.edu/data/roads_rivers.gml'
}]);
{
crs: 'EPSG:26986',
extent: [189000, 834000, 285000, 962000],
res: [1, 1],
},
]);
expect(layer.Layer[0].EX_GeographicBoundingBox).to.eql([
-71.63,
41.75,
-70.78,
42.9,
]);
expect(layer.Layer[0].Style).to.eql([
{
Name: 'USGS',
Title: 'USGS Topo Map Style',
Abstract:
'Features are shown in a style like that used in USGS ' +
'topographic maps.',
StyleSheetURL: {
Format: 'text/xsl',
OnlineResource: 'http://www.university.edu/stylesheets/usgs.xsl',
},
LegendURL: [
{
Format: 'image/gif',
OnlineResource: 'http://www.university.edu/legends/usgs.gif',
size: [72, 72],
},
],
},
]);
expect(layer.Layer[0].FeatureListURL).to.eql([
{
Format: 'XML',
OnlineResource: 'http://www.university.edu/data/roads_rivers.gml',
},
]);
expect(layer.Layer[0].Attribution).to.eql({
Title: 'State College University',
OnlineResource: 'http://www.university.edu/',
LogoURL: {
Format: 'image/gif',
OnlineResource: 'http://www.university.edu/icons/logo.gif',
size: [100, 100]
}
size: [100, 100],
},
});
});
});
});
+149 -151
View File
@@ -2,35 +2,29 @@ import WMSGetFeatureInfo from '../../../../src/ol/format/WMSGetFeatureInfo.js';
import {addCommon, clearAllProjections} from '../../../../src/ol/proj.js';
import {register} from '../../../../src/ol/proj/proj4.js';
describe('ol.format.WMSGetFeatureInfo', function() {
describe('#getLayers', function() {
it('returns null if layers is undefined', function() {
describe('ol.format.WMSGetFeatureInfo', function () {
describe('#getLayers', function () {
it('returns null if layers is undefined', function () {
const format = new WMSGetFeatureInfo();
expect(format.getLayers()).to.be(null);
});
it('returns the value provided in the layers option', function() {
it('returns the value provided in the layers option', function () {
const format = new WMSGetFeatureInfo({
layers: ['a', 'z']
layers: ['a', 'z'],
});
expect(format.getLayers()).to.eql(['a', 'z']);
});
});
describe('#readFormat', function() {
describe('read Features', function() {
describe('#readFormat', function () {
describe('read Features', function () {
let features;
before(function(done) {
before(function (done) {
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
register(proj4);
afterLoadText('spec/ol/format/wms/getfeatureinfo.xml', function(data) {
afterLoadText('spec/ol/format/wms/getfeatureinfo.xml', function (data) {
try {
features = new WMSGetFeatureInfo().readFeatures(data);
} catch (e) {
@@ -40,64 +34,69 @@ describe('ol.format.WMSGetFeatureInfo', function() {
});
});
after(function() {
after(function () {
delete proj4.defs['urn:x-ogc:def:crs:EPSG:4326'];
clearAllProjections();
addCommon();
});
it('creates 3 features', function() {
it('creates 3 features', function () {
expect(features).to.have.length(3);
});
it('creates a feature for 1071', function() {
it('creates a feature for 1071', function () {
const feature = features[0];
expect(feature.getId()).to.be(undefined);
expect(feature.get('FID')).to.equal('1071');
expect(feature.get('NO_CAMPAGNE')).to.equal('1020050');
});
it('read boundedBy but no geometry', function() {
it('read boundedBy but no geometry', function () {
const feature = features[0];
expect(feature.getGeometry()).to.be(undefined);
expect(feature.get('boundedBy')).to.eql(
[-531138.686422, 5386348.414671, -117252.819653, 6144475.186022]);
expect(feature.get('boundedBy')).to.eql([
-531138.686422,
5386348.414671,
-117252.819653,
6144475.186022,
]);
});
it('read empty response', function() {
it('read empty response', function () {
// read empty response
const text = '<?xml version="1.0" encoding="ISO-8859-1"?>' +
'<msGMLOutput xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
' <AAA64_layer>' +
' </AAA64_layer>' +
'</msGMLOutput>';
const text =
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
'<msGMLOutput xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
' <AAA64_layer>' +
' </AAA64_layer>' +
'</msGMLOutput>';
const features = new WMSGetFeatureInfo().readFeatures(text);
expect(features.length).to.be(0);
});
it('read empty attributes', function() {
it('read empty attributes', function () {
const text =
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
'<msGMLOutput ' +
' xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
' <AAA64_layer>' +
' <AAA64_feature>' +
' <gml:boundedBy>' +
' <gml:Box srsName="EPSG:4326">' +
' <gml:coordinates>' +
' 107397.266000,460681.063000 116568.188000,480609.250000' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <FOO>bar</FOO>' +
' <EMPTY></EMPTY>' +
' </AAA64_feature>' +
' </AAA64_layer>' +
'</msGMLOutput>';
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
'<msGMLOutput ' +
' xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
' <AAA64_layer>' +
' <AAA64_feature>' +
' <gml:boundedBy>' +
' <gml:Box srsName="EPSG:4326">' +
' <gml:coordinates>' +
' 107397.266000,460681.063000 116568.188000,480609.250000' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <FOO>bar</FOO>' +
' <EMPTY></EMPTY>' +
' </AAA64_feature>' +
' </AAA64_layer>' +
'</msGMLOutput>';
const features = new WMSGetFeatureInfo().readFeatures(text);
expect(features.length).to.be(1);
expect(features[0].get('FOO')).to.be('bar');
@@ -105,59 +104,59 @@ describe('ol.format.WMSGetFeatureInfo', function() {
expect(features[0].get('EMPTY')).to.be(undefined);
});
it('read features from multiple layers', function() {
it('read features from multiple layers', function () {
const text =
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
'<msGMLOutput ' +
' xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
' <AAA64_layer>' +
' <AAA64_feature>' +
' <gml:boundedBy>' +
' <gml:Box srsName="EPSG:4326">' +
' <gml:coordinates>' +
' 129799.109000,467950.250000 133199.906000,468904.063000' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <OBJECTID>287</OBJECTID>' +
' <ROUTE>N403</ROUTE>' +
' <ROUTE_CH>#N403</ROUTE_CH>' +
' <COUNT>1</COUNT>' +
' <BEHEERDER>P</BEHEERDER>' +
' <LENGTH>4091.25</LENGTH>' +
' <SHAPE>&lt;shape&gt;</SHAPE>' +
' <SE_ANNO_CAD_DATA>&lt;null&gt;</SE_ANNO_CAD_DATA>' +
' </AAA64_feature>' +
' </AAA64_layer>' +
' <AAA62_layer>' +
' <AAA62_feature>' +
' <gml:boundedBy>' +
' <gml:Box srsName="EPSG:4326">' +
' <gml:coordinates>' +
' 129936.000000,468362.000000 131686.000000,473119.000000' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <OBJECTID>1251</OBJECTID>' +
' <VWK_ID>1515</VWK_ID>' +
' <VWK_BEGDTM>00:00:00 01/01/1998</VWK_BEGDTM>' +
' <VWJ_ID_BEG>1472</VWJ_ID_BEG>' +
' <VWJ_ID_END>1309</VWJ_ID_END>' +
' <VAKTYPE>D</VAKTYPE>' +
' <VRT_CODE>227</VRT_CODE>' +
' <VRT_NAAM>Vecht</VRT_NAAM>' +
' <VWG_NR>2</VWG_NR>' +
' <VWG_NAAM>Vecht</VWG_NAAM>' +
' <BEGKM>18.25</BEGKM>' +
' <ENDKM>23.995</ENDKM>' +
' <LENGTH>5745.09</LENGTH>' +
' <SHAPE>&lt;shape&gt;</SHAPE>' +
' <SE_ANNO_CAD_DATA>&lt;null&gt;</SE_ANNO_CAD_DATA>' +
' </AAA62_feature>' +
' </AAA62_layer>' +
'</msGMLOutput>';
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
'<msGMLOutput ' +
' xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
' <AAA64_layer>' +
' <AAA64_feature>' +
' <gml:boundedBy>' +
' <gml:Box srsName="EPSG:4326">' +
' <gml:coordinates>' +
' 129799.109000,467950.250000 133199.906000,468904.063000' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <OBJECTID>287</OBJECTID>' +
' <ROUTE>N403</ROUTE>' +
' <ROUTE_CH>#N403</ROUTE_CH>' +
' <COUNT>1</COUNT>' +
' <BEHEERDER>P</BEHEERDER>' +
' <LENGTH>4091.25</LENGTH>' +
' <SHAPE>&lt;shape&gt;</SHAPE>' +
' <SE_ANNO_CAD_DATA>&lt;null&gt;</SE_ANNO_CAD_DATA>' +
' </AAA64_feature>' +
' </AAA64_layer>' +
' <AAA62_layer>' +
' <AAA62_feature>' +
' <gml:boundedBy>' +
' <gml:Box srsName="EPSG:4326">' +
' <gml:coordinates>' +
' 129936.000000,468362.000000 131686.000000,473119.000000' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <OBJECTID>1251</OBJECTID>' +
' <VWK_ID>1515</VWK_ID>' +
' <VWK_BEGDTM>00:00:00 01/01/1998</VWK_BEGDTM>' +
' <VWJ_ID_BEG>1472</VWJ_ID_BEG>' +
' <VWJ_ID_END>1309</VWJ_ID_END>' +
' <VAKTYPE>D</VAKTYPE>' +
' <VRT_CODE>227</VRT_CODE>' +
' <VRT_NAAM>Vecht</VRT_NAAM>' +
' <VWG_NR>2</VWG_NR>' +
' <VWG_NAAM>Vecht</VWG_NAAM>' +
' <BEGKM>18.25</BEGKM>' +
' <ENDKM>23.995</ENDKM>' +
' <LENGTH>5745.09</LENGTH>' +
' <SHAPE>&lt;shape&gt;</SHAPE>' +
' <SE_ANNO_CAD_DATA>&lt;null&gt;</SE_ANNO_CAD_DATA>' +
' </AAA62_feature>' +
' </AAA62_layer>' +
'</msGMLOutput>';
const format = new WMSGetFeatureInfo();
const features = format.readFeatures(text);
expect(features.length).to.be(2);
@@ -174,62 +173,61 @@ describe('ol.format.WMSGetFeatureInfo', function() {
expect(dummyFeatures.length).to.be(0);
});
it('read geoservers response', function() {
it('read geoservers response', function () {
const text =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs"' +
' xmlns:wfs="http://www.opengis.net/wfs"' +
' xmlns:opengeo="http://opengeo.org"' +
' xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xsi:schemaLocation="http://opengeo.org ' +
' http://demo.opengeo.org:80/geoserver/wfs?service=WFS&amp;' +
'version=1.0.0&amp;request=DescribeFeatureType&amp;' +
'typeName=opengeo:roads http://www.opengis.net/wfs ' +
' http://demo.opengeo.org:80/geoserver/schemas/wfs/1.0.0/' +
'WFS-basic.xsd">' +
' <gml:boundedBy>' +
' <gml:Box' +
' srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">' +
' <gml:coordinates xmlns:gml="http://www.opengis.net/gml"' +
' decimal="." cs="," ts=" ">' +
'591943.9375,4925605 593045.625,4925845' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <gml:featureMember>' +
' <opengeo:roads fid="roads.90">' +
' <opengeo:cat>3</opengeo:cat>' +
' <opengeo:label>secondary highway, hard surface' +
' </opengeo:label>' +
' <opengeo:the_geom>' +
' <gml:MultiLineString' +
' srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">' +
' <gml:lineStringMember>' +
' <gml:LineString>' +
' <gml:coordinates xmlns:gml="http://www.opengis.net/gml"' +
' decimal="." cs="," ts=" ">' +
'593045.60746465,4925605.0059156 593024.32382915,4925606.79305411' +
' 592907.54863574,4925624.85647524 592687.35111096,' +
'4925670.76834012 592430.76279218,4925678.79393165' +
' 592285.97636109,4925715.70811767 592173.39165655,' +
'4925761.83511156 592071.1753393,4925793.95523514' +
' 591985.96972625,4925831.59842486' +
' 591943.98769455,4925844.93220071' +
' </gml:coordinates>' +
' </gml:LineString>' +
' </gml:lineStringMember>' +
' </gml:MultiLineString>' +
' </opengeo:the_geom>' +
' </opengeo:roads>' +
' </gml:featureMember>' +
'</wfs:FeatureCollection>';
'<?xml version="1.0" encoding="UTF-8"?>' +
'<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs"' +
' xmlns:wfs="http://www.opengis.net/wfs"' +
' xmlns:opengeo="http://opengeo.org"' +
' xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xsi:schemaLocation="http://opengeo.org ' +
' http://demo.opengeo.org:80/geoserver/wfs?service=WFS&amp;' +
'version=1.0.0&amp;request=DescribeFeatureType&amp;' +
'typeName=opengeo:roads http://www.opengis.net/wfs ' +
' http://demo.opengeo.org:80/geoserver/schemas/wfs/1.0.0/' +
'WFS-basic.xsd">' +
' <gml:boundedBy>' +
' <gml:Box' +
' srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">' +
' <gml:coordinates xmlns:gml="http://www.opengis.net/gml"' +
' decimal="." cs="," ts=" ">' +
'591943.9375,4925605 593045.625,4925845' +
' </gml:coordinates>' +
' </gml:Box>' +
' </gml:boundedBy>' +
' <gml:featureMember>' +
' <opengeo:roads fid="roads.90">' +
' <opengeo:cat>3</opengeo:cat>' +
' <opengeo:label>secondary highway, hard surface' +
' </opengeo:label>' +
' <opengeo:the_geom>' +
' <gml:MultiLineString' +
' srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">' +
' <gml:lineStringMember>' +
' <gml:LineString>' +
' <gml:coordinates xmlns:gml="http://www.opengis.net/gml"' +
' decimal="." cs="," ts=" ">' +
'593045.60746465,4925605.0059156 593024.32382915,4925606.79305411' +
' 592907.54863574,4925624.85647524 592687.35111096,' +
'4925670.76834012 592430.76279218,4925678.79393165' +
' 592285.97636109,4925715.70811767 592173.39165655,' +
'4925761.83511156 592071.1753393,4925793.95523514' +
' 591985.96972625,4925831.59842486' +
' 591943.98769455,4925844.93220071' +
' </gml:coordinates>' +
' </gml:LineString>' +
' </gml:lineStringMember>' +
' </gml:MultiLineString>' +
' </opengeo:the_geom>' +
' </opengeo:roads>' +
' </gml:featureMember>' +
'</wfs:FeatureCollection>';
const features = new WMSGetFeatureInfo().readFeatures(text);
expect(features.length).to.be(1);
expect(features[0].get('cat')).to.be('3');
expect(features[0].getGeometry().getType()).to.be('MultiLineString');
});
});
});
});
+65 -56
View File
@@ -1,14 +1,11 @@
import WMTSCapabilities from '../../../../src/ol/format/WMTSCapabilities.js';
describe('ol.format.WMTSCapabilities', function() {
describe('when parsing ogcsample.xml', function() {
describe('ol.format.WMTSCapabilities', function () {
describe('when parsing ogcsample.xml', function () {
const parser = new WMTSCapabilities();
let capabilities;
before(function(done) {
afterLoadText('spec/ol/format/wmts/ogcsample.xml', function(xml) {
before(function (done) {
afterLoadText('spec/ol/format/wmts/ogcsample.xml', function (xml) {
try {
capabilities = parser.read(xml);
} catch (e) {
@@ -18,15 +15,14 @@ describe('ol.format.WMTSCapabilities', function() {
});
});
it('can read Capability.Contents.Layer', function() {
it('can read Capability.Contents.Layer', function () {
expect(capabilities.Contents.Layer).to.be.an('array');
expect(capabilities.Contents.Layer).to.have.length(1);
const layer = capabilities.Contents.Layer[0];
expect(layer.Abstract).to.be
.eql('Blue Marble Next Generation NASA Product');
expect(layer.Abstract).to.be.eql(
'Blue Marble Next Generation NASA Product'
);
expect(layer.Identifier).to.be.eql('BlueMarbleNextGeneration');
expect(layer.Title).to.be.eql('Blue Marble Next Generation');
@@ -48,19 +44,20 @@ describe('ol.format.WMTSCapabilities', function() {
expect(layer.Style[0].Identifier).to.be.eql('DarkBlue');
expect(layer.Style[0].isDefault).to.be(true);
expect(layer.Style[0].Title).to.be.eql('Dark Blue');
expect(layer.Style[0].LegendURL[0].href).to.be
.eql('http://www.miramon.uab.es/wmts/Coastlines/' +
'coastlines_darkBlue.png');
expect(layer.Style[0].LegendURL[0].href).to.be.eql(
'http://www.miramon.uab.es/wmts/Coastlines/' + 'coastlines_darkBlue.png'
);
expect(layer.Style[0].LegendURL[0].format).to.be.eql('image/png');
expect(layer.TileMatrixSetLink).to.be.an('array');
expect(layer.TileMatrixSetLink).to.have.length(3);
expect(layer.TileMatrixSetLink[0].TileMatrixSet).to.be
.eql('BigWorldPixel');
expect(layer.TileMatrixSetLink[1].TileMatrixSet).to.be
.eql('google3857');
expect(layer.TileMatrixSetLink[2].TileMatrixSet).to.be
.eql('google3857subset');
expect(layer.TileMatrixSetLink[0].TileMatrixSet).to.be.eql(
'BigWorldPixel'
);
expect(layer.TileMatrixSetLink[1].TileMatrixSet).to.be.eql('google3857');
expect(layer.TileMatrixSetLink[2].TileMatrixSet).to.be.eql(
'google3857subset'
);
const wgs84Bbox = layer.WGS84BoundingBox;
expect(wgs84Bbox).to.be.an('array');
@@ -72,13 +69,13 @@ describe('ol.format.WMTSCapabilities', function() {
expect(layer.ResourceURL).to.be.an('array');
expect(layer.ResourceURL).to.have.length(2);
expect(layer.ResourceURL[0].format).to.be.eql('image/png');
expect(layer.ResourceURL[0].template).to.be
.eql('http://www.example.com/wmts/coastlines/{TileMatrix}' +
'/{TileRow}/{TileCol}.png');
expect(layer.ResourceURL[0].template).to.be.eql(
'http://www.example.com/wmts/coastlines/{TileMatrix}' +
'/{TileRow}/{TileCol}.png'
);
});
it('Can read Capabilities.Content.TileMatrixSet', function() {
it('Can read Capabilities.Content.TileMatrixSet', function () {
expect(capabilities.Contents.TileMatrixSet).to.be.ok();
const bigWorld = capabilities.Contents.TileMatrixSet[2];
@@ -104,24 +101,19 @@ describe('ol.format.WMTSCapabilities', function() {
expect(bigWorld.TileMatrix[1].TopLeftCorner).to.be.a('array');
expect(bigWorld.TileMatrix[1].TopLeftCorner[0]).to.be.eql(-180);
expect(bigWorld.TileMatrix[1].TopLeftCorner[1]).to.be.eql(84);
});
it('Can read OWS tags', function() {
it('Can read OWS tags', function () {
expect(capabilities.ServiceIdentification).to.be.ok();
expect(capabilities.OperationsMetadata).to.be.ok();
});
});
describe('when parsing ign.xml', function() {
describe('when parsing ign.xml', function () {
const parser = new WMTSCapabilities();
let capabilities;
before(function(done) {
afterLoadText('spec/ol/format/wmts/ign.xml', function(xml) {
before(function (done) {
afterLoadText('spec/ol/format/wmts/ign.xml', function (xml) {
try {
capabilities = parser.read(xml);
} catch (e) {
@@ -131,35 +123,53 @@ describe('ol.format.WMTSCapabilities', function() {
});
});
it('can read Capability.Contents.Layer', function() {
it('can read Capability.Contents.Layer', function () {
expect(capabilities.Contents.Layer).to.be.an('array');
expect(capabilities.Contents.Layer).to.have.length(1);
const layer = capabilities.Contents.Layer[0];
expect(layer.TileMatrixSetLink).to.be.an('array');
expect(layer.TileMatrixSetLink).to.have.length(2);
expect(layer.TileMatrixSetLink[0].TileMatrixSet).to.be.eql('PM');
expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits).to.be.an('array');
expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits).to.have.length(20);
expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].TileMatrix).to.be.eql('0');
expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileRow).to.be.eql(0);
expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileRow).to.be.eql(1);
expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileCol).to.be.eql(0);
expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileCol).to.be.eql(1);
expect(
layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].TileMatrix
).to.be.eql('0');
expect(
layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileRow
).to.be.eql(0);
expect(
layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileRow
).to.be.eql(1);
expect(
layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileCol
).to.be.eql(0);
expect(
layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileCol
).to.be.eql(1);
expect(layer.TileMatrixSetLink[1].TileMatrixSet).to.be.eql('Prefixed');
expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits).to.be.an('array');
expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits).to.have.length(2);
expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].TileMatrix).to.be.eql('Prefixed:0');
expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MinTileRow).to.be.eql(0);
expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MaxTileRow).to.be.eql(1);
expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MinTileCol).to.be.eql(0);
expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MaxTileCol).to.be.eql(1);
expect(
layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].TileMatrix
).to.be.eql('Prefixed:0');
expect(
layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MinTileRow
).to.be.eql(0);
expect(
layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MaxTileRow
).to.be.eql(1);
expect(
layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MinTileCol
).to.be.eql(0);
expect(
layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MaxTileCol
).to.be.eql(1);
});
it('Can read Capabilities.Content.TileMatrixSet', function() {
it('Can read Capabilities.Content.TileMatrixSet', function () {
expect(capabilities.Contents.TileMatrixSet).to.be.ok();
const pm = capabilities.Contents.TileMatrixSet[0];
@@ -170,8 +180,9 @@ describe('ol.format.WMTSCapabilities', function() {
expect(pm.TileMatrix[0].Identifier).to.be.eql('0');
expect(pm.TileMatrix[0].MatrixHeight).to.be.eql(1);
expect(pm.TileMatrix[0].MatrixWidth).to.be.eql(1);
expect(pm.TileMatrix[0].ScaleDenominator)
.to.be.eql(559082264.0287178958533332);
expect(pm.TileMatrix[0].ScaleDenominator).to.be.eql(
559082264.0287178958533332
);
expect(pm.TileMatrix[0].TileWidth).to.be.eql(256);
expect(pm.TileMatrix[0].TileHeight).to.be.eql(256);
expect(pm.TileMatrix[0].TopLeftCorner).to.be.a('array');
@@ -180,16 +191,14 @@ describe('ol.format.WMTSCapabilities', function() {
expect(pm.TileMatrix[1].Identifier).to.be.eql('1');
expect(pm.TileMatrix[1].MatrixHeight).to.be.eql(2);
expect(pm.TileMatrix[1].MatrixWidth).to.be.eql(2);
expect(pm.TileMatrix[1].ScaleDenominator)
.to.be.eql(279541132.0143588959472254);
expect(pm.TileMatrix[1].ScaleDenominator).to.be.eql(
279541132.0143588959472254
);
expect(pm.TileMatrix[1].TileWidth).to.be.eql(256);
expect(pm.TileMatrix[1].TileHeight).to.be.eql(256);
expect(pm.TileMatrix[1].TopLeftCorner).to.be.a('array');
expect(pm.TileMatrix[1].TopLeftCorner[0]).to.be.eql(-20037508);
expect(pm.TileMatrix[1].TopLeftCorner[1]).to.be.eql(20037508);
});
});
});
+6 -7
View File
@@ -1,14 +1,13 @@
import {readDateTime} from '../../../../src/ol/format/xsd.js';
describe('ol/format/xsd', function() {
describe('readDateTime', function() {
it('can handle non-Zulu time zones', function() {
describe('ol/format/xsd', function () {
describe('readDateTime', function () {
it('can handle non-Zulu time zones', function () {
const node = document.createElement('time');
node.textContent = '2016-07-12T15:00:00+03:00';
expect(new Date(readDateTime(node) * 1000).toISOString()).to.eql('2016-07-12T12:00:00.000Z');
expect(new Date(readDateTime(node) * 1000).toISOString()).to.eql(
'2016-07-12T12:00:00.000Z'
);
});
});
});
+6 -9
View File
@@ -1,10 +1,8 @@
import {memoizeOne} from '../../../src/ol/functions.js';
describe('ol/functions', function() {
describe('memoizeOne()', function() {
it('returns the result from the first call when called a second time with the same args', function() {
describe('ol/functions', function () {
describe('memoizeOne()', function () {
it('returns the result from the first call when called a second time with the same args', function () {
const arg1 = {};
const arg2 = {};
const arg3 = {};
@@ -16,7 +14,7 @@ describe('ol/functions', function() {
expect(memoized(arg1, arg2, arg3)).to.be(result);
});
it('returns the result from the first call when called a second time with the same this object', function() {
it('returns the result from the first call when called a second time with the same this object', function () {
const arg1 = {};
const arg2 = {};
const arg3 = {};
@@ -31,7 +29,7 @@ describe('ol/functions', function() {
expect(memoized.call(thisObj, arg1, arg2, arg3)).to.be(result);
});
it('returns a different result when called a second time with the different args', function() {
it('returns a different result when called a second time with the different args', function () {
const arg1 = {};
const arg2 = {};
const arg3 = {};
@@ -43,7 +41,7 @@ describe('ol/functions', function() {
expect(memoized(arg3, arg2, arg1)).not.to.be(result);
});
it('returns a different result when called a second time with a different this object', function() {
it('returns a different result when called a second time with a different this object', function () {
const arg1 = {};
const arg2 = {};
const arg3 = {};
@@ -57,5 +55,4 @@ describe('ol/functions', function() {
expect(memoized.call(secondThis, arg1, arg2, arg3)).not.to.be(result);
});
});
});
+3 -8
View File
@@ -1,15 +1,10 @@
import Geolocation from '../../../src/ol/Geolocation.js';
describe('ol.Geolocation', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.Geolocation', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new Geolocation();
expect(instance).to.be.an(Geolocation);
});
});
});
+65 -100
View File
@@ -1,67 +1,57 @@
import Circle from '../../../../src/ol/geom/Circle.js';
describe('ol.geom.Circle', function() {
describe('with a unit circle', function() {
describe('ol.geom.Circle', function () {
describe('with a unit circle', function () {
let circle;
beforeEach(function() {
beforeEach(function () {
circle = new Circle([0, 0], 1);
});
describe('#clone', function() {
it('returns a clone', function() {
describe('#clone', function () {
it('returns a clone', function () {
const clone = circle.clone();
expect(clone).to.be.an(Circle);
expect(clone.getCenter()).to.eql(circle.getCenter());
expect(clone.getCenter()).not.to.be(circle.getCenter());
expect(clone.getRadius()).to.be(circle.getRadius());
});
});
describe('#intersectsCoordinate', function() {
it('contains the center', function() {
describe('#intersectsCoordinate', function () {
it('contains the center', function () {
expect(circle.intersectsCoordinate([0, 0])).to.be(true);
});
it('contains points inside the perimeter', function() {
it('contains points inside the perimeter', function () {
expect(circle.intersectsCoordinate([0.5, 0.5])).to.be(true);
expect(circle.intersectsCoordinate([-0.5, 0.5])).to.be(true);
expect(circle.intersectsCoordinate([-0.5, -0.5])).to.be(true);
expect(circle.intersectsCoordinate([0.5, -0.5])).to.be(true);
});
it('contains points on the perimeter', function() {
it('contains points on the perimeter', function () {
expect(circle.intersectsCoordinate([1, 0])).to.be(true);
expect(circle.intersectsCoordinate([0, 1])).to.be(true);
expect(circle.intersectsCoordinate([-1, 0])).to.be(true);
expect(circle.intersectsCoordinate([0, -1])).to.be(true);
});
it('does not contain points outside the perimeter', function() {
it('does not contain points outside the perimeter', function () {
expect(circle.intersectsCoordinate([2, 0])).to.be(false);
expect(circle.intersectsCoordinate([1, 1])).to.be(false);
expect(circle.intersectsCoordinate([-2, 0])).to.be(false);
expect(circle.intersectsCoordinate([0, -2])).to.be(false);
});
});
describe('#getCenter', function() {
it('returns the expected value', function() {
describe('#getCenter', function () {
it('returns the expected value', function () {
expect(circle.getCenter()).to.eql([0, 0]);
});
});
describe('#getClosestPoint', function() {
it('returns the closest point on the perimeter', function() {
describe('#getClosestPoint', function () {
it('returns the closest point on the perimeter', function () {
let closestPoint;
closestPoint = circle.getClosestPoint([2, 0]);
expect(closestPoint[0]).to.roughlyEqual(1, 1e-15);
@@ -89,7 +79,7 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[1]).to.roughlyEqual(-Math.sqrt(0.5), 1e-15);
});
it('maintains Z coordinates', function() {
it('maintains Z coordinates', function () {
const circle = new Circle([0, 0, 1], 1);
expect(circle.getLayout()).to.be('XYZ');
const closestPoint = circle.getClosestPoint([2, 0]);
@@ -99,9 +89,8 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[2]).to.be(1);
});
it('maintains M coordinates', function() {
const circle = new Circle([0, 0, 2], 1,
'XYM');
it('maintains M coordinates', function () {
const circle = new Circle([0, 0, 2], 1, 'XYM');
const closestPoint = circle.getClosestPoint([2, 0]);
expect(closestPoint).to.have.length(3);
expect(closestPoint[0]).to.roughlyEqual(1, 1e-15);
@@ -109,7 +98,7 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[2]).to.be(2);
});
it('maintains Z and M coordinates', function() {
it('maintains Z and M coordinates', function () {
const circle = new Circle([0, 0, 1, 2], 1);
expect(circle.getLayout()).to.be('XYZM');
const closestPoint = circle.getClosestPoint([2, 0]);
@@ -119,112 +108,92 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[2]).to.be(1);
expect(closestPoint[3]).to.be(2);
});
});
describe('#getExtent', function() {
it('returns the expected value', function() {
describe('#getExtent', function () {
it('returns the expected value', function () {
expect(circle.getExtent()).to.eql([-1, -1, 1, 1]);
});
});
describe('#getRadius', function() {
it('returns the expected value', function() {
describe('#getRadius', function () {
it('returns the expected value', function () {
expect(circle.getRadius()).to.be(1);
});
});
describe('#getSimplifiedGeometry', function() {
it('returns the same geometry', function() {
describe('#getSimplifiedGeometry', function () {
it('returns the same geometry', function () {
expect(circle.getSimplifiedGeometry(1)).to.be(circle);
});
});
describe('#getType', function() {
it('returns the expected value', function() {
describe('#getType', function () {
it('returns the expected value', function () {
expect(circle.getType()).to.be('Circle');
});
});
describe('#setCenter', function() {
it('sets the center', function() {
describe('#setCenter', function () {
it('sets the center', function () {
circle.setCenter([1, 2]);
expect(circle.getCenter()).to.eql([1, 2]);
});
it('fires a change event', function() {
it('fires a change event', function () {
const spy = sinon.spy();
circle.on('change', spy);
circle.setCenter([1, 2]);
expect(spy.calledOnce).to.be(true);
});
});
describe('#setFlatCoordinates', function() {
it('sets both center and radius', function() {
describe('#setFlatCoordinates', function () {
it('sets both center and radius', function () {
circle.setFlatCoordinates('XY', [1, 2, 4, 2]);
expect(circle.getCenter()).to.eql([1, 2]);
expect(circle.getRadius()).to.be(3);
});
});
describe('#setRadius', function() {
it('sets the radius', function() {
describe('#setRadius', function () {
it('sets the radius', function () {
circle.setRadius(2);
expect(circle.getRadius()).to.be(2);
});
it('fires a change event', function() {
it('fires a change event', function () {
const spy = sinon.spy();
circle.on('change', spy);
circle.setRadius(2);
expect(spy.calledOnce).to.be(true);
});
});
describe('#intersectsExtent', function() {
describe('#intersectsExtent', function () {
it('returns false for non-intersecting extents (wide outside own bbox)', function () {
const wideOutsideLeftTop = [-3, 2, -2, 3];
const wideOutsideRightTop = [2, 2, 3, 3];
const wideOutsideRightBottom = [2, -3, 3, -2];
const wideOutsideLeftBottom = [-3, -3, -2, -2];
expect(circle.intersectsExtent(wideOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(wideOutsideLeftBottom)).to.be(false);
});
it('returns false for non-intersecting extents (wide outside own bbox)',
function() {
const wideOutsideLeftTop = [-3, 2, -2, 3];
const wideOutsideRightTop = [2, 2, 3, 3];
const wideOutsideRightBottom = [2, -3, 3, -2];
const wideOutsideLeftBottom = [-3, -3, -2, -2];
expect(circle.intersectsExtent(wideOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(wideOutsideLeftBottom)).to.be(false);
}
);
it('returns false for non-intersecting extents (inside own bbox)', function () {
const nearOutsideLeftTop = [-1, 0.9, -0.9, 1];
const nearOutsideRightTop = [0.9, 0.9, 1, 1];
const nearOutsideRightBottom = [0.9, -1, 1, -0.9];
const nearOutsideLeftBottom = [-1, -1, -0.9, -0.9];
expect(circle.intersectsExtent(nearOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(nearOutsideLeftBottom)).to.be(false);
});
it('returns false for non-intersecting extents (inside own bbox)',
function() {
const nearOutsideLeftTop = [-1, 0.9, -0.9, 1];
const nearOutsideRightTop = [0.9, 0.9, 1, 1];
const nearOutsideRightBottom = [0.9, -1, 1, -0.9];
const nearOutsideLeftBottom = [-1, -1, -0.9, -0.9];
expect(circle.intersectsExtent(nearOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(nearOutsideLeftBottom)).to.be(false);
}
);
it('returns true for extents that intersect clearly', function() {
it('returns true for extents that intersect clearly', function () {
const intersectingLeftTop = [-1.5, 0.5, -0.5, 1.5];
const intersectingRightTop = [0.5, 0.5, 1.5, 1.5];
const intersectingRightBottom = [0.5, -1.5, 1.5, -0.5];
@@ -235,7 +204,7 @@ describe('ol.geom.Circle', function() {
expect(circle.intersectsExtent(intersectingLeftBottom)).to.be(true);
});
it('returns true for extents that touch the circumference', function() {
it('returns true for extents that touch the circumference', function () {
const touchCircumferenceLeft = [-2, 0, -1, 1];
const touchCircumferenceTop = [0, 1, 1, 2];
const touchCircumferenceRight = [1, -1, 2, 0];
@@ -246,33 +215,31 @@ describe('ol.geom.Circle', function() {
expect(circle.intersectsExtent(touchCircumferenceBottom)).to.be(true);
});
it('returns true for a contained extent', function() {
it('returns true for a contained extent', function () {
const containedExtent = [-0.5, -0.5, 0.5, 0.5];
expect(circle.intersectsExtent(containedExtent)).to.be(true);
});
it('returns true for a covering extent', function() {
it('returns true for a covering extent', function () {
const bigCoveringExtent = [-5, -5, 5, 5];
expect(circle.intersectsExtent(bigCoveringExtent)).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
const circleExtent = circle.getExtent();
expect(circle.intersectsExtent(circleExtent)).to.be(true);
});
});
describe('#rotate', function() {
it('rotates the center around the anchor', function() {
describe('#rotate', function () {
it('rotates the center around the anchor', function () {
circle.setCenter([1, 0]);
circle.rotate(Math.PI / 2, [2, 0]);
expect(circle.getCenter()).to.eql([2, -1]);
expect(circle.getExtent()).to.eql([1, -2, 3, 0]);
});
it('does not change if the anchor equals the center', function() {
it('does not change if the anchor equals the center', function () {
const center = [1, 0];
circle.setCenter(center);
const extent = circle.getExtent();
@@ -282,9 +249,8 @@ describe('ol.geom.Circle', function() {
});
});
describe('#translate', function() {
it('translates the circle', function() {
describe('#translate', function () {
it('translates the circle', function () {
circle.setCenter([1, 1]);
circle.translate(5, 10);
expect(circle.getCenter()).to.eql([6, 11]);
@@ -292,5 +258,4 @@ describe('ol.geom.Circle', function() {
});
});
});
});
+11 -13
View File
@@ -1,29 +1,27 @@
import {linearRing, linearRings} from '../../../../../src/ol/geom/flat/area.js';
describe('ol.geom.flat.area', function() {
describe('ol.geom.flat.area.linearRing', function() {
it('calculates the area of a triangle', function() {
describe('ol.geom.flat.area', function () {
describe('ol.geom.flat.area.linearRing', function () {
it('calculates the area of a triangle', function () {
const area = linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2);
expect(area).to.be(0.5);
});
it('calculates the area of a unit square', function() {
it('calculates the area of a unit square', function () {
const area = linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
expect(area).to.be(1);
});
});
describe('ol.geom.flat.area.linearRings', function() {
it('calculates the area with holes', function() {
describe('ol.geom.flat.area.linearRings', function () {
it('calculates the area with holes', function () {
const area = linearRings(
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], 0, [8, 16], 2);
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2],
0,
[8, 16],
2
);
expect(area).to.be(8);
});
});
});
+50 -21
View File
@@ -1,15 +1,20 @@
import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js';
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js';
describe('ol.geom.flat.center', function() {
describe('ol.geom.flat.center.linearRingss', function() {
it('calculates the center of a square', function() {
const squareMultiPoly = new MultiPolygon([[
[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
]]);
describe('ol.geom.flat.center', function () {
describe('ol.geom.flat.center.linearRingss', function () {
it('calculates the center of a square', function () {
const squareMultiPoly = new MultiPolygon([
[
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
]);
const got = linearRingssCenter(
squareMultiPoly.flatCoordinates,
0,
@@ -19,14 +24,26 @@ describe('ol.geom.flat.center', function() {
expect(got).to.eql([0.5, 0.5]);
});
it('calculates the centers of two squares', function() {
it('calculates the centers of two squares', function () {
const squareMultiPoly = new MultiPolygon([
[
[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
[
[[3, 0], [3, 1], [4, 1], [4, 0], [3, 0]]
]
[
[3, 0],
[3, 1],
[4, 1],
[4, 0],
[3, 0],
],
],
]);
const got = linearRingssCenter(
squareMultiPoly.flatCoordinates,
@@ -37,11 +54,25 @@ describe('ol.geom.flat.center', function() {
expect(got).to.eql([0.5, 0.5, 3.5, 0.5]);
});
it('does not care about holes', function() {
const polywithHole = new MultiPolygon([[
[[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]],
[[1, 1], [1, 4], [4, 4], [4, 1], [1, 1]]
]]);
it('does not care about holes', function () {
const polywithHole = new MultiPolygon([
[
[
[0, 0],
[0, 5],
[5, 5],
[5, 0],
[0, 0],
],
[
[1, 1],
[1, 4],
[4, 4],
[4, 1],
[1, 1],
],
],
]);
const got = linearRingssCenter(
polywithHole.flatCoordinates,
0,
@@ -50,7 +81,5 @@ describe('ol.geom.flat.center', function() {
);
expect(got).to.eql([2.5, 2.5]);
});
});
});
+345 -98
View File
@@ -1,143 +1,390 @@
import {assignClosestPoint, maxSquaredDelta} from '../../../../../src/ol/geom/flat/closest.js';
describe('ol.geom.flat.closest', function() {
describe('with simple data', function() {
import {
assignClosestPoint,
maxSquaredDelta,
} from '../../../../../src/ol/geom/flat/closest.js';
describe('ol.geom.flat.closest', function () {
describe('with simple data', function () {
const flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0];
describe('ol.geom.flat.closest.maxSquaredDelta', function() {
it('returns the expected value in simple cases', function() {
expect(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0)).to.be(9);
describe('ol.geom.flat.closest.maxSquaredDelta', function () {
it('returns the expected value in simple cases', function () {
expect(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
).to.be(9);
});
});
describe('ol.geom.flat.closest.assignClosestPoint', function() {
it('returns the expected value', function() {
const maxDelta = Math.sqrt(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
describe('ol.geom.flat.closest.assignClosestPoint', function () {
it('returns the expected value', function () {
const maxDelta = Math.sqrt(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
);
expect(maxDelta).to.be(3);
const closestPoint = [NaN, NaN];
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).to.be(0);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
0,
0,
closestPoint,
Infinity
)
).to.be(0);
expect(closestPoint).to.eql([0, 0]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 4, 1, closestPoint, Infinity)).to.be(1);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
4,
1,
closestPoint,
Infinity
)
).to.be(1);
expect(closestPoint).to.eql([4, 0]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 5, 2, closestPoint, Infinity)).to.be(4);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
5,
2,
closestPoint,
Infinity
)
).to.be(4);
expect(closestPoint).to.eql([5, 0]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 10, 100, closestPoint, Infinity)).to.be(10000);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
10,
100,
closestPoint,
Infinity
)
).to.be(10000);
expect(closestPoint).to.eql([10, 0]);
});
});
});
describe('with real data', function() {
describe('with real data', function () {
const flatCoordinates = [
224.55, 250.15, 226.91, 244.19, 233.31, 241.45, 234.98, 236.06,
244.21, 232.76, 262.59, 215.31, 267.76, 213.81, 273.57, 201.84,
273.12, 192.16, 277.62, 189.03, 280.36, 181.41, 286.51, 177.74,
292.41, 159.37, 296.91, 155.64, 314.95, 151.37, 319.75, 145.16,
330.33, 137.57, 341.48, 139.96, 369.98, 137.89, 387.39, 142.51,
391.28, 139.39, 409.52, 141.14, 414.82, 139.75, 427.72, 127.30,
439.60, 119.74, 474.93, 107.87, 486.51, 106.75, 489.20, 109.45,
493.79, 108.63, 504.74, 119.66, 512.96, 122.35, 518.63, 120.89,
524.09, 126.88, 529.57, 127.86, 534.21, 140.93, 539.27, 147.24,
567.69, 148.91, 575.25, 157.26, 580.62, 158.15, 601.53, 156.85,
617.74, 159.86, 622.00, 167.04, 629.55, 194.60, 638.90, 195.61,
641.26, 200.81, 651.77, 204.56, 671.55, 222.55, 683.68, 217.45,
695.25, 219.15, 700.64, 217.98, 703.12, 214.36, 712.26, 215.87,
721.49, 212.81, 727.81, 213.36, 729.98, 208.73, 735.32, 208.20,
739.94, 204.77, 769.98, 208.42, 779.60, 216.87, 784.20, 218.16,
800.24, 214.62, 810.53, 219.73, 817.19, 226.82, 820.77, 236.17,
827.23, 236.16, 829.89, 239.89, 851.00, 248.94, 859.88, 255.49,
865.21, 268.53, 857.95, 280.30, 865.48, 291.45, 866.81, 298.66,
864.68, 302.71, 867.79, 306.17, 859.87, 311.37, 860.08, 314.35,
858.29, 314.94, 858.10, 327.60, 854.54, 335.40, 860.92, 343.00,
856.43, 350.15, 851.42, 352.96, 849.84, 359.59, 854.56, 365.53,
849.74, 370.38, 844.09, 371.89, 844.75, 380.44, 841.52, 383.67,
839.57, 390.40, 845.59, 399.05, 848.40, 407.55, 843.71, 411.30,
844.09, 419.88, 839.51, 432.76, 841.33, 441.04, 847.62, 449.22,
847.16, 458.44, 851.38, 462.79, 853.97, 471.15, 866.36, 480.77
224.55,
250.15,
226.91,
244.19,
233.31,
241.45,
234.98,
236.06,
244.21,
232.76,
262.59,
215.31,
267.76,
213.81,
273.57,
201.84,
273.12,
192.16,
277.62,
189.03,
280.36,
181.41,
286.51,
177.74,
292.41,
159.37,
296.91,
155.64,
314.95,
151.37,
319.75,
145.16,
330.33,
137.57,
341.48,
139.96,
369.98,
137.89,
387.39,
142.51,
391.28,
139.39,
409.52,
141.14,
414.82,
139.75,
427.72,
127.3,
439.6,
119.74,
474.93,
107.87,
486.51,
106.75,
489.2,
109.45,
493.79,
108.63,
504.74,
119.66,
512.96,
122.35,
518.63,
120.89,
524.09,
126.88,
529.57,
127.86,
534.21,
140.93,
539.27,
147.24,
567.69,
148.91,
575.25,
157.26,
580.62,
158.15,
601.53,
156.85,
617.74,
159.86,
622.0,
167.04,
629.55,
194.6,
638.9,
195.61,
641.26,
200.81,
651.77,
204.56,
671.55,
222.55,
683.68,
217.45,
695.25,
219.15,
700.64,
217.98,
703.12,
214.36,
712.26,
215.87,
721.49,
212.81,
727.81,
213.36,
729.98,
208.73,
735.32,
208.2,
739.94,
204.77,
769.98,
208.42,
779.6,
216.87,
784.2,
218.16,
800.24,
214.62,
810.53,
219.73,
817.19,
226.82,
820.77,
236.17,
827.23,
236.16,
829.89,
239.89,
851.0,
248.94,
859.88,
255.49,
865.21,
268.53,
857.95,
280.3,
865.48,
291.45,
866.81,
298.66,
864.68,
302.71,
867.79,
306.17,
859.87,
311.37,
860.08,
314.35,
858.29,
314.94,
858.1,
327.6,
854.54,
335.4,
860.92,
343.0,
856.43,
350.15,
851.42,
352.96,
849.84,
359.59,
854.56,
365.53,
849.74,
370.38,
844.09,
371.89,
844.75,
380.44,
841.52,
383.67,
839.57,
390.4,
845.59,
399.05,
848.4,
407.55,
843.71,
411.3,
844.09,
419.88,
839.51,
432.76,
841.33,
441.04,
847.62,
449.22,
847.16,
458.44,
851.38,
462.79,
853.97,
471.15,
866.36,
480.77,
];
describe('ol.geom.closest.maxSquaredDelta', function() {
it('returns the expected value', function() {
expect(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0)).
to.roughlyEqual(1389.1058, 1e-9);
describe('ol.geom.closest.maxSquaredDelta', function () {
it('returns the expected value', function () {
expect(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
).to.roughlyEqual(1389.1058, 1e-9);
});
});
describe('ol.geom.flat.closest.assignClosestPoint', function() {
it('returns the expected value', function() {
const maxDelta = Math.sqrt(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
describe('ol.geom.flat.closest.assignClosestPoint', function () {
it('returns the expected value', function () {
const maxDelta = Math.sqrt(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
);
expect(maxDelta).to.roughlyEqual(Math.sqrt(1389.1058), 1e-9);
const closestPoint = [NaN, NaN];
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).
to.roughlyEqual(110902.405, 1e-9);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
0,
0,
closestPoint,
Infinity
)
).to.roughlyEqual(110902.405, 1e-9);
expect(closestPoint).to.eql([292.41, 159.37]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 500, 500, closestPoint, Infinity)).
to.roughlyEqual(106407.905, 1e-9);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
500,
500,
closestPoint,
Infinity
)
).to.roughlyEqual(106407.905, 1e-9);
expect(closestPoint).to.eql([671.55, 222.55]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 1000, 500, closestPoint, Infinity)).
to.roughlyEqual(18229.4425, 1e-9);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
1000,
500,
closestPoint,
Infinity
)
).to.roughlyEqual(18229.4425, 1e-9);
expect(closestPoint).to.eql([866.36, 480.77]);
});
});
});
describe('with multi-dimensional data', function() {
describe('with multi-dimensional data', function () {
const flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20];
const stride = 4;
describe('ol.geom.flat.closest.assignClosestPoint', function() {
it('interpolates M coordinates', function() {
const maxDelta = Math.sqrt(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, stride, 0));
describe('ol.geom.flat.closest.assignClosestPoint', function () {
it('interpolates M coordinates', function () {
const maxDelta = Math.sqrt(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, stride, 0)
);
expect(maxDelta).to.roughlyEqual(Math.sqrt(8), 1e-9);
const closestPoint = [NaN, NaN];
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, stride,
maxDelta, false, 1, 1, closestPoint, Infinity)).
to.roughlyEqual(0, 1e-9);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
stride,
maxDelta,
false,
1,
1,
closestPoint,
Infinity
)
).to.roughlyEqual(0, 1e-9);
expect(closestPoint).to.have.length(stride);
expect(closestPoint[0]).to.be(1);
expect(closestPoint[1]).to.be(1);
expect(closestPoint[2]).to.be(20);
expect(closestPoint[3]).to.be(-15);
});
});
});
});
+80 -24
View File
@@ -1,40 +1,96 @@
import {linearRingContainsXY} from '../../../../../src/ol/geom/flat/contains.js';
describe('ol.geom.flat.contains', function() {
describe('with simple data', function() {
describe('ol.geom.flat.contains', function () {
describe('with simple data', function () {
const flatCoordinatesSimple = [0, 0, 1, 0, 1, 1, 0, 1];
const flatCoordinatesNonSimple = [0, 0, 4, 0, 4, 3, 1, 3, 1, 2, 3, 2, 3, 1, 2, 1, 2, 4, 0, 4];
const flatCoordinatesNonSimple = [
0,
0,
4,
0,
4,
3,
1,
3,
1,
2,
3,
2,
3,
1,
2,
1,
2,
4,
0,
4,
];
describe('ol.geom.flat.contains.linearRingContainsXY', function() {
it('returns true for point inside a simple polygon', function() {
expect(linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 0.5, 0.5)).to.be(true);
describe('ol.geom.flat.contains.linearRingContainsXY', function () {
it('returns true for point inside a simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesSimple,
0,
flatCoordinatesSimple.length,
2,
0.5,
0.5
)
).to.be(true);
});
it('returns false for point outside a simple polygon', function() {
expect(linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 1.5, 1.5)).to.be(false);
it('returns false for point outside a simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesSimple,
0,
flatCoordinatesSimple.length,
2,
1.5,
1.5
)
).to.be(false);
});
it('returns true for point inside a non-simple polygon', function() {
expect(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1, 1)).to.be(true);
it('returns true for point inside a non-simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesNonSimple,
0,
flatCoordinatesNonSimple.length,
2,
1,
1
)
).to.be(true);
});
it('returns true for point inside an overlap of a non-simple polygon', function() {
expect(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1.5, 2.5)).to.be(true);
it('returns true for point inside an overlap of a non-simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesNonSimple,
0,
flatCoordinatesNonSimple.length,
2,
1.5,
2.5
)
).to.be(true);
});
it('returns false for a point inside a hole of a non-simple polygon', function() {
expect(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 2.5, 1.5)).to.be(false);
it('returns false for a point inside a hole of a non-simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesNonSimple,
0,
flatCoordinatesNonSimple.length,
2,
2.5,
1.5
)
).to.be(false);
});
});
});
});
+34 -18
View File
@@ -1,38 +1,54 @@
import {deflateCoordinates, deflateCoordinatesArray} from '../../../../../src/ol/geom/flat/deflate.js';
describe('ol.geom.flat.deflate', function() {
describe('ol.geom.flat.deflate.deflateCoordinates', function() {
import {
deflateCoordinates,
deflateCoordinatesArray,
} from '../../../../../src/ol/geom/flat/deflate.js';
describe('ol.geom.flat.deflate', function () {
describe('ol.geom.flat.deflate.deflateCoordinates', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [];
});
it('flattens coordinates', function() {
it('flattens coordinates', function () {
const offset = deflateCoordinates(
flatCoordinates, 0, [[1, 2], [3, 4]], 2);
flatCoordinates,
0,
[
[1, 2],
[3, 4],
],
2
);
expect(offset).to.be(4);
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
});
});
describe('ol.geom.flat.deflate.deflateCoordinatesArray', function() {
describe('ol.geom.flat.deflate.deflateCoordinatesArray', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [];
});
it('flattens arrays of coordinates', function() {
const ends = deflateCoordinatesArray(flatCoordinates, 0,
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], 2);
it('flattens arrays of coordinates', function () {
const ends = deflateCoordinatesArray(
flatCoordinates,
0,
[
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
],
2
);
expect(ends).to.eql([4, 8]);
expect(flatCoordinates).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
});
});
});
+15 -17
View File
@@ -1,33 +1,31 @@
import {flipXY} from '../../../../../src/ol/geom/flat/flip.js';
describe('ol.geom.flat.flip', function() {
describe('ol.geom.flat.flip.flipXY', function() {
it('can flip XY coordinates', function() {
describe('ol.geom.flat.flip', function () {
describe('ol.geom.flat.flip.flipXY', function () {
it('can flip XY coordinates', function () {
const flatCoordinates = flipXY([1, 2, 3, 4], 0, 4, 2);
expect(flatCoordinates).to.eql([2, 1, 4, 3]);
});
it('can flip XY coordinates while preserving other dimensions', function() {
it('can flip XY coordinates while preserving other dimensions', function () {
const flatCoordinates = flipXY([1, 2, 3, 4, 5, 6, 7, 8], 0, 8, 4);
expect(flatCoordinates).to.eql([2, 1, 3, 4, 6, 5, 7, 8]);
});
it('can flip XY coordinates in place', function() {
it('can flip XY coordinates in place', function () {
const flatCoordinates = [1, 2, 3, 4];
expect(flipXY(flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
expect(flipXY(flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(
flatCoordinates
);
expect(flatCoordinates).to.eql([2, 1, 4, 3]);
});
it('can flip XY coordinates in place while preserving other dimensions',
function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(flipXY(flatCoordinates, 0, 9, 3, flatCoordinates)).to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
});
it('can flip XY coordinates in place while preserving other dimensions', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(flipXY(flatCoordinates, 0, 9, 3, flatCoordinates)).to.be(
flatCoordinates
);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
});
});
});
+28 -16
View File
@@ -1,25 +1,37 @@
import {inflateCoordinates, inflateCoordinatesArray} from '../../../../../src/ol/geom/flat/inflate.js';
import {
inflateCoordinates,
inflateCoordinatesArray,
} from '../../../../../src/ol/geom/flat/inflate.js';
describe('ol.geom.flat.inflate', function() {
describe('ol.geom.flat.inflate.inflateCoordinates', function() {
it('inflates coordinates', function() {
describe('ol.geom.flat.inflate', function () {
describe('ol.geom.flat.inflate.inflateCoordinates', function () {
it('inflates coordinates', function () {
const coordinates = inflateCoordinates([1, 2, 3, 4], 0, 4, 2);
expect(coordinates).to.eql([[1, 2], [3, 4]]);
expect(coordinates).to.eql([
[1, 2],
[3, 4],
]);
});
});
describe('ol.geom.flat.inflate.inflateCoordinatesArray', function() {
it('inflates arrays of coordinates', function() {
describe('ol.geom.flat.inflate.inflateCoordinatesArray', function () {
it('inflates arrays of coordinates', function () {
const coordinatess = inflateCoordinatesArray(
[1, 2, 3, 4, 5, 6, 7, 8], 0, [4, 8], 2);
expect(coordinatess).to.eql([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
[1, 2, 3, 4, 5, 6, 7, 8],
0,
[4, 8],
2
);
expect(coordinatess).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
});
});
+41 -54
View File
@@ -1,80 +1,67 @@
import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js';
describe('ol.geom.flat.interpolate', function() {
describe('ol.geom.flat.interpolate.interpolatePoint', function() {
it('returns the expected value for single points', function() {
describe('ol.geom.flat.interpolate', function () {
describe('ol.geom.flat.interpolate.interpolatePoint', function () {
it('returns the expected value for single points', function () {
const flatCoordinates = [0, 1];
const point =
interpolatePoint(flatCoordinates, 0, 2, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 2, 2, 0.5);
expect(point).to.eql([0, 1]);
});
it('returns the expected value for simple line segments', function() {
it('returns the expected value for simple line segments', function () {
const flatCoordinates = [0, 1, 2, 3];
const point =
interpolatePoint(flatCoordinates, 0, 4, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 4, 2, 0.5);
expect(point).to.eql([1, 2]);
});
it('returns the expected value when the mid point is an existing ' +
it(
'returns the expected value when the mid point is an existing ' +
'coordinate',
function() {
const flatCoordinates = [0, 1, 2, 3, 4, 5];
const point = interpolatePoint(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([2, 3]);
});
function () {
const flatCoordinates = [0, 1, 2, 3, 4, 5];
const point = interpolatePoint(flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([2, 3]);
}
);
it('also when vertices are repeated', function() {
it('also when vertices are repeated', function () {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5];
const point = interpolatePoint(
flatCoordinates, 0, 8, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([2, 3]);
});
it('returns the expected value when the midpoint falls halfway between ' +
it(
'returns the expected value when the midpoint falls halfway between ' +
'two existing coordinates',
function() {
const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
function () {
const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
}
);
it('also when vertices are repeated', function() {
it('also when vertices are repeated', function () {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 10, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 10, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when the coordinates are not evenly spaced',
function() {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when the coordinates are not evenly spaced', function () {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('also when vertices are repeated',
function() {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when using opt_dest',
function() {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
expect(point).to.eql([3, 4]);
});
it('also when vertices are repeated', function () {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when using opt_dest', function () {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
expect(point).to.eql([3, 4]);
});
});
});
+139 -55
View File
@@ -1,118 +1,202 @@
import {intersectsLinearRing, intersectsLineString, intersectsLinearRingArray} from '../../../../../src/ol/geom/flat/intersectsextent.js';
import {
intersectsLineString,
intersectsLinearRing,
intersectsLinearRingArray,
} from '../../../../../src/ol/geom/flat/intersectsextent.js';
describe('ol.geom.flat.intersectsextent', function() {
describe('ol.geom.flat.intersectsextent.intersectsLineString', function() {
describe('ol.geom.flat.intersectsextent', function () {
describe('ol.geom.flat.intersectsextent.intersectsLineString', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [0, 0, 1, 1, 2, 2];
});
describe('linestring envelope does not intersect the extent', function() {
it('returns false', function() {
describe('linestring envelope does not intersect the extent', function () {
it('returns false', function () {
const extent = [3, 3, 4, 4];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
});
describe('linestring envelope within the extent', function() {
it('returns true', function() {
describe('linestring envelope within the extent', function () {
it('returns true', function () {
const extent = [-1, -1, 3, 3];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
});
describe('linestring envelope bisected by an edge of the extent',
function() {
it('returns true', function() {
const extent = [-0.1, 0.1, 2.1, 0.1];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(true);
});
describe('linestring envelope bisected by an edge of the extent', function () {
it('returns true', function () {
const extent = [-0.1, 0.1, 2.1, 0.1];
const r = intersectsLineString(
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
describe('a segment intersects the extent', function() {
it('returns true', function() {
});
describe('a segment intersects the extent', function () {
it('returns true', function () {
const extent = [-0.5, -0.5, 0.5, 0.5];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
});
describe('no segments intersect the extent', function() {
it('returns false', function() {
describe('no segments intersect the extent', function () {
it('returns false', function () {
const extent = [0.5, 1.5, 1, 1.75];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
it('returns false', function() {
it('returns false', function () {
const extent = [1, 0.25, 1.5, 0.5];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
});
});
describe('ol.geom.flat.intersectsextent.intersectsLinearRing', function() {
describe('ol.geom.flat.intersectsextent.intersectsLinearRing', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [0, 0, 1, 1, 2, 0, 1, -1, 0, 0];
});
describe('boundary intersects the extent', function() {
it('returns true', function() {
describe('boundary intersects the extent', function () {
it('returns true', function () {
const extent = [1.5, 0.0, 2.5, 1.0];
const r = intersectsLinearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
});
describe('boundary does not intersect the extent and ring does not ' +
describe(
'boundary does not intersect the extent and ring does not ' +
'contain a corner of the extent',
function() {
it('returns false', function() {
const extent = [2.0, 0.5, 3, 1.5];
const r = intersectsLinearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(false);
});
});
describe('ring contains the extent', function() {
it('returns true', function() {
function () {
it('returns false', function () {
const extent = [2.0, 0.5, 3, 1.5];
const r = intersectsLinearRing(
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
}
);
describe('ring contains the extent', function () {
it('returns true', function () {
const extent = [0.75, -0.25, 1.25, 0.25];
const r = intersectsLinearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
});
});
describe('ol.geom.flat.intersectsextent.intersectsLinearRingArray', function() {
describe('ol.geom.flat.intersectsextent.intersectsLinearRingArray', function () {
let flatCoordinates;
let ends;
beforeEach(function() {
flatCoordinates = [0, 0, 0, 10, 10, 10, 10, 0, 0, 0, /*hole*/2, 2, 8, 2, 8, 4, 5, 5, 8, 6, 8, 8, 2, 8, 2, 2];
beforeEach(function () {
flatCoordinates = [
0,
0,
0,
10,
10,
10,
10,
0,
0,
0,
/*hole*/ 2,
2,
8,
2,
8,
4,
5,
5,
8,
6,
8,
8,
2,
8,
2,
2,
];
ends = [10, flatCoordinates.length];
});
describe('ring with hole where hole contains the extent', function() {
it('returns true', function() {
describe('ring with hole where hole contains the extent', function () {
it('returns true', function () {
const extent = [3, 3, 3.5, 3.5];
const r = intersectsLinearRingArray(
flatCoordinates, 0, ends, 2, extent);
flatCoordinates,
0,
ends,
2,
extent
);
expect(r).to.be(false);
});
});
describe('ring with hole intersects the extent', function() {
it('returns true', function() {
describe('ring with hole intersects the extent', function () {
it('returns true', function () {
const extent = [3, 3, 6, 6];
const r = intersectsLinearRingArray(
flatCoordinates, 0, ends, 2, extent);
flatCoordinates,
0,
ends,
2,
extent
);
expect(r).to.be(true);
});
});
});
});
+17 -22
View File
@@ -1,15 +1,15 @@
import {lineStringLength, linearRingLength} from '../../../../../src/ol/geom/flat/length.js';
import {
lineStringLength,
linearRingLength,
} from '../../../../../src/ol/geom/flat/length.js';
describe('ol.geom.flat.length', function() {
describe('ol.geom.flat.length.lineStringLength', function() {
describe('stride = 2', function() {
describe('ol.geom.flat.length', function () {
describe('ol.geom.flat.length.lineStringLength', function () {
describe('stride = 2', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
it('calculates the total length of a lineString', function() {
it('calculates the total length of a lineString', function () {
const offset = 0;
const end = 8;
const expected = 3;
@@ -17,7 +17,7 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (offset)', function() {
it('calculates a partwise length of a lineString (offset)', function () {
const offset = 2;
const end = 8;
const expected = 2;
@@ -25,21 +25,20 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (end)', function() {
it('calculates a partwise length of a lineString (end)', function () {
const offset = 0;
const end = 4;
const expected = 1;
const got = lineStringLength(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
});
describe('stride = 3', function() {
describe('stride = 3', function () {
const flatCoords = [0, 0, 42, 1, 0, 42, 1, 1, 42, 0, 1, 42];
const stride = 3;
it('calculates the total length of a lineString', function() {
it('calculates the total length of a lineString', function () {
const offset = 0;
const end = 12;
const expected = 3;
@@ -47,7 +46,7 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (offset)', function() {
it('calculates a partwise length of a lineString (offset)', function () {
const offset = 3;
const end = 12;
const expected = 2;
@@ -55,20 +54,18 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (end)', function() {
it('calculates a partwise length of a lineString (end)', function () {
const offset = 0;
const end = 6;
const expected = 1;
const got = lineStringLength(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
});
});
describe('ol.geom.flat.length.linearRingLength', function() {
it('calculates the total length of a simple linearRing', function() {
describe('ol.geom.flat.length.linearRingLength', function () {
it('calculates the total length of a simple linearRing', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
const offset = 0;
@@ -78,7 +75,7 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates the total length of a figure-8 linearRing', function() {
it('calculates the total length of a figure-8 linearRing', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0];
const stride = 2;
const offset = 0;
@@ -87,7 +84,5 @@ describe('ol.geom.flat.length', function() {
const got = linearRingLength(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
});
});
+281 -56
View File
@@ -1,101 +1,255 @@
import {linearRingIsClockwise, linearRingsAreOriented,
linearRingssAreOriented, orientLinearRings, orientLinearRingsArray} from '../../../../../src/ol/geom/flat/orient.js';
import {
linearRingIsClockwise,
linearRingsAreOriented,
linearRingssAreOriented,
orientLinearRings,
orientLinearRingsArray,
} from '../../../../../src/ol/geom/flat/orient.js';
describe('ol.geom.flat.orient', function() {
describe('ol.geom.flat.orient.linearRingIsClockwise', function() {
it('identifies clockwise rings', function() {
describe('ol.geom.flat.orient', function () {
describe('ol.geom.flat.orient.linearRingIsClockwise', function () {
it('identifies clockwise rings', function () {
const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0];
const isClockwise = linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClockwise).to.be(true);
});
it('identifies anti-clockwise rings', function() {
it('identifies anti-clockwise rings', function () {
const flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3];
const isClockwise = linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClockwise).to.be(false);
});
});
describe('ol.geom.flat.orient.linearRingsAreOriented', function() {
describe('ol.geom.flat.orient.linearRingsAreOriented', function () {
const oriented = linearRingsAreOriented;
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
-180,
-90,
180,
-90,
180,
90,
-180,
90,
-180,
-90,
-100,
-45,
-100,
45,
100,
45,
100,
-45,
-100,
-45,
];
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
-180,
-90,
-180,
90,
180,
90,
180,
-90,
-180,
-90,
-100,
-45,
100,
-45,
100,
45,
-100,
45,
-100,
-45,
];
const ends = [10, 20];
it('checks for left-hand orientation by default', function() {
it('checks for left-hand orientation by default', function () {
expect(oriented(rightCoords, 0, ends, 2)).to.be(false);
expect(oriented(leftCoords, 0, ends, 2)).to.be(true);
});
it('can check for right-hand orientation', function() {
it('can check for right-hand orientation', function () {
expect(oriented(rightCoords, 0, ends, 2, true)).to.be(true);
expect(oriented(leftCoords, 0, ends, 2, true)).to.be(false);
});
});
describe('ol.geom.flat.orient.linearRingssAreOriented', function() {
describe('ol.geom.flat.orient.linearRingssAreOriented', function () {
const oriented = linearRingssAreOriented;
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45,
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
-180,
-90,
180,
-90,
180,
90,
-180,
90,
-180,
-90,
-100,
-45,
-100,
45,
100,
45,
100,
-45,
-100,
-45,
-180,
-90,
180,
-90,
180,
90,
-180,
90,
-180,
-90,
-100,
-45,
-100,
45,
100,
45,
100,
-45,
-100,
-45,
];
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45,
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
-180,
-90,
-180,
90,
180,
90,
180,
-90,
-180,
-90,
-100,
-45,
100,
-45,
100,
45,
-100,
45,
-100,
-45,
-180,
-90,
-180,
90,
180,
90,
180,
-90,
-180,
-90,
-100,
-45,
100,
-45,
100,
45,
-100,
45,
-100,
-45,
];
const ends = [[10, 20], [30, 40]];
const ends = [
[10, 20],
[30, 40],
];
it('checks for left-hand orientation by default', function() {
it('checks for left-hand orientation by default', function () {
expect(oriented(rightCoords, 0, ends, 2)).to.be(false);
expect(oriented(leftCoords, 0, ends, 2)).to.be(true);
});
it('can check for right-hand orientation', function() {
it('can check for right-hand orientation', function () {
expect(oriented(rightCoords, 0, ends, 2, true)).to.be(true);
expect(oriented(leftCoords, 0, ends, 2, true)).to.be(false);
});
});
describe('ol.geom.flat.orient.orientLinearRings', function() {
describe('ol.geom.flat.orient.orientLinearRings', function () {
const orient = orientLinearRings;
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
-180,
-90,
180,
-90,
180,
90,
-180,
90,
-180,
-90,
-100,
-45,
-100,
45,
100,
45,
100,
-45,
-100,
-45,
];
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
-180,
-90,
-180,
90,
180,
90,
180,
-90,
-180,
-90,
-100,
-45,
100,
-45,
100,
45,
-100,
45,
-100,
-45,
];
const ends = [10, 20];
it('orients using the left-hand rule by default', function() {
it('orients using the left-hand rule by default', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2);
expect(rightClone).to.eql(leftCoords);
@@ -105,7 +259,7 @@ describe('ol.geom.flat.orient', function() {
expect(leftClone).to.eql(leftCoords);
});
it('can orient using the right-hand rule', function() {
it('can orient using the right-hand rule', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2, true);
expect(rightClone).to.eql(rightCoords);
@@ -114,29 +268,103 @@ describe('ol.geom.flat.orient', function() {
orient(leftClone, 0, ends, 2, true);
expect(leftClone).to.eql(rightCoords);
});
});
describe('ol.geom.flat.orient.orientLinearRingsArray', function() {
describe('ol.geom.flat.orient.orientLinearRingsArray', function () {
const orient = orientLinearRingsArray;
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45,
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
-180,
-90,
180,
-90,
180,
90,
-180,
90,
-180,
-90,
-100,
-45,
-100,
45,
100,
45,
100,
-45,
-100,
-45,
-180,
-90,
180,
-90,
180,
90,
-180,
90,
-180,
-90,
-100,
-45,
-100,
45,
100,
45,
100,
-45,
-100,
-45,
];
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45,
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
-180,
-90,
-180,
90,
180,
90,
180,
-90,
-180,
-90,
-100,
-45,
100,
-45,
100,
45,
-100,
45,
-100,
-45,
-180,
-90,
-180,
90,
180,
90,
180,
-90,
-180,
-90,
-100,
-45,
100,
-45,
100,
45,
-100,
45,
-100,
-45,
];
const ends = [[10, 20], [30, 40]];
const ends = [
[10, 20],
[30, 40],
];
it('orients using the left-hand rule by default', function() {
it('orients using the left-hand rule by default', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2);
expect(rightClone).to.eql(leftCoords);
@@ -146,7 +374,7 @@ describe('ol.geom.flat.orient', function() {
expect(leftClone).to.eql(leftCoords);
});
it('can orient using the right-hand rule', function() {
it('can orient using the right-hand rule', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2, true);
expect(rightClone).to.eql(rightCoords);
@@ -155,8 +383,5 @@ describe('ol.geom.flat.orient', function() {
orient(leftClone, 0, ends, 2, true);
expect(leftClone).to.eql(rightCoords);
});
});
});
+56 -35
View File
@@ -1,114 +1,135 @@
import {coordinates as reverseCoordinates} from '../../../../../src/ol/geom/flat/reverse.js';
describe('ol.geom.flat.reverse', function() {
describe('ol.geom.flat.reverse.coordinates', function() {
describe('with a stride of 2', function() {
it('can reverse empty flat coordinates', function() {
describe('ol.geom.flat.reverse', function () {
describe('ol.geom.flat.reverse.coordinates', function () {
describe('with a stride of 2', function () {
it('can reverse empty flat coordinates', function () {
const flatCoordinates = [];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
it('can reverse one flat coordinates', function () {
const flatCoordinates = [1, 2];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([1, 2]);
});
it('can reverse two flat coordinates', function() {
it('can reverse two flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([3, 4, 1, 2]);
});
it('can reverse three flat coordinates', function() {
it('can reverse three flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([5, 6, 3, 4, 1, 2]);
});
it('can reverse four flat coordinates', function() {
it('can reverse four flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([7, 8, 5, 6, 3, 4, 1, 2]);
});
});
describe('with a stride of 3', function() {
it('can reverse empty flat coordinates', function() {
describe('with a stride of 3', function () {
it('can reverse empty flat coordinates', function () {
const flatCoordinates = [];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
it('can reverse one flat coordinates', function () {
const flatCoordinates = [1, 2, 3];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([1, 2, 3]);
});
it('can reverse two flat coordinates', function() {
it('can reverse two flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([4, 5, 6, 1, 2, 3]);
});
it('can reverse three flat coordinates', function() {
it('can reverse three flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([7, 8, 9, 4, 5, 6, 1, 2, 3]);
});
it('can reverse four flat coordinates', function() {
it('can reverse four flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3]);
});
});
describe('with a stride of 4', function() {
it('can reverse empty flat coordinates', function() {
describe('with a stride of 4', function () {
it('can reverse empty flat coordinates', function () {
const flatCoordinates = [];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
it('can reverse one flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
});
it('can reverse two flat coordinates', function() {
it('can reverse two flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([5, 6, 7, 8, 1, 2, 3, 4]);
});
it('can reverse three flat coordinates', function() {
it('can reverse three flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]);
});
it('can reverse four flat coordinates', function() {
const flatCoordinates =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
it('can reverse four flat coordinates', function () {
const flatCoordinates = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql(
[13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]);
expect(flatCoordinates).to.eql([
13,
14,
15,
16,
9,
10,
11,
12,
5,
6,
7,
8,
1,
2,
3,
4,
]);
});
});
});
});
+9 -11
View File
@@ -1,20 +1,18 @@
import {forEach as forEachSegment} from '../../../../../src/ol/geom/flat/segments.js';
describe('ol.geom.flat.segments', function() {
describe('ol.geom.flat.segments.forEach', function() {
describe('ol.geom.flat.segments', function () {
describe('ol.geom.flat.segments.forEach', function () {
let flatCoordinates, offset, end, stride;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [0, 0, 1, 1, 2, 2, 3, 3];
offset = 0;
end = 8;
stride = 2;
});
describe('callback returns undefined', function() {
it('executes the callback for each segment', function() {
describe('callback returns undefined', function () {
it('executes the callback for each segment', function () {
const args = [];
const spy = sinon.spy(function(point1, point2) {
const spy = sinon.spy(function (point1, point2) {
args.push([point1[0], point1[1], point2[0], point2[1]]);
});
const ret = forEachSegment(flatCoordinates, offset, end, stride, spy);
@@ -34,10 +32,10 @@ describe('ol.geom.flat.segments', function() {
expect(ret).to.be(false);
});
});
describe('callback returns true', function() {
it('executes the callback for the first segment', function() {
describe('callback returns true', function () {
it('executes the callback for the first segment', function () {
const args = [];
const spy = sinon.spy(function(point1, point2) {
const spy = sinon.spy(function (point1, point2) {
args.push([point1[0], point1[1], point2[0], point2[1]]);
return true;
});
File diff suppressed because it is too large Load Diff
+31 -20
View File
@@ -1,58 +1,69 @@
import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js';
describe('ol.geom.flat.straightchunk', function() {
describe('ol.geom.flat.straightchunk.matchingChunk', function() {
describe('single segment with stride == 3', function() {
describe('ol.geom.flat.straightchunk', function () {
describe('ol.geom.flat.straightchunk.matchingChunk', function () {
describe('single segment with stride == 3', function () {
const flatCoords = [0, 0, 42, 1, 1, 42];
const stride = 3;
it('returns whole line with angle delta', function() {
it('returns whole line with angle delta', function () {
const got = matchingChunk(Math.PI / 4, flatCoords, 0, 6, stride);
expect(got).to.eql([0, 6]);
});
it('returns whole line with zero angle delta', function() {
it('returns whole line with zero angle delta', function () {
const got = matchingChunk(0, flatCoords, 0, 6, stride);
expect(got).to.eql([0, 6]);
});
});
describe('short line string', function() {
describe('short line string', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
it('returns whole line if straight enough', function() {
it('returns whole line if straight enough', function () {
const got = matchingChunk(Math.PI, flatCoords, 0, 8, stride);
expect(got).to.eql([0, 8]);
});
it('returns first matching chunk if all chunk lengths are the same', function() {
it('returns first matching chunk if all chunk lengths are the same', function () {
const got = matchingChunk(Math.PI / 4, flatCoords, 0, 8, stride);
expect(got).to.eql([0, 4]);
});
});
describe('longer line string', function() {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0, -1, 2, -2, 4];
describe('longer line string', function () {
const flatCoords = [
0,
0,
1,
0,
1,
1,
0,
1,
0,
-1,
-1,
-1,
-1,
0,
-1,
2,
-2,
4,
];
const stride = 2;
it('returns stright chunk from within the linestring', function() {
it('returns stright chunk from within the linestring', function () {
const got = matchingChunk(0, flatCoords, 0, 18, stride);
expect(got).to.eql([10, 16]);
});
it('returns long chunk at the end if angle and length within threshold', function() {
it('returns long chunk at the end if angle and length within threshold', function () {
const got = matchingChunk(Math.PI / 4, flatCoords, 0, 18, stride);
expect(got).to.eql([10, 18]);
});
});
});
});
+165 -35
View File
@@ -1,8 +1,7 @@
import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js';
import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js';
describe('ol.geom.flat.drawTextOnPath', function() {
describe('ol.geom.flat.drawTextOnPath', function () {
const horizontal = [0, 0, 100, 0];
const vertical = [0, 0, 0, 100];
const diagonal = [0, 0, 100, 100];
@@ -14,103 +13,234 @@ describe('ol.geom.flat.drawTextOnPath', function() {
return 10 * text.length;
}
it('center-aligns text on a horizontal line', function() {
it('center-aligns text on a horizontal line', function () {
const startM = 50 - 15;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[40, 0, 5, 0, 'foo']]);
});
it('left-aligns text on a horizontal line', function() {
it('left-aligns text on a horizontal line', function () {
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', 0, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
0,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[5, 0, 5, 0, 'foo']]);
});
it('right-aligns text on a horizontal line', function() {
it('right-aligns text on a horizontal line', function () {
const startM = 100 - 30;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[75, 0, 5, 0, 'foo']]);
});
it('draws text on a vertical line', function() {
it('draws text on a vertical line', function () {
const startM = 50 - 15;
const instructions = drawTextOnPath(
vertical, 0, vertical.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
const a = 90 * Math.PI / 180;
vertical,
0,
vertical.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
const a = (90 * Math.PI) / 180;
expect(instructions).to.eql([[0, 40, 5, a, 'foo']]);
});
it('draws text on a diagonal line', function() {
it('draws text on a diagonal line', function () {
const startM = Math.sqrt(2) * 50 - 15;
const instructions = drawTextOnPath(
diagonal, 0, diagonal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
diagonal,
0,
diagonal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('draws reverse text on a diagonal line', function() {
it('draws reverse text on a diagonal line', function () {
const startM = Math.sqrt(2) * 50 - 15;
const instructions = drawTextOnPath(
reverse, 0, reverse.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
reverse,
0,
reverse.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((-45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('renders long text with extrapolation', function() {
it('renders long text with extrapolation', function () {
const startM = 50 - 75;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo-foo-foo-foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo-foo-foo-foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0]).to.eql([-20, 0, 5, 0, 'foo-foo-foo-foo']);
expect(instructions.length).to.be(1);
});
it('renders angled text', function() {
it('renders angled text', function () {
const length = lineStringLength(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, angled.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.eql(45 * Math.PI / 180);
angled,
0,
angled.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.eql((45 * Math.PI) / 180);
expect(instructions[0][4]).to.be('f');
expect(instructions[1][3]).to.eql(45 * Math.PI / 180);
expect(instructions[1][3]).to.eql((45 * Math.PI) / 180);
expect(instructions[1][4]).to.be('o');
expect(instructions[2][3]).to.eql(-45 * Math.PI / 180);
expect(instructions[2][3]).to.eql((-45 * Math.PI) / 180);
expect(instructions[2][4]).to.be('o');
});
it('respects maxAngle', function() {
it('respects maxAngle', function () {
const length = lineStringLength(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, angled.length, 2, 'foo', startM, Math.PI / 4, 1, measureAndCacheTextWidth, '', {});
angled,
0,
angled.length,
2,
'foo',
startM,
Math.PI / 4,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.be(null);
});
it('uses the smallest angle for maxAngleDelta', function() {
it('uses the smallest angle for maxAngleDelta', function () {
const length = lineStringLength(reverseangled, 0, reverseangled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
reverseangled, 0, reverseangled.length, 2, 'foo', startM, Math.PI, 1, measureAndCacheTextWidth, '', {});
reverseangled,
0,
reverseangled.length,
2,
'foo',
startM,
Math.PI,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.not.be(undefined);
});
it('respects the offset option', function() {
it('respects the offset option', function () {
const length = lineStringLength(angled, 2, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 2, angled.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
angled,
2,
angled.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((-45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('respects the end option', function() {
it('respects the end option', function () {
const length = lineStringLength(angled, 0, 4, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, 4, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
angled,
0,
4,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
});
+29 -13
View File
@@ -1,31 +1,47 @@
import {lineStringIsClosed} from '../../../../../src/ol/geom/flat/topology.js';
describe('ol.geom.flat.topology', function() {
describe('ol.geom.flat.topology.lineStringIsClosed', function() {
it('identifies closed lines aka boundaries', function() {
describe('ol.geom.flat.topology', function () {
describe('ol.geom.flat.topology.lineStringIsClosed', function () {
it('identifies closed lines aka boundaries', function () {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0];
const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
const isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(true);
});
it('identifies regular linestrings', function() {
it('identifies regular linestrings', function () {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2];
const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
const isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(false);
});
it('identifies degenerate boundaries', function() {
it('identifies degenerate boundaries', function () {
let flatCoordinates = [0, 0, 3, 0, 0, 0];
let isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
let isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(false);
flatCoordinates = [0, 0, 1, 1, 3, 3, 5, 5, 0, 0];
isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(false);
});
});
});
+129 -46
View File
@@ -1,37 +1,48 @@
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
import {transformGeom2D} from '../../../../../src/ol/geom/SimpleGeometry.js';
import {rotate, translate} from '../../../../../src/ol/geom/flat/transform.js';
import {transformGeom2D} from '../../../../../src/ol/geom/SimpleGeometry.js';
describe('ol.geom.flat.transform', function() {
describe('ol.geom.flat.transform.transform2D', function() {
it('transforms a Simple Geometry to 2D', function() {
describe('ol.geom.flat.transform', function () {
describe('ol.geom.flat.transform.transform2D', function () {
it('transforms a Simple Geometry to 2D', function () {
const multiPolygonGeometry = new MultiPolygon([
[[[-80.736061, 28.788576000000006, 0],
[-80.763557, 28.821799999999996, 0],
[-80.817406, 28.895123999999996, 0],
[-80.891304, 29.013130000000004, 0],
[-80.916512, 29.071560000000005, 0],
[-80.899323, 29.061249000000004, 0],
[-80.862663, 28.991361999999995, 0],
[-80.736061, 28.788576000000006, 0]]], [[
[-82.102127, 26.585724, 0],
[-82.067139, 26.497208, 0],
[-82.097641, 26.493585999999993, 0],
[-82.135895, 26.642279000000002, 0],
[-82.183495, 26.683082999999996, 0],
[-82.128838, 26.693342, 0],
[-82.102127, 26.585724, 0]]]
[
[
[-80.736061, 28.788576000000006, 0],
[-80.763557, 28.821799999999996, 0],
[-80.817406, 28.895123999999996, 0],
[-80.891304, 29.013130000000004, 0],
[-80.916512, 29.071560000000005, 0],
[-80.899323, 29.061249000000004, 0],
[-80.862663, 28.991361999999995, 0],
[-80.736061, 28.788576000000006, 0],
],
],
[
[
[-82.102127, 26.585724, 0],
[-82.067139, 26.497208, 0],
[-82.097641, 26.493585999999993, 0],
[-82.135895, 26.642279000000002, 0],
[-82.183495, 26.683082999999996, 0],
[-82.128838, 26.693342, 0],
[-82.102127, 26.585724, 0],
],
],
]).transform('EPSG:4326', 'EPSG:3857');
const transform = [
0.0004088332670837288, 0,
0, -0.0004088332670837288,
4480.991370439071, 1529.5752568707105
0.0004088332670837288,
0,
0,
-0.0004088332670837288,
4480.991370439071,
1529.5752568707105,
];
const pixelCoordinates = transformGeom2D(multiPolygonGeometry, transform, []);
const pixelCoordinates = transformGeom2D(
multiPolygonGeometry,
transform,
[]
);
expect(pixelCoordinates[0]).to.roughlyEqual(806.6035275946265, 1e-9);
expect(pixelCoordinates[1]).to.roughlyEqual(160.48916296287916, 1e-9);
expect(pixelCoordinates[2]).to.roughlyEqual(805.3521540835154, 1e-9);
@@ -63,37 +74,111 @@ describe('ol.geom.flat.transform', function() {
expect(pixelCoordinates[28]).to.roughlyEqual(744.4323460835158, 1e-9);
expect(pixelCoordinates[29]).to.roughlyEqual(273.7179168205373, 1e-9);
});
});
describe('ol.geom.flat.transform.translate', function() {
it('translates the coordinates array', function() {
describe('ol.geom.flat.transform.translate', function () {
it('translates the coordinates array', function () {
const multiPolygon = new MultiPolygon([
[[[0, 0, 2], [0, 1, 2], [1, 1, 2], [1, 0, 2], [0, 0, 2]]],
[[[2, 2, 3], [2, 3, 3], [3, 3, 3], [3, 2, 3], [2, 2, 3]]]]);
[
[
[0, 0, 2],
[0, 1, 2],
[1, 1, 2],
[1, 0, 2],
[0, 0, 2],
],
],
[
[
[2, 2, 3],
[2, 3, 3],
[3, 3, 3],
[3, 2, 3],
[2, 2, 3],
],
],
]);
const flatCoordinates = multiPolygon.getFlatCoordinates();
const deltaX = 1;
const deltaY = 2;
translate(flatCoordinates, 0,
flatCoordinates.length, multiPolygon.getStride(),
deltaX, deltaY, flatCoordinates);
translate(
flatCoordinates,
0,
flatCoordinates.length,
multiPolygon.getStride(),
deltaX,
deltaY,
flatCoordinates
);
expect(flatCoordinates).to.eql([
1, 2, 2, 1, 3, 2, 2, 3, 2, 2, 2, 2, 1, 2, 2,
3, 4, 3, 3, 5, 3, 4, 5, 3, 4, 4, 3, 3, 4, 3]);
1,
2,
2,
1,
3,
2,
2,
3,
2,
2,
2,
2,
1,
2,
2,
3,
4,
3,
3,
5,
3,
4,
5,
3,
4,
4,
3,
3,
4,
3,
]);
});
});
describe('ol.geom.flat.transform.rotate', function() {
it('rotates the coordinates array', function() {
describe('ol.geom.flat.transform.rotate', function () {
it('rotates the coordinates array', function () {
const multiPolygon = new MultiPolygon([
[[[0, 0, 2], [0, 1, 2], [1, 1, 2], [1, 0, 2], [0, 0, 2]]],
[[[2, 2, 3], [2, 3, 3], [3, 3, 3], [3, 2, 3], [2, 2, 3]]]]);
[
[
[0, 0, 2],
[0, 1, 2],
[1, 1, 2],
[1, 0, 2],
[0, 0, 2],
],
],
[
[
[2, 2, 3],
[2, 3, 3],
[3, 3, 3],
[3, 2, 3],
[2, 2, 3],
],
],
]);
const flatCoordinates = multiPolygon.getFlatCoordinates();
const angle = Math.PI / 2;
const anchor = [0, 1];
rotate(flatCoordinates, 0,
flatCoordinates.length, multiPolygon.getStride(),
angle, anchor, flatCoordinates);
rotate(
flatCoordinates,
0,
flatCoordinates.length,
multiPolygon.getStride(),
angle,
anchor,
flatCoordinates
);
expect(flatCoordinates[0]).to.roughlyEqual(1, 1e-9);
expect(flatCoordinates[1]).to.roughlyEqual(1, 1e-9);
expect(flatCoordinates[2]).to.roughlyEqual(2, 1e-9);
@@ -125,7 +210,5 @@ describe('ol.geom.flat.transform', function() {
expect(flatCoordinates[28]).to.roughlyEqual(3, 1e-9);
expect(flatCoordinates[29]).to.roughlyEqual(3, 1e-9);
});
});
});
+124 -80
View File
@@ -4,60 +4,78 @@ import LineString from '../../../../src/ol/geom/LineString.js';
import Point from '../../../../src/ol/geom/Point.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
describe('ol.geom.GeometryCollection', function() {
const outer = [[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]];
const inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]];
const inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
describe('constructor', function() {
describe('ol.geom.GeometryCollection', function () {
const outer = [
[0, 0],
[0, 10],
[10, 10],
[10, 0],
[0, 0],
];
const inner1 = [
[1, 1],
[2, 1],
[2, 2],
[1, 2],
[1, 1],
];
const inner2 = [
[8, 8],
[9, 8],
[9, 9],
[8, 9],
[8, 8],
];
describe('constructor', function () {
let line, multi, point, poly;
beforeEach(function() {
beforeEach(function () {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
poly = new Polygon([outer, inner1, inner2]);
multi = new GeometryCollection([point, line, poly]);
});
it('creates a geometry collection from an array of geometries', function() {
it('creates a geometry collection from an array of geometries', function () {
expect(multi).to.be.a(GeometryCollection);
expect(multi).to.be.a(Geometry);
});
it('fires a change event when one of its component changes',
function(done) {
multi.on('change', function() {
done();
});
point.setCoordinates([10, 10]);
}
);
it('fires a change event when one of its component changes', function (done) {
multi.on('change', function () {
done();
});
point.setCoordinates([10, 10]);
});
it('deregister old components', function() {
it('deregister old components', function () {
multi.setGeometries([poly]);
multi.on('change', function() {
multi.on('change', function () {
expect().fail();
});
point.setCoordinates([10, 10]);
});
it('register new components', function(done) {
it('register new components', function (done) {
const point2 = new Point([10, 20]);
multi.setGeometriesArray([point2]);
multi.on('change', function() {
multi.on('change', function () {
done();
});
point2.setCoordinates([10, 10]);
});
});
describe('#getGeometries', function() {
it('returns a collection of geometries', function() {
describe('#getGeometries', function () {
it('returns a collection of geometries', function () {
const point = new Point([10, 20]);
const line = new LineString([[10, 20], [30, 40]]);
const line = new LineString([
[10, 20],
[30, 40],
]);
const poly = new Polygon([outer, inner1, inner2]);
const multi = new GeometryCollection([point, line, poly]);
@@ -68,25 +86,29 @@ describe('ol.geom.GeometryCollection', function() {
expect(geometries[1]).to.be.a(LineString);
expect(geometries[2]).to.be.a(Polygon);
});
});
describe('#clone()', function() {
it('has a working clone method', function() {
describe('#clone()', function () {
it('has a working clone method', function () {
const point = new Point([10, 20]);
const line = new LineString([[10, 20], [30, 40]]);
const line = new LineString([
[10, 20],
[30, 40],
]);
const poly = new Polygon([outer, inner1, inner2]);
const multi = new GeometryCollection([point, line, poly]);
const clone = multi.clone();
expect(clone).to.not.be(multi);
const geometries = clone.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([10, 20]);
expect(geometries[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
expect(geometries[1].getCoordinates()).to.eql([
[10, 20],
[30, 40],
]);
expect(geometries[2].getCoordinates()).to.eql([outer, inner1, inner2]);
});
it('does a deep clone', function() {
it('does a deep clone', function () {
const point = new Point([30, 40]);
const originalGeometries = [point];
const multi = new GeometryCollection(originalGeometries);
@@ -96,17 +118,19 @@ describe('ol.geom.GeometryCollection', function() {
expect(clonedGeometries).to.have.length(originalGeometries.length);
expect(clonedGeometries).to.have.length(1);
expect(clonedGeometries[0]).not.to.be(originalGeometries[0]);
expect(clonedGeometries[0].getCoordinates()).
to.eql(originalGeometries[0].getCoordinates());
expect(clonedGeometries[0].getCoordinates()).to.eql(
originalGeometries[0].getCoordinates()
);
});
});
describe('#getExtent()', function() {
it('returns the bounding extent', function() {
describe('#getExtent()', function () {
it('returns the bounding extent', function () {
const point = new Point([10, 2]);
const line = new LineString([[1, 20], [30, 40]]);
const line = new LineString([
[1, 20],
[30, 40],
]);
const multi = new GeometryCollection([point, line]);
const extent = multi.getExtent();
expect(extent[0]).to.be(1);
@@ -114,111 +138,133 @@ describe('ol.geom.GeometryCollection', function() {
expect(extent[1]).to.be(2);
expect(extent[3]).to.be(40);
});
});
describe('#intersectsExtent()', function() {
describe('#intersectsExtent()', function () {
let point, line, poly, multi;
beforeEach(function() {
beforeEach(function () {
point = new Point([5, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
poly = new Polygon([outer, inner1, inner2]);
multi = new GeometryCollection([point, line, poly]);
});
it('returns true for intersecting point', function() {
it('returns true for intersecting point', function () {
expect(multi.intersectsExtent([5, 20, 5, 20])).to.be(true);
});
it('returns true for intersecting part of lineString', function() {
it('returns true for intersecting part of lineString', function () {
expect(multi.intersectsExtent([25, 35, 30, 40])).to.be(true);
});
it('returns true for intersecting part of polygon', function() {
it('returns true for intersecting part of polygon', function () {
expect(multi.intersectsExtent([0, 0, 5, 5])).to.be(true);
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
const extent = [0, 35, 5, 40];
expect(poly.intersectsExtent(extent)).to.be(false);
});
});
describe('#setGeometries', function() {
describe('#setGeometries', function () {
let line, multi, point, poly;
beforeEach(function() {
beforeEach(function () {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
poly = new Polygon([outer, inner1, inner2]);
multi = new GeometryCollection([point, line, poly]);
});
it('fires a change event', function() {
it('fires a change event', function () {
const listener = sinon.spy();
multi.on('change', listener);
multi.setGeometries([point, line, poly]);
expect(listener.calledOnce).to.be(true);
});
it('updates the extent', function() {
it('updates the extent', function () {
expect(multi.getExtent()).to.eql([0, 0, 30, 40]);
line.setCoordinates([[10, 20], [300, 400]]);
line.setCoordinates([
[10, 20],
[300, 400],
]);
expect(multi.getExtent()).to.eql([0, 0, 300, 400]);
});
});
describe('#scale()', function() {
it('scales a collection', function() {
describe('#scale()', function () {
it('scales a collection', function () {
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
new LineString([
[0, 0],
[1, 2],
]),
]);
geom.scale(10);
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-10, -20]);
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [10, 20]]);
expect(geometries[1].getCoordinates()).to.eql([
[0, 0],
[10, 20],
]);
});
it('accepts sx and sy', function() {
it('accepts sx and sy', function () {
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
new LineString([
[0, 0],
[1, 2],
]),
]);
geom.scale(2, 3);
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-2, -6]);
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [2, 6]]);
expect(geometries[1].getCoordinates()).to.eql([
[0, 0],
[2, 6],
]);
});
it('accepts an anchor', function() {
it('accepts an anchor', function () {
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
new LineString([
[0, 0],
[1, 2],
]),
]);
geom.scale(10, 15, [-1, -2]);
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-1, -2]);
expect(geometries[1].getCoordinates()).to.eql([[9, 28], [19, 58]]);
expect(geometries[1].getCoordinates()).to.eql([
[9, 28],
[19, 58],
]);
});
});
describe('#transform()', function() {
describe('#transform()', function () {
let line, multi, point;
beforeEach(function() {
beforeEach(function () {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
multi = new GeometryCollection([point, line]);
});
it('transforms all geometries', function() {
it('transforms all geometries', function () {
multi.transform('EPSG:4326', 'EPSG:3857');
const geometries = multi.getGeometries();
@@ -226,16 +272,14 @@ describe('ol.geom.GeometryCollection', function() {
expect(geometries[1]).to.be.a(LineString);
let coords = geometries[0].getCoordinates();
expect(coords[0]).to.roughlyEqual(1113194.90, 1e-2);
expect(coords[0]).to.roughlyEqual(1113194.9, 1e-2);
expect(coords[1]).to.roughlyEqual(2273030.92, 1e-2);
coords = geometries[1].getCoordinates();
expect(coords[0][0]).to.roughlyEqual(1113194.90, 1e-2);
expect(coords[0][0]).to.roughlyEqual(1113194.9, 1e-2);
expect(coords[0][1]).to.roughlyEqual(2273030.92, 1e-2);
expect(coords[1][0]).to.roughlyEqual(3339584.72, 1e-2);
expect(coords[1][1]).to.roughlyEqual(4865942.27, 1e-2);
});
});
});
+205 -182
View File
@@ -1,365 +1,394 @@
import {isEmpty} from '../../../../src/ol/extent.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import {isEmpty} from '../../../../src/ol/extent.js';
describe('ol.geom.LineString', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.LineString', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new LineString(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(lineString.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(lineString.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(lineString.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(lineString.getStride()).to.be(2);
});
it('can append coordinates', function() {
it('can append coordinates', function () {
lineString.appendCoordinate([1, 2]);
expect(lineString.getCoordinates()).to.eql([[1, 2]]);
lineString.appendCoordinate([3, 4]);
expect(lineString.getCoordinates()).to.eql([[1, 2], [3, 4]]);
expect(lineString.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2], [3, 4]]);
beforeEach(function () {
lineString = new LineString([
[1, 2],
[3, 4],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2], [3, 4]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 3, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(lineString.getStride()).to.be(2);
});
describe('#intersectsCoordinate', function() {
it('returns true for an intersecting coordinate', function() {
describe('#intersectsCoordinate', function () {
it('returns true for an intersecting coordinate', function () {
expect(lineString.intersectsCoordinate([1.5, 2.5])).to.be(true);
});
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
describe('#intersectsCoordinate', function() {
it('detects intersecting coordinates', function() {
describe('#intersectsCoordinate', function () {
it('detects intersecting coordinates', function () {
expect(lineString.intersectsCoordinate([1, 2])).to.be(true);
});
});
describe('#getClosestPoint', function() {
it('uses existing vertices', function() {
describe('#getClosestPoint', function () {
it('uses existing vertices', function () {
const closestPoint = lineString.getClosestPoint([0.9, 1.8]);
expect(closestPoint).to.eql([1, 2]);
});
});
describe('#getCoordinateAt', function() {
it('return the first point when fraction is 0', function() {
describe('#getCoordinateAt', function () {
it('return the first point when fraction is 0', function () {
expect(lineString.getCoordinateAt(0)).to.eql([1, 2]);
});
it('return the last point when fraction is 1', function() {
it('return the last point when fraction is 1', function () {
expect(lineString.getCoordinateAt(1)).to.eql([3, 4]);
});
it('return the mid point when fraction is 0.5', function() {
it('return the mid point when fraction is 0.5', function () {
expect(lineString.getCoordinateAt(0.5)).to.eql([2, 3]);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2, 3], [4, 5, 6]]);
beforeEach(function () {
lineString = new LineString([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(lineString.getStride()).to.be(3);
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString(
[[1, 2, 3], [4, 5, 6]], 'XYM');
[
[1, 2, 3],
[4, 5, 6],
],
'XYM'
);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(lineString.getStride()).to.be(3);
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2, 3, 4], [5, 6, 7, 8]]);
beforeEach(function () {
lineString = new LineString([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2, 3, 4], [5, 6, 7, 8]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 5, 6]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(lineString.getStride()).to.be(4);
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
});
describe('#scale()', function() {
it('scales a linestring', function() {
const geom = new LineString([[-10, -20], [10, 20]]);
describe('#scale()', function () {
it('scales a linestring', function () {
const geom = new LineString([
[-10, -20],
[10, 20],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
expect(coordinates).to.eql([
[-100, -200],
[100, 200],
]);
});
it('accepts sx and sy', function() {
const geom = new LineString([[-10, -20], [10, 20]]);
it('accepts sx and sy', function () {
const geom = new LineString([
[-10, -20],
[10, 20],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
expect(coordinates).to.eql([
[-20, -60],
[20, 60],
]);
});
it('accepts an anchor', function() {
const geom = new LineString([[-10, -20], [10, 20]]);
it('accepts an anchor', function () {
const geom = new LineString([
[-10, -20],
[10, 20],
]);
geom.scale(3, 2, [10, 20]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-50, -60], [10, 20]]);
expect(coordinates).to.eql([
[-50, -60],
[10, 20],
]);
});
});
describe('with a simple line string', function() {
describe('with a simple line string', function () {
let lineString;
beforeEach(function() {
lineString = new LineString(
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
beforeEach(function () {
lineString = new LineString([
[0, 0],
[1.5, 1],
[3, 3],
[5, 1],
[6, 3.5],
[7, 5],
]);
});
describe('#getFirstCoordinate', function() {
it('returns the expected result', function() {
describe('#getFirstCoordinate', function () {
it('returns the expected result', function () {
expect(lineString.getFirstCoordinate()).to.eql([0, 0]);
});
});
describe('#getFlatMidpoint', function() {
it('returns the expected result', function() {
describe('#getFlatMidpoint', function () {
it('returns the expected result', function () {
const midpoint = lineString.getFlatMidpoint();
expect(midpoint).to.be.an(Array);
expect(midpoint).to.have.length(2);
expect(midpoint[0]).to.roughlyEqual(4, 1e-1);
expect(midpoint[1]).to.roughlyEqual(2, 1e-1);
});
});
describe('#getLastCoordinate', function() {
it('returns the expected result', function() {
describe('#getLastCoordinate', function () {
it('returns the expected result', function () {
expect(lineString.getLastCoordinate()).to.eql([7, 5]);
});
});
describe('#simplify', function() {
it('returns a simplified geometry', function() {
describe('#simplify', function () {
it('returns a simplified geometry', function () {
const simplified = lineString.simplify(1);
expect(simplified).to.be.an(LineString);
expect(simplified.getCoordinates()).to.eql(
[[0, 0], [3, 3], [5, 1], [7, 5]]);
expect(simplified.getCoordinates()).to.eql([
[0, 0],
[3, 3],
[5, 1],
[7, 5],
]);
});
it('does not modify the original', function() {
it('does not modify the original', function () {
lineString.simplify(1);
expect(lineString.getCoordinates()).to.eql(
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
expect(lineString.getCoordinates()).to.eql([
[0, 0],
[1.5, 1],
[3, 3],
[5, 1],
[6, 3.5],
[7, 5],
]);
});
it('delegates to the internal method', function() {
it('delegates to the internal method', function () {
const simplified = lineString.simplify(2);
const internal = lineString.getSimplifiedGeometry(4);
expect(simplified.getCoordinates()).to.eql(internal.getCoordinates());
});
});
describe('#getSimplifiedGeometry', function() {
it('returns the expectedResult', function() {
describe('#getSimplifiedGeometry', function () {
it('returns the expectedResult', function () {
const simplifiedGeometry = lineString.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(LineString);
expect(simplifiedGeometry.getCoordinates()).to.eql(
[[0, 0], [3, 3], [5, 1], [7, 5]]);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[0, 0],
[3, 3],
[5, 1],
[7, 5],
]);
});
it('remembers the minimum squared tolerance', function() {
it('remembers the minimum squared tolerance', function () {
sinon.spy(lineString, 'getSimplifiedGeometryInternal');
const simplifiedGeometry1 = lineString.getSimplifiedGeometry(0.05);
expect(lineString.getSimplifiedGeometryInternal.callCount).to.be(1);
@@ -368,39 +397,38 @@ describe('ol.geom.LineString', function() {
expect(lineString.getSimplifiedGeometryInternal.callCount).to.be(1);
expect(simplifiedGeometry2).to.be(lineString);
});
});
describe('#getCoordinateAt', function() {
it('return the first point when fraction is 0', function() {
describe('#getCoordinateAt', function () {
it('return the first point when fraction is 0', function () {
expect(lineString.getCoordinateAt(0)).to.eql([0, 0]);
});
it('return the last point when fraction is 1', function() {
it('return the last point when fraction is 1', function () {
expect(lineString.getCoordinateAt(1)).to.eql([7, 5]);
});
it('return the mid point when fraction is 0.5', function() {
it('return the mid point when fraction is 0.5', function () {
const midpoint = lineString.getFlatMidpoint();
expect(lineString.getCoordinateAt(0.5)).to.eql(midpoint);
});
});
});
describe('with a simple XYM coordinates', function() {
describe('with a simple XYM coordinates', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString(
[[1, 2, 3], [4, 5, 6]], 'XYM');
[
[1, 2, 3],
[4, 5, 6],
],
'XYM'
);
});
describe('#getCoordinateAtM', function() {
it('returns the expected value', function() {
describe('#getCoordinateAtM', function () {
it('returns the expected value', function () {
expect(lineString.getCoordinateAtM(2, false)).to.be(null);
expect(lineString.getCoordinateAtM(2, true)).to.eql([1, 2, 2]);
expect(lineString.getCoordinateAtM(3, false)).to.eql([1, 2, 3]);
@@ -414,15 +442,12 @@ describe('ol.geom.LineString', function() {
expect(lineString.getCoordinateAtM(7, false)).to.eql(null);
expect(lineString.getCoordinateAtM(7, true)).to.eql([4, 5, 7]);
});
});
});
describe('with several XYZM coordinates', function() {
describe('with several XYZM coordinates', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString([
[0, 0, 0, 0],
[1, -1, 2, 1],
@@ -434,29 +459,29 @@ describe('ol.geom.LineString', function() {
[15, -15, 30, 15],
[16, -16, 32, 16],
[18, -18, 36, 18],
[22, -22, 44, 22]
[22, -22, 44, 22],
]);
});
describe('#getCoordinateAtM', function() {
it('returns the expected value', function() {
describe('#getCoordinateAtM', function () {
it('returns the expected value', function () {
expect(lineString.getLayout()).to.be('XYZM');
let m;
for (m = 0; m <= 22; m += 0.5) {
expect(lineString.getCoordinateAtM(m, true)).to.eql(
[m, -m, 2 * m, m]);
expect(lineString.getCoordinateAtM(m, true)).to.eql([
m,
-m,
2 * m,
m,
]);
}
});
});
});
describe('#containsXY()', function() {
describe('#containsXY()', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString([
[0, 0, 0, 0],
[1, -1, 2, 1],
@@ -468,22 +493,20 @@ describe('ol.geom.LineString', function() {
[15, -15, 30, 15],
[16, -16, 32, 16],
[18, -18, 36, 18],
[22, -22, 44, 22]
[22, -22, 44, 22],
]);
});
it('does contain XY', function() {
it('does contain XY', function () {
expect(lineString.containsXY(1, -1)).to.be(true);
expect(lineString.containsXY(16, -16)).to.be(true);
expect(lineString.containsXY(3, -3)).to.be(true);
});
it('does not contain XY', function() {
it('does not contain XY', function () {
expect(lineString.containsXY(1, 3)).to.be(false);
expect(lineString.containsXY(2, 2)).to.be(false);
expect(lineString.containsXY(2, 3)).to.be(false);
});
});
});
+486 -208
View File
@@ -1,353 +1,626 @@
import {isEmpty} from '../../../../src/ol/extent.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import MultiLineString from '../../../../src/ol/geom/MultiLineString.js';
import {isEmpty} from '../../../../src/ol/extent.js';
describe('ol.geom.MultiLineString', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.MultiLineString', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new MultiLineString(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let multiLineString;
beforeEach(function() {
beforeEach(function () {
multiLineString = new MultiLineString([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(multiLineString.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(multiLineString.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(multiLineString.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(2);
});
it('can append line strings', function() {
it('can append line strings', function () {
multiLineString.appendLineString(
new LineString([[1, 2], [3, 4]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]]]);
new LineString([
[1, 2],
[3, 4],
])
);
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
]);
multiLineString.appendLineString(
new LineString([[5, 6], [7, 8]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
new LineString([
[5, 6],
[7, 8],
])
);
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 7, 8]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(2);
});
describe('#getFlatMidpoints', function() {
it('returns the expected result', function() {
describe('#getFlatMidpoints', function () {
it('returns the expected result', function () {
expect(multiLineString.getFlatMidpoints()).to.eql([2, 3, 6, 7]);
});
});
describe('#intersectsExtent()', function() {
it('returns true for intersecting part of lineString', function() {
describe('#intersectsExtent()', function () {
it('returns true for intersecting part of lineString', function () {
expect(multiLineString.intersectsExtent([1, 2, 2, 3])).to.be(true);
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
expect(multiLineString.intersectsExtent([1, 7, 2, 8])).to.be(false);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(3);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let multiLineString;
beforeEach(function() {
beforeEach(function () {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
'XYM');
[
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
],
'XYM'
);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(3);
});
it('can return individual line strings', function() {
it('can return individual line strings', function () {
const lineString0 = multiLineString.getLineString(0);
expect(lineString0).to.be.an(LineString);
expect(lineString0.getLayout()).to.be('XYM');
expect(lineString0.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
expect(lineString0.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
const lineString1 = multiLineString.getLineString(1);
expect(lineString1).to.be.an(LineString);
expect(lineString1.getLayout()).to.be('XYM');
expect(lineString1.getCoordinates()).to.eql([[7, 8, 9], [10, 11, 12]]);
expect(lineString1.getCoordinates()).to.eql([
[7, 8, 9],
[10, 11, 12],
]);
});
describe('#getCoordinateAtM', function() {
describe('with extrapolation and interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, true)).to.eql(
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, true)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, true)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, true)).to.eql(
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, true, true)).to.eql(
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, true, true)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, true)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, true)).to.eql(
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, true)).to.eql(
[10, 11, 15]);
describe('#getCoordinateAtM', function () {
describe('with extrapolation and interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, true, true)).to.eql([
1,
2,
0,
]);
expect(multiLineString.getCoordinateAtM(3, true, true)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, true, true)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, true, true)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, true, true)).to.eql([
5.5,
6.5,
7.5,
]);
expect(multiLineString.getCoordinateAtM(9, true, true)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, true, true)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, true, true)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, true, true)).to.eql([
10,
11,
15,
]);
});
});
describe('with extrapolation and no interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, false)).to.eql(
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, false)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, false)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, false)).to.eql(
[4, 5, 6]);
describe('with extrapolation and no interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, true, false)).to.eql([
1,
2,
0,
]);
expect(multiLineString.getCoordinateAtM(3, true, false)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, true, false)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, true, false)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, true, false)).to.be(
null);
expect(multiLineString.getCoordinateAtM(9, true, false)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, false)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, false)).to.eql(
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, false)).to.eql(
[10, 11, 15]);
null
);
expect(multiLineString.getCoordinateAtM(9, true, false)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, true, false)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, true, false)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, true, false)).to.eql([
10,
11,
15,
]);
});
});
describe('with no extrapolation and interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, false, true)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(3, false, true)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, true)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, true)).to.eql(
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, false, true)).to.eql(
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, false, true)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, true)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, true)).to.eql(
[10, 11, 12]);
describe('with no extrapolation and interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, false, true)).to.eql(null);
expect(multiLineString.getCoordinateAtM(3, false, true)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, false, true)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, false, true)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, false, true)).to.eql([
5.5,
6.5,
7.5,
]);
expect(multiLineString.getCoordinateAtM(9, false, true)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, false, true)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, false, true)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, false, true)).to.eql(
null);
null
);
});
});
describe('with no extrapolation or interpolation', function() {
it('returns the expected value', function() {
describe('with no extrapolation or interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, false, false)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(3, false, false)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, false)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, false)).to.eql(
[4, 5, 6]);
null
);
expect(multiLineString.getCoordinateAtM(3, false, false)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, false, false)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, false, false)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, false, false)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(9, false, false)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, false)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, false)).to.eql(
[10, 11, 12]);
null
);
expect(multiLineString.getCoordinateAtM(9, false, false)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, false, false)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, false, false)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, false, false)).to.eql(
null);
null
);
});
});
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3, 4],
[5, 6, 7, 8],
],
[
[9, 10, 11, 12],
[13, 14, 15, 16],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3, 4],
[5, 6, 7, 8],
],
[
[9, 10, 11, 12],
[13, 14, 15, 16],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 13, 14]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(4);
});
});
describe('#scale()', function() {
it('scales a multi-linestring', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
describe('#scale()', function () {
it('scales a multi-linestring', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-100, -200], [100, 200]], [[50, -100], [-50, 100]]]);
expect(coordinates).to.eql([
[
[-100, -200],
[100, 200],
],
[
[50, -100],
[-50, 100],
],
]);
});
it('accepts sx and sy', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
it('accepts sx and sy', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-20, -60], [20, 60]], [[10, -30], [-10, 30]]]);
expect(coordinates).to.eql([
[
[-20, -60],
[20, 60],
],
[
[10, -30],
[-10, 30],
],
]);
});
it('accepts an anchor', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
it('accepts an anchor', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(3, 2, [10, 20]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-50, -60], [10, 20]], [[-5, -40], [-35, 0]]]);
expect(coordinates).to.eql([
[
[-50, -60],
[10, 20],
],
[
[-5, -40],
[-35, 0],
],
]);
});
});
describe('#setLineStrings', function() {
it('sets the line strings', function() {
const lineString1 = new LineString([[1, 2], [3, 4]]);
const lineString2 = new LineString([[5, 6], [7, 8]]);
describe('#setLineStrings', function () {
it('sets the line strings', function () {
const lineString1 = new LineString([
[1, 2],
[3, 4],
]);
const lineString2 = new LineString([
[5, 6],
[7, 8],
]);
const multiLineString = new MultiLineString([lineString1, lineString2]);
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
]);
expect(multiLineString.getEnds()).to.eql([4, 8]);
const coordinates = multiLineString.getCoordinates();
expect(coordinates[0]).to.eql(lineString1.getCoordinates());
@@ -355,15 +628,22 @@ describe('ol.geom.MultiLineString', function() {
});
});
describe('#containsXY()', function() {
describe('#containsXY()', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[-1, -1, 9], [2, 2, 12]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3],
[4, 5, 6],
],
[
[-1, -1, 9],
[2, 2, 12],
],
]);
});
it('does contain XY', function() {
it('does contain XY', function () {
expect(multiLineString.containsXY(1, 2)).to.be(true);
expect(multiLineString.containsXY(4, 5)).to.be(true);
expect(multiLineString.containsXY(3, 4)).to.be(true);
@@ -373,12 +653,10 @@ describe('ol.geom.MultiLineString', function() {
expect(multiLineString.containsXY(0, 0)).to.be(true);
});
it('does not contain XY', function() {
it('does not contain XY', function () {
expect(multiLineString.containsXY(1, 3)).to.be(false);
expect(multiLineString.containsXY(2, 11)).to.be(false);
expect(multiLineString.containsXY(-2, 3)).to.be(false);
});
});
});
+144 -108
View File
@@ -1,151 +1,163 @@
import {isEmpty} from '../../../../src/ol/extent.js';
import MultiPoint from '../../../../src/ol/geom/MultiPoint.js';
import Point from '../../../../src/ol/geom/Point.js';
import {isEmpty} from '../../../../src/ol/extent.js';
describe('ol.geom.MultiPoint', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.MultiPoint', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new MultiPoint(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let multiPoint;
beforeEach(function() {
beforeEach(function () {
multiPoint = new MultiPoint([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(multiPoint.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(multiPoint.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(multiPoint.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiPoint.getStride()).to.be(2);
});
it('can append points', function() {
it('can append points', function () {
multiPoint.appendPoint(new Point([1, 2]));
expect(multiPoint.getCoordinates()).to.eql([[1, 2]]);
multiPoint.appendPoint(new Point([3, 4]));
expect(multiPoint.getCoordinates()).to.eql([[1, 2], [3, 4]]);
expect(multiPoint.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2], [3, 4]]);
beforeEach(function () {
multiPoint = new MultiPoint([
[1, 2],
[3, 4],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2], [3, 4]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 3, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiPoint.getStride()).to.be(2);
});
describe('#intersectsExtent()', function() {
it('returns true for extent covering a point', function() {
describe('#intersectsExtent()', function () {
it('returns true for extent covering a point', function () {
expect(multiPoint.intersectsExtent([1, 2, 2, 2])).to.be(true);
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
expect(multiPoint.intersectsExtent([2, 3, 2, 4])).to.be(false);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2, 3], [4, 5, 6]]);
beforeEach(function () {
multiPoint = new MultiPoint([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(multiPoint.getStride()).to.be(3);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let multiPoint;
beforeEach(function() {
beforeEach(function () {
multiPoint = new MultiPoint(
[[1, 2, 3], [4, 5, 6]], 'XYM');
[
[1, 2, 3],
[4, 5, 6],
],
'XYM'
);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(multiPoint.getStride()).to.be(3);
});
it('can return individual points', function() {
it('can return individual points', function () {
const point0 = multiPoint.getPoint(0);
expect(point0.getLayout()).to.be('XYM');
expect(point0.getCoordinates()).to.eql([1, 2, 3]);
@@ -154,7 +166,7 @@ describe('ol.geom.MultiPoint', function() {
expect(point1.getCoordinates()).to.eql([4, 5, 6]);
});
it('can return all points', function() {
it('can return all points', function () {
const points = multiPoint.getPoints();
expect(points).to.have.length(2);
expect(points[0]).to.be.an(Point);
@@ -164,81 +176,100 @@ describe('ol.geom.MultiPoint', function() {
expect(points[1].getLayout()).to.be('XYM');
expect(points[1].getCoordinates()).to.eql([4, 5, 6]);
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2, 3, 4], [5, 6, 7, 8]]);
beforeEach(function () {
multiPoint = new MultiPoint([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3, 4], [5, 6, 7, 8]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 5, 6]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(multiPoint.getStride()).to.be(4);
});
describe('#getClosestPoint', function() {
it('preserves extra dimensions', function() {
describe('#getClosestPoint', function () {
it('preserves extra dimensions', function () {
const closestPoint = multiPoint.getClosestPoint([6, 6]);
expect(closestPoint).to.eql([5, 6, 7, 8]);
});
});
});
describe('#scale()', function() {
it('scales a multi-point', function() {
const geom = new MultiPoint([[-10, -20], [10, 20]]);
describe('#scale()', function () {
it('scales a multi-point', function () {
const geom = new MultiPoint([
[-10, -20],
[10, 20],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
expect(coordinates).to.eql([
[-100, -200],
[100, 200],
]);
});
it('accepts sx and sy', function() {
const geom = new MultiPoint([[-10, -20], [10, 20]]);
it('accepts sx and sy', function () {
const geom = new MultiPoint([
[-10, -20],
[10, 20],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
expect(coordinates).to.eql([
[-20, -60],
[20, 60],
]);
});
it('accepts an anchor', function() {
const geom = new MultiPoint([[-10, -20], [10, 20]]);
it('accepts an anchor', function () {
const geom = new MultiPoint([
[-10, -20],
[10, 20],
]);
geom.scale(3, 2, [-10, -20]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-10, -20], [50, 60]]);
expect(coordinates).to.eql([
[-10, -20],
[50, 60],
]);
});
});
describe('#applyTransform()', function() {
describe('#applyTransform()', function () {
let multi, transform;
beforeEach(function() {
multi = new MultiPoint([[1, 2], [3, 4]]);
beforeEach(function () {
multi = new MultiPoint([
[1, 2],
[3, 4],
]);
transform = sinon.spy();
});
it('calls a transform function', function() {
it('calls a transform function', function () {
multi.applyTransform(transform);
expect(transform.calledOnce).to.be(true);
const args = transform.firstCall.args;
@@ -249,8 +280,8 @@ describe('ol.geom.MultiPoint', function() {
expect(args[2]).to.be(2); // dimension
});
it('allows for modification of coordinates', function() {
const mod = function(input, output, dimension) {
it('allows for modification of coordinates', function () {
const mod = function (input, output, dimension) {
const copy = input.slice();
for (let i = 0, ii = copy.length; i < ii; i += dimension) {
output[i] = copy[i + 1];
@@ -258,21 +289,24 @@ describe('ol.geom.MultiPoint', function() {
}
};
multi.applyTransform(mod);
expect(multi.getCoordinates()).to.eql([[2, 1], [4, 3]]);
expect(multi.getCoordinates()).to.eql([
[2, 1],
[4, 3],
]);
});
it('returns undefined', function() {
it('returns undefined', function () {
const got = multi.applyTransform(transform);
expect(got).to.be(undefined);
});
});
describe('#transform()', function() {
it('transforms a geometry given CRS identifiers', function() {
const multi = new MultiPoint([[-111, 45], [111, -45]]).transform(
'EPSG:4326', 'EPSG:3857');
describe('#transform()', function () {
it('transforms a geometry given CRS identifiers', function () {
const multi = new MultiPoint([
[-111, 45],
[111, -45],
]).transform('EPSG:4326', 'EPSG:3857');
expect(multi).to.be.a(MultiPoint);
@@ -284,20 +318,24 @@ describe('ol.geom.MultiPoint', function() {
expect(coords[1][0]).to.roughlyEqual(12356463.47, 1e-2);
expect(coords[1][1]).to.roughlyEqual(-5621521.48, 1e-2);
});
});
describe('#containsXY()', function() {
it('does contain XY', function() {
const multi = new MultiPoint([[1, 2], [10, 20]]);
describe('#containsXY()', function () {
it('does contain XY', function () {
const multi = new MultiPoint([
[1, 2],
[10, 20],
]);
expect(multi.containsXY(1, 2)).to.be(true);
expect(multi.containsXY(10, 20)).to.be(true);
});
it('does not contain XY', function() {
const multi = new MultiPoint([[1, 2], [10, 20]]);
it('does not contain XY', function () {
const multi = new MultiPoint([
[1, 2],
[10, 20],
]);
expect(multi.containsXY(1, 3)).to.be(false);
expect(multi.containsXY(2, 2)).to.be(false);
@@ -307,7 +345,5 @@ describe('ol.geom.MultiPoint', function() {
expect(multi.containsXY(20, 20)).to.be(false);
expect(multi.containsXY(20, 30)).to.be(false);
});
});
});
+378 -138
View File
@@ -1,216 +1,456 @@
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
describe('ol.geom.MultiPolygon', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.MultiPolygon', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new MultiPolygon(null);
}).to.throwException();
});
describe('with a null MultiPolygon', function() {
it('can append polygons', function() {
describe('with a null MultiPolygon', function () {
it('can append polygons', function () {
const multiPolygon = new MultiPolygon([
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]])]);
expect(multiPolygon.getCoordinates()).to.eql(
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
multiPolygon.appendPolygon(
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
new Polygon([
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
]),
]);
expect(multiPolygon.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
]);
multiPolygon.appendPolygon(
new Polygon([
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
])
);
expect(multiPolygon.getCoordinates()).to.eql([
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
[
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
],
]);
expect(multiPolygon.getPolygons().length).to.eql(2);
});
});
describe('with an empty MultiPolygon', function() {
describe('with an empty MultiPolygon', function () {
let multiPolygon;
beforeEach(function() {
beforeEach(function () {
multiPolygon = new MultiPolygon([]);
});
it('can append polygons', function() {
it('can append polygons', function () {
multiPolygon.appendPolygon(
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
expect(multiPolygon.getCoordinates()).to.eql(
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
multiPolygon.appendPolygon(
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
new Polygon([
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
])
);
expect(multiPolygon.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
]);
multiPolygon.appendPolygon(
new Polygon([
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
])
);
expect(multiPolygon.getCoordinates()).to.eql([
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
[
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
],
]);
expect(multiPolygon.getPolygons().length).to.eql(2);
});
});
describe('#scale()', function() {
it('scales a multi-polygon', function() {
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
describe('#scale()', function () {
it('scales a multi-polygon', function () {
const geom = new MultiPolygon([
[
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]]);
});
it('accepts sx and sy', function() {
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]]);
});
it('accepts an anchor', function() {
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
geom.scale(3, 2, [-1, -2]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]]);
});
});
describe('with a simple MultiPolygon', function() {
let multiPolygon;
beforeEach(function() {
multiPolygon = new MultiPolygon([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
expect(coordinates).to.eql([
[
[
[-10, -20],
[10, -20],
[10, 20],
[-10, 20],
[-10, -20],
],
],
]);
});
it('can return individual polygons', function() {
const polygon0 = multiPolygon.getPolygon(0);
expect(polygon0).to.be.an(Polygon);
expect(polygon0.getCoordinates()).to.eql(
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
const polygon1 = multiPolygon.getPolygon(1);
expect(polygon1).to.be.an(Polygon);
expect(polygon1.getCoordinates()).to.eql(
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
it('accepts sx and sy', function () {
const geom = new MultiPolygon([
[
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([
[
[
[-2, -6],
[2, -6],
[2, 6],
[-2, 6],
[-2, -6],
],
],
]);
});
it('can return all polygons', function() {
it('accepts an anchor', function () {
const geom = new MultiPolygon([
[
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
],
]);
geom.scale(3, 2, [-1, -2]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([
[
[
[-1, -2],
[5, -2],
[5, 6],
[-1, 6],
[-1, -2],
],
],
]);
});
});
describe('with a simple MultiPolygon', function () {
let multiPolygon;
beforeEach(function () {
multiPolygon = new MultiPolygon([
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
[
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
],
]);
});
it('can return individual polygons', function () {
const polygon0 = multiPolygon.getPolygon(0);
expect(polygon0).to.be.an(Polygon);
expect(polygon0.getCoordinates()).to.eql([
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
]);
const polygon1 = multiPolygon.getPolygon(1);
expect(polygon1).to.be.an(Polygon);
expect(polygon1.getCoordinates()).to.eql([
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
]);
});
it('can return all polygons', function () {
const polygons = multiPolygon.getPolygons();
expect(polygons).to.be.an(Array);
expect(polygons).to.have.length(2);
expect(polygons[0]).to.be.an(Polygon);
expect(polygons[0].getCoordinates()).to.eql(
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
expect(polygons[0].getCoordinates()).to.eql([
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
]);
expect(polygons[1]).to.be.an(Polygon);
expect(polygons[1].getCoordinates()).to.eql(
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
expect(polygons[1].getCoordinates()).to.eql([
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
]);
});
describe('#clone()', function() {
it('has the expected endss_', function() {
describe('#clone()', function () {
it('has the expected endss_', function () {
const clone = multiPolygon.clone();
expect(multiPolygon.endss_).to.eql(clone.endss_);
});
});
describe('#getCoordinates()', function() {
describe('#getCoordinates()', function () {
const cw = [
[-180, -90],
[-180, 90],
[180, 90],
[180, -90],
[-180, -90],
];
const cw2 = [
[-140, -60],
[-140, 60],
[140, 60],
[140, -60],
[-140, -60],
];
const ccw = [
[-180, -90],
[180, -90],
[180, 90],
[-180, 90],
[-180, -90],
];
const ccw2 = [
[-140, -60],
[140, -60],
[140, 60],
[-140, 60],
[-140, -60],
];
const right = new MultiPolygon([
[ccw, cw],
[ccw2, cw2],
]);
const left = new MultiPolygon([
[cw, ccw],
[cw2, ccw2],
]);
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const cw2 = [[-140, -60], [-140, 60], [140, 60], [140, -60], [-140, -60]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
const ccw2 = [[-140, -60], [140, -60], [140, 60], [-140, 60], [-140, -60]];
const right = new MultiPolygon([[ccw, cw], [ccw2, cw2]]);
const left = new MultiPolygon([[cw, ccw], [cw2, ccw2]]);
it('returns coordinates as they were constructed', function() {
expect(right.getCoordinates()).to.eql([[ccw, cw], [ccw2, cw2]]);
expect(left.getCoordinates()).to.eql([[cw, ccw], [cw2, ccw2]]);
it('returns coordinates as they were constructed', function () {
expect(right.getCoordinates()).to.eql([
[ccw, cw],
[ccw2, cw2],
]);
expect(left.getCoordinates()).to.eql([
[cw, ccw],
[cw2, ccw2],
]);
});
it('can return coordinates with right-hand orientation', function() {
expect(right.getCoordinates(true)).to.eql([[ccw, cw], [ccw2, cw2]]);
expect(left.getCoordinates(true)).to.eql([[ccw, cw], [ccw2, cw2]]);
it('can return coordinates with right-hand orientation', function () {
expect(right.getCoordinates(true)).to.eql([
[ccw, cw],
[ccw2, cw2],
]);
expect(left.getCoordinates(true)).to.eql([
[ccw, cw],
[ccw2, cw2],
]);
});
it('can return coordinates with left-hand orientation', function() {
expect(right.getCoordinates(false)).to.eql([[cw, ccw], [cw2, ccw2]]);
expect(left.getCoordinates(false)).to.eql([[cw, ccw], [cw2, ccw2]]);
});
});
describe('#getExtent()', function() {
it('returns expected result', function() {
expect(multiPolygon.getExtent()).to.eql([0, 0, 5, 2]);
});
});
describe('#getSimplifiedGeometry', function() {
it('returns the expected result', function() {
const simplifiedGeometry = multiPolygon.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(MultiPolygon);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [2, 0]]],
[[[3, 0], [5, 2], [5, 0]]]
it('can return coordinates with left-hand orientation', function () {
expect(right.getCoordinates(false)).to.eql([
[cw, ccw],
[cw2, ccw2],
]);
expect(left.getCoordinates(false)).to.eql([
[cw, ccw],
[cw2, ccw2],
]);
});
});
describe('#intersectsExtent()', function() {
describe('#getExtent()', function () {
it('returns expected result', function () {
expect(multiPolygon.getExtent()).to.eql([0, 0, 5, 2]);
});
});
it('returns true for extent of of each polygon', function() {
describe('#getSimplifiedGeometry', function () {
it('returns the expected result', function () {
const simplifiedGeometry = multiPolygon.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(MultiPolygon);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[
[
[0, 0],
[0, 2],
[2, 0],
],
],
[
[
[3, 0],
[5, 2],
[5, 0],
],
],
]);
});
});
describe('#intersectsExtent()', function () {
it('returns true for extent of of each polygon', function () {
const polygons = multiPolygon.getPolygons();
for (let i = 0; i < polygons.length; i++) {
expect(multiPolygon.intersectsExtent(
polygons[i].getExtent())).to.be(true);
expect(multiPolygon.intersectsExtent(polygons[i].getExtent())).to.be(
true
);
}
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
expect(multiPolygon.intersectsExtent([2.1, 0, 2.9, 2])).to.be(false);
});
});
});
describe('#getArea', function() {
it('works with a clockwise and a counterclockwise Polygon', function() {
describe('#getArea', function () {
it('works with a clockwise and a counterclockwise Polygon', function () {
const multiPolygon = new MultiPolygon([
[[[1, 3], [1, 2], [0, 2], [1, 3]]], // clockwise polygon with area 0.5
[[[2, 1], [2, 0.5], [3, 1], [2, 1]]] // counterclockwise polygon with area 0.25
[
[
[1, 3],
[1, 2],
[0, 2],
[1, 3],
],
], // clockwise polygon with area 0.5
[
[
[2, 1],
[2, 0.5],
[3, 1],
[2, 1],
],
], // counterclockwise polygon with area 0.25
]);
expect(multiPolygon.getArea()).to.be(0.75);
});
});
describe('#getInteriorPoints', function() {
it('returns XYM multipoint with intersection width as M', function() {
describe('#getInteriorPoints', function () {
it('returns XYM multipoint with intersection width as M', function () {
const geom = new MultiPolygon([
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
[
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
[
[
[1, 1],
[1, 2],
[2, 2],
[2, 1],
[1, 1],
],
],
]);
const interiorPoints = geom.getInteriorPoints();
expect(interiorPoints.getType()).to.be('MultiPoint');
expect(interiorPoints.layout).to.be('XYM');
expect(interiorPoints.getCoordinates()).to.eql([[0.5, 0.5, 1], [1.5, 1.5, 1]]);
expect(interiorPoints.getCoordinates()).to.eql([
[0.5, 0.5, 1],
[1.5, 1.5, 1],
]);
});
});
});
+57 -76
View File
@@ -1,163 +1,153 @@
import Point from '../../../../src/ol/geom/Point.js';
import {get as getProjection, getTransformFromProjections} from '../../../../src/ol/proj.js';
import {
get as getProjection,
getTransformFromProjections,
} from '../../../../src/ol/proj.js';
describe('ol.geom.Point', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.Point', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new Point(null);
}).to.throwException();
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let point;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(point.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(point.getCoordinates()).to.eql([1, 2]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(point.getFlatCoordinates()).to.eql([1, 2]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(point.getStride()).to.be(2);
});
it('does not intersect non matching extent', function() {
it('does not intersect non matching extent', function () {
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
});
it('does intersect it\'s extent', function() {
it("does intersect it's extent", function () {
expect(point.intersectsExtent(point.getExtent())).to.be(true);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let point;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2, 3], 'XYM');
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(point.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(point.getCoordinates()).to.eql([1, 2, 3]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(point.getFlatCoordinates()).to.eql([1, 2, 3]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(point.getStride()).to.be(3);
});
it('does not intersect non matching extent', function() {
it('does not intersect non matching extent', function () {
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
});
it('does intersect it\'s extent', function() {
it("does intersect it's extent", function () {
expect(point.intersectsExtent(point.getExtent())).to.be(true);
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let point;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2, 3, 4]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(point.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(point.getCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(point.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(point.getStride()).to.be(4);
});
it('does not intersect non matching extent', function() {
it('does not intersect non matching extent', function () {
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
});
it('does intersect it\'s extent', function() {
it("does intersect it's extent", function () {
expect(point.intersectsExtent(point.getExtent())).to.be(true);
});
describe('#getClosestPoint', function() {
it('preseves extra dimensions', function() {
describe('#getClosestPoint', function () {
it('preseves extra dimensions', function () {
const closestPoint = point.getClosestPoint([0, 0]);
expect(closestPoint).to.eql([1, 2, 3, 4]);
});
});
});
describe('#scale()', function() {
it('scales a point', function() {
describe('#scale()', function () {
it('scales a point', function () {
const geom = new Point([1, 2]);
geom.scale(10e6);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([1, 2]);
});
it('accepts sx and sy', function() {
it('accepts sx and sy', function () {
const geom = new Point([1, 2]);
geom.scale(1e6, -42);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([1, 2]);
});
it('accepts an anchor', function() {
it('accepts an anchor', function () {
const geom = new Point([1, 2]);
geom.scale(10, 15, [0, 0]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([10, 30]);
});
});
describe('#simplifyTransformed()', function() {
it('returns the same result if called twice with the same arguments', function() {
describe('#simplifyTransformed()', function () {
it('returns the same result if called twice with the same arguments', function () {
const geom = new Point([1, 2]);
const source = getProjection('EPSG:4326');
const dest = getProjection('EPSG:3857');
@@ -168,7 +158,7 @@ describe('ol.geom.Point', function() {
expect(second).to.be(first);
});
it('returns a different result if called with a different tolerance', function() {
it('returns a different result if called with a different tolerance', function () {
const geom = new Point([1, 2]);
const source = getProjection('EPSG:4326');
const dest = getProjection('EPSG:3857');
@@ -179,7 +169,7 @@ describe('ol.geom.Point', function() {
expect(second).not.to.be(first);
});
it('returns a different result if called after geometry modification', function() {
it('returns a different result if called after geometry modification', function () {
const geom = new Point([1, 2]);
const source = getProjection('EPSG:4326');
const dest = getProjection('EPSG:3857');
@@ -191,18 +181,16 @@ describe('ol.geom.Point', function() {
const second = geom.simplifyTransformed(squaredTolerance * 2, transform);
expect(second).not.to.be(first);
});
});
describe('#applyTransform()', function() {
describe('#applyTransform()', function () {
let point, transform;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2]);
transform = sinon.spy();
});
it('calls a transform function', function() {
it('calls a transform function', function () {
point.applyTransform(transform);
expect(transform.calledOnce).to.be(true);
const args = transform.firstCall.args;
@@ -213,8 +201,8 @@ describe('ol.geom.Point', function() {
expect(args[2]).to.be(2); // dimension
});
it('allows for modification of coordinates', function() {
const mod = function(input, output, dimension) {
it('allows for modification of coordinates', function () {
const mod = function (input, output, dimension) {
const copy = input.slice();
output[1] = copy[0];
output[0] = copy[1];
@@ -223,18 +211,15 @@ describe('ol.geom.Point', function() {
expect(point.getCoordinates()).to.eql([2, 1]);
});
it('returns undefined', function() {
it('returns undefined', function () {
const got = point.applyTransform(transform);
expect(got).to.be(undefined);
});
});
describe('#transform()', function() {
it('transforms a geometry given CRS identifiers', function() {
const point = new Point([-111, 45]).transform(
'EPSG:4326', 'EPSG:3857');
describe('#transform()', function () {
it('transforms a geometry given CRS identifiers', function () {
const point = new Point([-111, 45]).transform('EPSG:4326', 'EPSG:3857');
expect(point).to.be.a(Point);
@@ -244,7 +229,7 @@ describe('ol.geom.Point', function() {
expect(coords[1]).to.roughlyEqual(5621521.48, 1e-2);
});
it('modifies the original', function() {
it('modifies the original', function () {
const point = new Point([-111, 45]);
point.transform('EPSG:4326', 'EPSG:3857');
const coords = point.getCoordinates();
@@ -252,25 +237,21 @@ describe('ol.geom.Point', function() {
expect(coords[0]).to.roughlyEqual(-12356463.47, 1e-2);
expect(coords[1]).to.roughlyEqual(5621521.48, 1e-2);
});
});
describe('#containsXY()', function() {
it('does contain XY', function() {
describe('#containsXY()', function () {
it('does contain XY', function () {
const point = new Point([1, 2]);
expect(point.containsXY(1, 2)).to.be(true);
});
it('does not contain XY', function() {
it('does not contain XY', function () {
const point = new Point([1, 2]);
expect(point.containsXY(1, 3)).to.be(false);
expect(point.containsXY(2, 2)).to.be(false);
expect(point.containsXY(2, 3)).to.be(false);
});
});
});
+376 -211
View File
@@ -1,64 +1,97 @@
import {isEmpty, boundingExtent} from '../../../../src/ol/extent.js';
import Circle from '../../../../src/ol/geom/Circle.js';
import LinearRing from '../../../../src/ol/geom/LinearRing.js';
import Polygon, {fromCircle, fromExtent} from '../../../../src/ol/geom/Polygon.js';
import Polygon, {
fromCircle,
fromExtent,
} from '../../../../src/ol/geom/Polygon.js';
import {boundingExtent, isEmpty} from '../../../../src/ol/extent.js';
describe('ol/geom/Polygon', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol/geom/Polygon', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new Polygon(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let polygon;
beforeEach(function() {
beforeEach(function () {
polygon = new Polygon([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(polygon.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(polygon.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(polygon.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(2);
});
it('can append linear rings', function() {
it('can append linear rings', function () {
polygon.appendLinearRing(
new LinearRing([[1, 2], [3, 4], [5, 6]]));
expect(polygon.getCoordinates()).to.eql(
[[[1, 2], [3, 4], [5, 6]]]);
new LinearRing([
[1, 2],
[3, 4],
[5, 6],
])
);
expect(polygon.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
[5, 6],
],
]);
polygon.appendLinearRing(
new LinearRing([[7, 8], [9, 10], [11, 12]]));
expect(polygon.getCoordinates()).to.eql(
[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]);
new LinearRing([
[7, 8],
[9, 10],
[11, 12],
])
);
expect(polygon.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
[5, 6],
],
[
[7, 8],
[9, 10],
[11, 12],
],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let outerRing, innerRing, polygon, flatCoordinates;
let outsideOuter, inside, insideInner;
beforeEach(function() {
outerRing = [[0, 1], [1, 4], [4, 3], [3, 0]];
innerRing = [[2, 2], [3, 2], [3, 3], [2, 3]];
beforeEach(function () {
outerRing = [
[0, 1],
[1, 4],
[4, 3],
[3, 0],
];
innerRing = [
[2, 2],
[3, 2],
[3, 3],
[2, 3],
];
polygon = new Polygon([outerRing, innerRing]);
flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0, 2, 2, 3, 2, 3, 3, 2, 3];
outsideOuter = [0, 4];
@@ -66,32 +99,32 @@ describe('ol/geom/Polygon', function() {
insideInner = [2.5, 3.5];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([outerRing, innerRing]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 4, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(2);
});
it('can return individual rings', function() {
it('can return individual rings', function () {
expect(polygon.getLinearRing(0).getCoordinates()).to.eql(outerRing);
expect(polygon.getLinearRing(1).getCoordinates()).to.eql(innerRing);
});
it('has the expected rings', function() {
it('has the expected rings', function () {
const linearRings = polygon.getLinearRings();
expect(linearRings).to.be.an(Array);
expect(linearRings).to.have.length(2);
@@ -101,7 +134,7 @@ describe('ol/geom/Polygon', function() {
expect(linearRings[1].getCoordinates()).to.eql(innerRing);
});
it('does not reverse any rings', function() {
it('does not reverse any rings', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
@@ -110,74 +143,88 @@ describe('ol/geom/Polygon', function() {
expect(coordinates[1]).to.eql(innerRing);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner)).to.be(false);
});
describe('#getCoordinates()', function() {
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
describe('#getCoordinates()', function () {
const cw = [
[-180, -90],
[-180, 90],
[180, 90],
[180, -90],
[-180, -90],
];
const ccw = [
[-180, -90],
[180, -90],
[180, 90],
[-180, 90],
[-180, -90],
];
const right = new Polygon([ccw, cw]);
const left = new Polygon([cw, ccw]);
it('returns coordinates as they were constructed', function() {
it('returns coordinates as they were constructed', function () {
expect(right.getCoordinates()).to.eql([ccw, cw]);
expect(left.getCoordinates()).to.eql([cw, ccw]);
});
it('can return coordinates with right-hand orientation', function() {
it('can return coordinates with right-hand orientation', function () {
expect(right.getCoordinates(true)).to.eql([ccw, cw]);
expect(left.getCoordinates(true)).to.eql([ccw, cw]);
});
it('can return coordinates with left-hand orientation', function() {
it('can return coordinates with left-hand orientation', function () {
expect(right.getCoordinates(false)).to.eql([cw, ccw]);
expect(left.getCoordinates(false)).to.eql([cw, ccw]);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let outerRing, innerRing, polygon, flatCoordinates;
let outsideOuter, inside, insideInner;
beforeEach(function() {
outerRing = [[0, 0, 1], [4, 4, 2], [4, 0, 3]];
innerRing = [[2, 1, 4], [3, 1, 5], [3, 2, 6]];
beforeEach(function () {
outerRing = [
[0, 0, 1],
[4, 4, 2],
[4, 0, 3],
];
innerRing = [
[2, 1, 4],
[3, 1, 5],
[3, 2, 6],
];
polygon = new Polygon([outerRing, innerRing]);
flatCoordinates = [0, 0, 1, 4, 4, 2, 4, 0, 3, 2, 1, 4, 3, 1, 5, 3, 2, 6];
outsideOuter = [1, 3];
@@ -185,203 +232,251 @@ describe('ol/geom/Polygon', function() {
insideInner = [2.9, 1.1];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([outerRing, innerRing]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 4, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(3);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner)).to.be(false);
});
describe('#intersectsExtent', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([outsideOuter]))).to.be(false);
describe('#intersectsExtent', function () {
it('does not intersect outside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([outsideOuter]))).to.be(
false
);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([inside]))).to.be(true);
it('does intersect inside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
it('does intersect boundary extent', function () {
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
expect(
polygon.intersectsExtent(boundingExtent([[firstMidX, firstMidY]]))
).to.be(true);
});
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
boundingExtent([insideInner]))).to.be(false);
it('does not intersect extent fully contained by inner ring', function () {
expect(polygon.intersectsExtent(boundingExtent([insideInner]))).to.be(
false
);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let outerRing, innerRing, polygon, flatCoordinates;
let outsideOuter, inside, insideInner;
beforeEach(function() {
outerRing = [[0, 0, 1], [4, 4, 2], [4, 0, 3]];
innerRing = [[2, 1, 4], [3, 1, 5], [3, 2, 6]];
polygon = new Polygon(
[outerRing, innerRing], 'XYM');
beforeEach(function () {
outerRing = [
[0, 0, 1],
[4, 4, 2],
[4, 0, 3],
];
innerRing = [
[2, 1, 4],
[3, 1, 5],
[3, 2, 6],
];
polygon = new Polygon([outerRing, innerRing], 'XYM');
flatCoordinates = [0, 0, 1, 4, 4, 2, 4, 0, 3, 2, 1, 4, 3, 1, 5, 3, 2, 6];
outsideOuter = [1, 3];
inside = [3.5, 0.5];
insideInner = [2.9, 1.1];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([outerRing, innerRing]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 4, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(3);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner)).to.be(false);
});
describe('#intersectsExtent', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([outsideOuter]))).to.be(false);
describe('#intersectsExtent', function () {
it('does not intersect outside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([outsideOuter]))).to.be(
false
);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([inside]))).to.be(true);
it('does intersect inside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
it('does intersect boundary extent', function () {
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
expect(
polygon.intersectsExtent(boundingExtent([[firstMidX, firstMidY]]))
).to.be(true);
});
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
boundingExtent([insideInner]))).to.be(false);
it('does not intersect extent fully contained by inner ring', function () {
expect(polygon.intersectsExtent(boundingExtent([insideInner]))).to.be(
false
);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let outerRing, innerRing1, innerRing2, polygon, flatCoordinates;
let outsideOuter, inside, insideInner1, insideInner2;
beforeEach(function() {
outerRing = [[0, 6, 1, 2], [6, 6, 3, 4], [3, 0, 5, 6]];
innerRing1 =
[[2, 4, 7, 8], [4, 4, 9, 10], [4, 5, 11, 12], [2, 5, 13, 14]];
innerRing2 = [[3, 2, 15, 16], [4, 3, 17, 18], [2, 3, 19, 20]];
beforeEach(function () {
outerRing = [
[0, 6, 1, 2],
[6, 6, 3, 4],
[3, 0, 5, 6],
];
innerRing1 = [
[2, 4, 7, 8],
[4, 4, 9, 10],
[4, 5, 11, 12],
[2, 5, 13, 14],
];
innerRing2 = [
[3, 2, 15, 16],
[4, 3, 17, 18],
[2, 3, 19, 20],
];
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
flatCoordinates = [
0, 6, 1, 2, 6, 6, 3, 4, 3, 0, 5, 6,
2, 4, 7, 8, 4, 4, 9, 10, 4, 5, 11, 12, 2, 5, 13, 14,
3, 2, 15, 16, 4, 3, 17, 18, 2, 3, 19, 20
0,
6,
1,
2,
6,
6,
3,
4,
3,
0,
5,
6,
2,
4,
7,
8,
4,
4,
9,
10,
4,
5,
11,
12,
2,
5,
13,
14,
3,
2,
15,
16,
4,
3,
17,
18,
2,
3,
19,
20,
];
outsideOuter = [1, 1];
inside = [3, 1];
@@ -389,161 +484,235 @@ describe('ol/geom/Polygon', function() {
insideInner2 = [3, 2.5];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(polygon.getCoordinates()).to.eql(
[outerRing, innerRing1, innerRing2]);
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([
outerRing,
innerRing1,
innerRing2,
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 6, 6]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(4);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner1)).to.be(false);
expect(polygon.intersectsCoordinate(insideInner2)).to.be(false);
});
describe('#intersectsExtent', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([outsideOuter]))).to.be(false);
describe('#intersectsExtent', function () {
it('does not intersect outside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([outsideOuter]))).to.be(
false
);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([inside]))).to.be(true);
it('does intersect inside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
it('does intersect boundary extent', function () {
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
expect(
polygon.intersectsExtent(boundingExtent([[firstMidX, firstMidY]]))
).to.be(true);
});
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
boundingExtent([insideInner1]))).to.be(false);
expect(polygon.intersectsExtent(
boundingExtent([insideInner2]))).to.be(false);
it('does not intersect extent fully contained by inner ring', function () {
expect(polygon.intersectsExtent(boundingExtent([insideInner1]))).to.be(
false
);
expect(polygon.intersectsExtent(boundingExtent([insideInner2]))).to.be(
false
);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing1.reverse();
innerRing2.reverse();
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing1.reverse();
innerRing2.reverse();
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('with a simple polygon', function() {
describe('with a simple polygon', function () {
let polygon;
beforeEach(function() {
polygon = new Polygon(
[[[3, 0], [1, 3], [0, 6], [2, 6], [3, 7], [4, 6], [6, 6], [4, 3]]]);
beforeEach(function () {
polygon = new Polygon([
[
[3, 0],
[1, 3],
[0, 6],
[2, 6],
[3, 7],
[4, 6],
[6, 6],
[4, 3],
],
]);
});
describe('#getSimplifiedGeometry', function() {
it('returns the expected result', function() {
describe('#getSimplifiedGeometry', function () {
it('returns the expected result', function () {
const simplifiedGeometry = polygon.getSimplifiedGeometry(9);
expect(simplifiedGeometry).to.be.an(Polygon);
expect(simplifiedGeometry.getCoordinates()).to.eql(
[[[3, 0], [0, 3], [0, 6], [6, 6], [3, 3]]]);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[
[3, 0],
[0, 3],
[0, 6],
[6, 6],
[3, 3],
],
]);
});
});
});
describe('#scale()', function() {
it('scales a polygon', function() {
describe('#scale()', function () {
it('scales a polygon', function () {
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]);
expect(coordinates).to.eql([
[
[-10, -20],
[10, -20],
[10, 20],
[-10, 20],
[-10, -20],
],
]);
});
it('accepts sx and sy', function() {
it('accepts sx and sy', function () {
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]);
expect(coordinates).to.eql([
[
[-2, -6],
[2, -6],
[2, 6],
[-2, 6],
[-2, -6],
],
]);
});
it('accepts an anchor', function() {
it('accepts an anchor', function () {
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
]);
geom.scale(3, 2, [-1, -2]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]);
expect(coordinates).to.eql([
[
[-1, -2],
[5, -2],
[5, 6],
[-1, 6],
[-1, -2],
],
]);
});
});
describe('#getInteriorPoint', function() {
it('returns XYM point with intersection width as M', function() {
const geom = new Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
describe('#getInteriorPoint', function () {
it('returns XYM point with intersection width as M', function () {
const geom = new Polygon([
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
]);
const interiorPoint = geom.getInteriorPoint();
expect(interiorPoint.getType()).to.be('Point');
expect(interiorPoint.layout).to.be('XYM');
expect(interiorPoint.getCoordinates()).to.eql([0.5, 0.5, 1]);
});
it('returns XYM point for donut polygons', function() {
it('returns XYM point for donut polygons', function () {
const geom = new Polygon([
[[0.5, 0.5], [0.5, 2.5], [2.5, 2.5], [2.5, 0.5], [0.5, 0.5]],
[[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]
[
[0.5, 0.5],
[0.5, 2.5],
[2.5, 2.5],
[2.5, 0.5],
[0.5, 0.5],
],
[
[1, 1],
[2, 1],
[2, 2],
[1, 2],
[1, 1],
],
]);
const interiorPoint = geom.getInteriorPoint();
expect(interiorPoint.getType()).to.be('Point');
@@ -552,22 +721,19 @@ describe('ol/geom/Polygon', function() {
});
});
describe('fromExtent()', function() {
it('creates the correct polygon', function() {
describe('fromExtent()', function () {
it('creates the correct polygon', function () {
const extent = [1, 2, 3, 5];
const polygon = fromExtent(extent);
const flatCoordinates = polygon.getFlatCoordinates();
expect(flatCoordinates).to.eql(
[1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
expect(flatCoordinates).to.eql([1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
const orientedFlatCoordinates = polygon.getOrientedFlatCoordinates();
expect(orientedFlatCoordinates).to.eql(
[1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
expect(orientedFlatCoordinates).to.eql([1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
});
});
describe('fromCircle()', function() {
it('creates a regular polygon', function() {
describe('fromCircle()', function () {
it('creates a regular polygon', function () {
const circle = new Circle([0, 0, 0], 1, 'XYZ');
const polygon = fromCircle(circle);
const coordinates = polygon.getLinearRing(0).getCoordinates();
@@ -588,7 +754,7 @@ describe('ol/geom/Polygon', function() {
expect(coordinates[24][1]).to.roughlyEqual(-1, 1e-9);
});
it('creates a regular polygon with custom sides and angle', function() {
it('creates a regular polygon with custom sides and angle', function () {
const circle = new Circle([0, 0], 1);
const polygon = fromCircle(circle, 4, Math.PI / 2);
const coordinates = polygon.getLinearRing(0).getCoordinates();
@@ -605,5 +771,4 @@ describe('ol/geom/Polygon', function() {
expect(coordinates[0][3]).to.eql(1);
});
});
});
+94 -57
View File
@@ -1,28 +1,32 @@
import Feature from '../../../src/ol/Feature.js';
import Graticule from '../../../src/ol/layer/Graticule.js';
import Map from '../../../src/ol/Map.js';
import {fromLonLat, get as getProjection} from '../../../src/ol/proj.js';
import Stroke from '../../../src/ol/style/Stroke.js';
import Text from '../../../src/ol/style/Text.js';
import Feature from '../../../src/ol/Feature.js';
import {fromLonLat, get as getProjection} from '../../../src/ol/proj.js';
describe('ol.layer.Graticule', function() {
describe('ol.layer.Graticule', function () {
let graticule;
function createGraticule() {
graticule = new Graticule();
new Map({
layers: [graticule]
layers: [graticule],
});
}
describe('#createGraticule', function() {
it('creates a graticule without labels', function() {
describe('#createGraticule', function () {
it('creates a graticule without labels', function () {
createGraticule();
const extent = [-25614353.926475704, -7827151.696402049,
25614353.926475704, 7827151.696402049];
const extent = [
-25614353.926475704,
-7827151.696402049,
25614353.926475704,
7827151.696402049,
];
const projection = getProjection('EPSG:3857');
const resolution = 39135.75848201024;
const squaredTolerance = resolution * resolution / 4.0;
const squaredTolerance = (resolution * resolution) / 4.0;
graticule.updateProjectionInfo_(projection);
graticule.createGraticule_(extent, [0, 0], resolution, squaredTolerance);
expect(graticule.getMeridians().length).to.be(13);
@@ -31,17 +35,21 @@ describe('ol.layer.Graticule', function() {
expect(graticule.parallelsLabels_).to.be(null);
});
it('creates a graticule with normal world labels', function() {
it('creates a graticule with normal world labels', function () {
const feature = new Feature();
graticule = new Graticule({
showLabels: true,
wrapX: false
wrapX: false,
});
new Map({
layers: [graticule]
layers: [graticule],
});
const extent = [-25614353.926475704, -7827151.696402049,
25614353.926475704, 7827151.696402049];
const extent = [
-25614353.926475704,
-7827151.696402049,
25614353.926475704,
7827151.696402049,
];
const projection = getProjection('EPSG:3857');
const resolution = 39135.75848201024;
graticule.loaderFunction(extent, resolution, projection);
@@ -55,33 +63,45 @@ describe('ol.layer.Graticule', function() {
viewState: {
projection: projection,
resolution: resolution,
rotation: 0
}
}
rotation: 0,
},
},
};
graticule.drawLabels_(event);
expect(graticule.meridiansLabels_.length).to.be(13);
expect(graticule.meridiansLabels_[0].text).to.be('0° 00 00″');
expect(graticule.meridiansLabels_[0].geom.getCoordinates()[0]).to.roughlyEqual(0, 1e-9);
expect(
graticule.meridiansLabels_[0].geom.getCoordinates()[0]
).to.roughlyEqual(0, 1e-9);
expect(graticule.parallelsLabels_.length).to.be(3);
expect(graticule.parallelsLabels_[0].text).to.be('0° 00 00″');
expect(graticule.parallelsLabels_[0].geom.getCoordinates()[1]).to.roughlyEqual(0, 1e-9);
expect(
graticule.parallelsLabels_[0].geom.getCoordinates()[1]
).to.roughlyEqual(0, 1e-9);
feature.set('graticule_label', graticule.meridiansLabels_[0].text);
expect(graticule.lonLabelStyle_(feature).getText().getText()).to.be('0° 00 00″');
expect(graticule.lonLabelStyle_(feature).getText().getText()).to.be(
'0° 00 00″'
);
feature.set('graticule_label', graticule.parallelsLabels_[0].text);
expect(graticule.latLabelStyle_(feature).getText().getText()).to.be('0° 00 00″');
expect(graticule.latLabelStyle_(feature).getText().getText()).to.be(
'0° 00 00″'
);
});
it('creates a graticule with wrapped world labels', function() {
it('creates a graticule with wrapped world labels', function () {
const feature = new Feature();
graticule = new Graticule({
showLabels: true
showLabels: true,
});
new Map({
layers: [graticule]
layers: [graticule],
});
const extent = [-25614353.926475704, -7827151.696402049,
25614353.926475704, 7827151.696402049];
const extent = [
-25614353.926475704,
-7827151.696402049,
25614353.926475704,
7827151.696402049,
];
const projection = getProjection('EPSG:3857');
const resolution = 39135.75848201024;
graticule.loaderFunction(extent, resolution, projection);
@@ -95,25 +115,33 @@ describe('ol.layer.Graticule', function() {
viewState: {
projection: projection,
resolution: resolution,
rotation: 0
}
}
rotation: 0,
},
},
};
graticule.drawLabels_(event);
expect(graticule.meridiansLabels_.length).to.be(13);
expect(graticule.meridiansLabels_[0].text).to.be('0° 00 00″');
const coordinates = fromLonLat([360, 0]);
expect(graticule.meridiansLabels_[0].geom.getCoordinates()[0]).to.roughlyEqual(coordinates[0], 1e-9);
expect(
graticule.meridiansLabels_[0].geom.getCoordinates()[0]
).to.roughlyEqual(coordinates[0], 1e-9);
expect(graticule.parallelsLabels_.length).to.be(3);
expect(graticule.parallelsLabels_[0].text).to.be('0° 00 00″');
expect(graticule.parallelsLabels_[0].geom.getCoordinates()[1]).to.roughlyEqual(0, 1e-9);
expect(
graticule.parallelsLabels_[0].geom.getCoordinates()[1]
).to.roughlyEqual(0, 1e-9);
feature.set('graticule_label', graticule.meridiansLabels_[0].text);
expect(graticule.lonLabelStyle_(feature).getText().getText()).to.be('0° 00 00″');
expect(graticule.lonLabelStyle_(feature).getText().getText()).to.be(
'0° 00 00″'
);
feature.set('graticule_label', graticule.parallelsLabels_[0].text);
expect(graticule.latLabelStyle_(feature).getText().getText()).to.be('0° 00 00″');
expect(graticule.latLabelStyle_(feature).getText().getText()).to.be(
'0° 00 00″'
);
});
it('has a default stroke style', function() {
it('has a default stroke style', function () {
createGraticule();
const actualStyle = graticule.strokeStyle_;
@@ -121,14 +149,14 @@ describe('ol.layer.Graticule', function() {
expect(actualStyle instanceof Stroke).to.be(true);
});
it('can be configured with a stroke style', function() {
it('can be configured with a stroke style', function () {
createGraticule();
const customStrokeStyle = new Stroke({
color: 'rebeccapurple'
color: 'rebeccapurple',
});
const styledGraticule = new Graticule({
map: new Map({}),
strokeStyle: customStrokeStyle
strokeStyle: customStrokeStyle,
});
const actualStyle = styledGraticule.strokeStyle_;
@@ -136,29 +164,33 @@ describe('ol.layer.Graticule', function() {
expect(actualStyle).to.be(customStrokeStyle);
});
it('can be configured with label options', function() {
it('can be configured with label options', function () {
const latLabelStyle = new Text();
const lonLabelStyle = new Text();
const feature = new Feature();
graticule = new Graticule({
map: new Map({}),
showLabels: true,
lonLabelFormatter: function(lon) {
lonLabelFormatter: function (lon) {
return 'lon: ' + lon.toString();
},
latLabelFormatter: function(lat) {
latLabelFormatter: function (lat) {
return 'lat: ' + lat.toString();
},
lonLabelPosition: 0.9,
latLabelPosition: 0.1,
lonLabelStyle: lonLabelStyle,
latLabelStyle: latLabelStyle
latLabelStyle: latLabelStyle,
});
const extent = [-25614353.926475704, -7827151.696402049,
25614353.926475704, 7827151.696402049];
const extent = [
-25614353.926475704,
-7827151.696402049,
25614353.926475704,
7827151.696402049,
];
const projection = getProjection('EPSG:3857');
const resolution = 39135.75848201024;
const squaredTolerance = resolution * resolution / 4.0;
const squaredTolerance = (resolution * resolution) / 4.0;
graticule.updateProjectionInfo_(projection);
graticule.createGraticule_(extent, [0, 0], resolution, squaredTolerance);
expect(graticule.meridiansLabels_[0].text).to.be('lon: 0');
@@ -166,32 +198,40 @@ describe('ol.layer.Graticule', function() {
expect(graticule.lonLabelStyle_(feature).getText()).to.eql(lonLabelStyle);
expect(graticule.latLabelStyle_(feature).getText()).to.eql(latLabelStyle);
feature.set('graticule_label', graticule.meridiansLabels_[0].text);
expect(graticule.lonLabelStyle_(feature).getText().getText()).to.be('lon: 0');
expect(graticule.lonLabelStyle_(feature).getText().getText()).to.be(
'lon: 0'
);
feature.set('graticule_label', graticule.parallelsLabels_[0].text);
expect(graticule.latLabelStyle_(feature).getText().getText()).to.be('lat: 0');
expect(graticule.latLabelStyle_(feature).getText().getText()).to.be(
'lat: 0'
);
expect(graticule.lonLabelPosition_).to.be(0.9);
expect(graticule.latLabelPosition_).to.be(0.1);
});
it('can be configured with interval limits', function() {
it('can be configured with interval limits', function () {
graticule = new Graticule({
showLabels: true,
lonLabelFormatter: function(lon) {
lonLabelFormatter: function (lon) {
return lon.toString();
},
latLabelFormatter: function(lat) {
latLabelFormatter: function (lat) {
return lat.toString();
},
intervals: [10]
intervals: [10],
});
new Map({
layers: [graticule]
layers: [graticule],
});
const extent = [-25614353.926475704, -7827151.696402049,
25614353.926475704, 7827151.696402049];
const extent = [
-25614353.926475704,
-7827151.696402049,
25614353.926475704,
7827151.696402049,
];
const projection = getProjection('EPSG:3857');
const resolution = 4891.96981025128;
const squaredTolerance = resolution * resolution / 4.0;
const squaredTolerance = (resolution * resolution) / 4.0;
graticule.updateProjectionInfo_(projection);
graticule.createGraticule_(extent, [0, 0], resolution, squaredTolerance);
@@ -205,8 +245,5 @@ describe('ol.layer.Graticule', function() {
expect(graticule.getMeridians().length).to.be(37);
expect(graticule.getParallels().length).to.be(11);
});
});
});
+10 -12
View File
@@ -1,57 +1,55 @@
import {listenImage} from '../../../src/ol/Image.js';
describe('HTML Image loading', function() {
describe('HTML Image loading', function () {
let handleLoad, handleError, img;
beforeEach(function() {
beforeEach(function () {
handleLoad = sinon.spy();
handleError = sinon.spy();
img = new Image();
});
it('handles load event', function(done) {
it('handles load event', function (done) {
img.src = 'spec/ol/data/dot.png';
listenImage(img, handleLoad, handleError);
setTimeout(function() {
setTimeout(function () {
expect(handleLoad.called).to.be(true);
expect(handleError.called).to.be(false);
done();
}, 200);
});
it('handles load event when src is set later', function(done) {
it('handles load event when src is set later', function (done) {
listenImage(img, handleLoad, handleError);
img.src = 'spec/ol/data/dot.png';
setTimeout(function() {
setTimeout(function () {
expect(handleLoad.called).to.be(true);
expect(handleError.called).to.be(false);
done();
}, 200);
});
it('handles error event', function(done) {
it('handles error event', function (done) {
img.src = 'invalid.jpeg';
listenImage(img, handleLoad, handleError);
setTimeout(function() {
setTimeout(function () {
expect(handleLoad.called).to.be(false);
expect(handleError.called).to.be(true);
done();
}, 500);
});
it('handles cancelation', function(done) {
it('handles cancelation', function (done) {
img.src = 'spec/ol/data/dot.png';
listenImage(img, handleLoad, handleError)();
setTimeout(function() {
setTimeout(function () {
expect(handleLoad.called).to.be(false);
expect(handleError.called).to.be(false);
done();
}, 200);
});
});
+10 -15
View File
@@ -1,15 +1,12 @@
import EventType from '../../../src/ol/events/EventType.js';
import ImageTile from '../../../src/ol/ImageTile.js';
import TileState from '../../../src/ol/TileState.js';
import {listen, unlistenByKey} from '../../../src/ol/events.js';
import EventType from '../../../src/ol/events/EventType.js';
import {defaultImageLoadFunction} from '../../../src/ol/source/Image.js';
import {listen, unlistenByKey} from '../../../src/ol/events.js';
describe('ol.ImageTile', function() {
describe('#load()', function() {
it('can load idle tile', function(done) {
describe('ol.ImageTile', function () {
describe('#load()', function () {
it('can load idle tile', function (done) {
const tileCoord = [0, 0, 0];
const state = TileState.IDLE;
const src = 'spec/ol/data/osm-0-0-0.png';
@@ -18,7 +15,7 @@ describe('ol.ImageTile', function() {
let previousState = tile.getState();
listen(tile, EventType.CHANGE, function(event) {
listen(tile, EventType.CHANGE, function (event) {
const state = tile.getState();
if (previousState == TileState.IDLE) {
expect(state).to.be(TileState.LOADING);
@@ -34,7 +31,7 @@ describe('ol.ImageTile', function() {
tile.load();
});
it('can load error tile', function(done) {
it('can load error tile', function (done) {
const tileCoord = [0, 0, 0];
const state = TileState.ERROR;
const src = 'spec/ol/data/osm-0-0-0.png';
@@ -43,7 +40,7 @@ describe('ol.ImageTile', function() {
let previousState = tile.getState();
listen(tile, EventType.CHANGE, function(event) {
listen(tile, EventType.CHANGE, function (event) {
const state = tile.getState();
if (previousState == TileState.ERROR) {
expect(state).to.be(TileState.LOADING);
@@ -59,14 +56,14 @@ describe('ol.ImageTile', function() {
tile.load();
});
it('loads an empty image on error ', function(done) {
it('loads an empty image on error ', function (done) {
const tileCoord = [0, 0, 0];
const state = TileState.IDLE;
const src = 'spec/ol/data/osm-0-0-99.png';
const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
const key = listen(tile, EventType.CHANGE, function(event) {
const key = listen(tile, EventType.CHANGE, function (event) {
const state = tile.getState();
if (state == TileState.ERROR) {
expect(state).to.be(TileState.ERROR);
@@ -80,7 +77,5 @@ describe('ol.ImageTile', function() {
tile.load();
});
});
});
+3 -3
View File
@@ -1,12 +1,12 @@
import {getUid} from '../../../src/ol/util.js';
describe('getUid()', function() {
it('is constant once generated', function() {
describe('getUid()', function () {
it('is constant once generated', function () {
const a = {};
expect(getUid(a)).to.be(getUid(a));
});
it('generates a strictly increasing sequence', function() {
it('generates a strictly increasing sequence', function () {
const a = {};
const b = {};
const c = {};
+33 -35
View File
@@ -1,51 +1,50 @@
import View from '../../../../src/ol/View.js';
import DragAndDrop from '../../../../src/ol/interaction/DragAndDrop.js';
import Event from '../../../../src/ol/events/Event.js';
import EventTarget from '../../../../src/ol/events/Target.js';
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
import DragAndDrop from '../../../../src/ol/interaction/DragAndDrop.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import View from '../../../../src/ol/View.js';
where('FileReader').describe('ol.interaction.DragAndDrop', function() {
where('FileReader').describe('ol.interaction.DragAndDrop', function () {
let viewport, map, interaction;
beforeEach(function() {
beforeEach(function () {
viewport = new EventTarget();
map = {
getViewport: function() {
getViewport: function () {
return viewport;
},
getView: function() {
getView: function () {
return new View();
}
},
};
interaction = new DragAndDrop({
formatConstructors: [GeoJSON]
formatConstructors: [GeoJSON],
});
});
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const interaction = new DragAndDrop();
expect(interaction).to.be.an(DragAndDrop);
});
it('sets formatConstructors on the instance', function() {
it('sets formatConstructors on the instance', function () {
expect(interaction.formatConstructors_).to.have.length(1);
});
it('accepts a source option', function() {
it('accepts a source option', function () {
const source = new VectorSource();
const drop = new DragAndDrop({
formatConstructors: [GeoJSON],
source: source
source: source,
});
expect(drop.source_).to.equal(source);
});
});
describe('#setActive()', function() {
it('registers and unregisters listeners', function() {
describe('#setActive()', function () {
it('registers and unregisters listeners', function () {
interaction.setMap(map);
interaction.setActive(true);
expect(viewport.hasListener('dragenter')).to.be(true);
@@ -58,8 +57,8 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
});
});
describe('#setMap()', function() {
it('registers and unregisters listeners', function() {
describe('#setMap()', function () {
it('registers and unregisters listeners', function () {
interaction.setMap(map);
expect(viewport.hasListener('dragenter')).to.be(true);
expect(viewport.hasListener('dragover')).to.be(true);
@@ -70,11 +69,11 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
expect(viewport.hasListener('drop')).to.be(false);
});
it('registers and unregisters listeners on a custom target', function() {
it('registers and unregisters listeners on a custom target', function () {
const customTarget = new EventTarget();
interaction = new DragAndDrop({
formatConstructors: [GeoJSON],
target: customTarget
target: customTarget,
});
interaction.setMap(map);
expect(customTarget.hasListener('dragenter')).to.be(true);
@@ -87,10 +86,10 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
});
});
describe('#handleDrop_', function() {
describe('#handleDrop_', function () {
let OrigFileReader;
beforeEach(function() {
beforeEach(function () {
OrigFileReader = FileReader;
class MockFileReader extends EventTarget {
@@ -105,12 +104,12 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
FileReader = MockFileReader;
});
afterEach(function() {
afterEach(function () {
FileReader = OrigFileReader;
});
it('reads dropped files', function(done) {
interaction.on('addfeatures', function(evt) {
it('reads dropped files', function (done) {
interaction.on('addfeatures', function (evt) {
expect(evt.features.length).to.be(1);
done();
});
@@ -124,27 +123,27 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
event.type = 'drop';
event.dataTransfer.files = {
length: 1,
item: function() {
item: function () {
return JSON.stringify({
type: 'FeatureCollection',
features: [{type: 'Feature', id: '1'}]
features: [{type: 'Feature', id: '1'}],
});
}
},
};
viewport.dispatchEvent(event);
expect(event.dataTransfer.dropEffect).to.be('copy');
expect(event.propagationStopped).to.be(true);
});
it('adds dropped features to a source', function(done) {
it('adds dropped features to a source', function (done) {
const source = new VectorSource();
const drop = new DragAndDrop({
formatConstructors: [GeoJSON],
source: source
source: source,
});
drop.setMap(map);
drop.on('addfeatures', function(evt) {
drop.on('addfeatures', function (evt) {
const features = source.getFeatures();
expect(features.length).to.be(1);
done();
@@ -159,17 +158,16 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
event.type = 'drop';
event.dataTransfer.files = {
length: 1,
item: function() {
item: function () {
return JSON.stringify({
type: 'FeatureCollection',
features: [{type: 'Feature', id: '1'}]
features: [{type: 'Feature', id: '1'}],
});
}
},
};
viewport.dispatchEvent(event);
expect(event.dataTransfer.dropEffect).to.be('copy');
expect(event.propagationStopped).to.be(true);
});
});
});
@@ -1,30 +1,26 @@
import DragRotateAndZoom from '../../../../src/ol/interaction/DragRotateAndZoom.js';
import Event from '../../../../src/ol/events/Event.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js';
import DragRotateAndZoom from '../../../../src/ol/interaction/DragRotateAndZoom.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import Event from '../../../../src/ol/events/Event.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import View from '../../../../src/ol/View.js';
describe('ol.interaction.DragRotateAndZoom', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.interaction.DragRotateAndZoom', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new DragRotateAndZoom();
expect(instance).to.be.an(DragRotateAndZoom);
});
});
describe('#handleDragEvent()', function() {
describe('#handleDragEvent()', function () {
let target, map, interaction;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
style.position = 'absolute';
@@ -43,32 +39,37 @@ describe('ol.interaction.DragRotateAndZoom', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.once('postrender', function() {
map.once('postrender', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
});
it('does not rotate when rotation is disabled on the view', function() {
it('does not rotate when rotation is disabled on the view', function () {
const pointerEvent = new Event();
pointerEvent.type = 'pointermove';
pointerEvent.clientX = 20;
pointerEvent.clientY = 10;
pointerEvent.pointerType = 'mouse';
let event = new MapBrowserPointerEvent('pointermove', map, pointerEvent, true);
let event = new MapBrowserPointerEvent(
'pointermove',
map,
pointerEvent,
true
);
interaction.lastAngle_ = Math.PI;
let callCount = 0;
let view = map.getView();
view.on('change:rotation', function() {
view.on('change:rotation', function () {
callCount++;
});
@@ -81,10 +82,10 @@ describe('ol.interaction.DragRotateAndZoom', function() {
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1,
enableRotation: false
enableRotation: false,
});
map.setView(view);
view.on('change:rotation', function() {
view.on('change:rotation', function () {
callCount++;
});
@@ -92,11 +93,15 @@ describe('ol.interaction.DragRotateAndZoom', function() {
pointerEvent.clientX = 24;
pointerEvent.clientY = 16;
pointerEvent.pointerType = 'mouse';
event = new MapBrowserPointerEvent('pointermove', map, pointerEvent, true);
event = new MapBrowserPointerEvent(
'pointermove',
map,
pointerEvent,
true
);
interaction.handleDragEvent(event);
expect(callCount).to.be(0);
});
});
});
+22 -32
View File
@@ -1,21 +1,19 @@
import DragZoom from '../../../../src/ol/interaction/DragZoom.js';
import Map from '../../../../src/ol/Map.js';
import RenderBox from '../../../../src/ol/render/Box.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import View from '../../../../src/ol/View.js';
import {getCenter} from '../../../../src/ol/extent.js';
import {fromExtent as polygonFromExtent} from '../../../../src/ol/geom/Polygon.js';
import DragZoom from '../../../../src/ol/interaction/DragZoom.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import RenderBox from '../../../../src/ol/render/Box.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
describe('ol.interaction.DragZoom', function() {
describe('ol.interaction.DragZoom', function () {
let target, map, source;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
style.position = 'absolute';
@@ -32,41 +30,38 @@ describe('ol.interaction.DragZoom', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.once('postrender', function() {
map.once('postrender', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
});
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new DragZoom();
expect(instance).to.be.an(DragZoom);
});
it('sets "ol-dragzoom" as box className', function() {
it('sets "ol-dragzoom" as box className', function () {
const instance = new DragZoom();
expect(instance.box_.element_.className).to.be('ol-box ol-dragzoom');
});
it('sets a custom box className', function() {
it('sets a custom box className', function () {
const instance = new DragZoom({className: 'test-dragzoom'});
expect(instance.box_.element_.className).to.be('ol-box test-dragzoom');
});
});
describe('#onBoxEnd()', function() {
it('centers the view on the box geometry', function(done) {
describe('#onBoxEnd()', function () {
it('centers the view on the box geometry', function (done) {
const interaction = new DragZoom({
duration: 10
duration: 10,
});
map.addInteraction(interaction);
@@ -76,19 +71,18 @@ describe('ol.interaction.DragZoom', function() {
interaction.box_ = box;
interaction.onBoxEnd_();
setTimeout(function() {
setTimeout(function () {
const view = map.getView();
const center = view.getCenterInternal();
expect(center).to.eql(getCenter(extent));
done();
}, 50);
});
it('sets new resolution while zooming out', function(done) {
it('sets new resolution while zooming out', function (done) {
const interaction = new DragZoom({
duration: 10,
out: true
out: true,
});
map.addInteraction(interaction);
@@ -98,19 +92,15 @@ describe('ol.interaction.DragZoom', function() {
interaction.box_ = box;
map.getView().setResolution(0.25);
setTimeout(function() {
setTimeout(function () {
interaction.onBoxEnd_();
setTimeout(function() {
setTimeout(function () {
const view = map.getView();
const resolution = view.getResolution();
expect(resolution).to.eql(view.getConstrainedResolution(0.5));
done();
}, 50);
}, 50);
});
});
});
File diff suppressed because it is too large Load Diff
+20 -23
View File
@@ -1,15 +1,15 @@
import ExtentInteraction from '../../../../src/ol/interaction/Extent.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js';
import ExtentInteraction from '../../../../src/ol/interaction/Extent.js';
describe('ol.interaction.Extent', function() {
describe('ol.interaction.Extent', function () {
let map, interaction;
const width = 360;
const height = 180;
beforeEach(function() {
beforeEach(function () {
const target = createMapDiv(width, height);
map = new Map({
@@ -18,8 +18,8 @@ describe('ol.interaction.Extent', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.renderSync();
@@ -27,7 +27,7 @@ describe('ol.interaction.Extent', function() {
map.addInteraction(interaction);
});
afterEach(function() {
afterEach(function () {
if (map) {
disposeMap(map);
}
@@ -57,33 +57,31 @@ describe('ol.interaction.Extent', function() {
pointerEvent.clientY = position.top - y + height / 2;
pointerEvent.shiftKey = shiftKey;
pointerEvent.pointerId = 0;
pointerEvent.preventDefault = function() {};
pointerEvent.preventDefault = function () {};
const event = new MapBrowserPointerEvent(type, map, pointerEvent);
event.pointerEvent.pointerId = 1;
map.handleMapBrowserEvent(event);
}
describe('Constructor', function() {
it('can be configured with an extent', function() {
expect(function() {
describe('Constructor', function () {
it('can be configured with an extent', function () {
expect(function () {
new ExtentInteraction({
extent: [-10, -10, 10, 10]
extent: [-10, -10, 10, 10],
});
}).to.not.throwException();
});
});
describe('snap to vertex', function() {
it('snap to vertex works', function() {
describe('snap to vertex', function () {
it('snap to vertex works', function () {
interaction.setExtent([-50, -50, 50, 50]);
expect(interaction.snapToVertex_([230, 40], map)).to.eql([50, 50]);
expect(interaction.snapToVertex_([231, 41], map)).to.eql([50, 50]);
});
it('snap to edge works', function() {
it('snap to edge works', function () {
interaction.setExtent([-50, -50, 50, 50]);
expect(interaction.snapToVertex_([230, 90], map)).to.eql([50, 0]);
@@ -92,9 +90,8 @@ describe('ol.interaction.Extent', function() {
});
});
describe('draw extent', function() {
it('drawing extent works', function() {
describe('draw extent', function () {
it('drawing extent works', function () {
simulateEvent('pointerdown', -50, -50, false, 0);
simulateEvent('pointerdrag', 50, 50, false, 0);
simulateEvent('pointerup', 50, 50, false, 0);
@@ -102,7 +99,7 @@ describe('ol.interaction.Extent', function() {
expect(interaction.getExtent()).to.eql([-50, -50, 50, 50]);
});
it('clicking off extent nulls extent', function() {
it('clicking off extent nulls extent', function () {
interaction.setExtent([-50, -50, 50, 50]);
simulateEvent('pointerdown', -10, -10, false, 0);
@@ -111,7 +108,7 @@ describe('ol.interaction.Extent', function() {
expect(interaction.getExtent()).to.equal(null);
});
it('clicking on extent does not null extent', function() {
it('clicking on extent does not null extent', function () {
interaction.setExtent([-50, -50, 50, 50]);
simulateEvent('pointerdown', 50, 50, false, 0);
@@ -120,7 +117,7 @@ describe('ol.interaction.Extent', function() {
expect(interaction.getExtent()).to.eql([-50, -50, 50, 50]);
});
it('snap and drag vertex works', function() {
it('snap and drag vertex works', function () {
interaction.setExtent([-50, -50, 50, 50]);
simulateEvent('pointerdown', 51, 49, false, 0);
@@ -130,7 +127,7 @@ describe('ol.interaction.Extent', function() {
expect(interaction.getExtent()).to.eql([-70, -50, -50, -40]);
});
it('snap and drag edge works', function() {
it('snap and drag edge works', function () {
interaction.setExtent([-50, -50, 50, 50]);
simulateEvent('pointerdown', 51, 5, false, 0);
+22 -29
View File
@@ -1,64 +1,59 @@
import {Map, View} from '../../../../src/ol/index.js';
import EventTarget from '../../../../src/ol/events/Target.js';
import Interaction, {zoomByDelta} from '../../../../src/ol/interaction/Interaction.js';
import Interaction, {
zoomByDelta,
} from '../../../../src/ol/interaction/Interaction.js';
import {FALSE} from '../../../../src/ol/functions.js';
import {useGeographic, clearUserProjection} from '../../../../src/ol/proj.js';
import {Map, View} from '../../../../src/ol/index.js';
import {clearUserProjection, useGeographic} from '../../../../src/ol/proj.js';
describe('ol.interaction.Interaction', function() {
describe('constructor', function() {
describe('ol.interaction.Interaction', function () {
describe('constructor', function () {
let interaction;
beforeEach(function() {
beforeEach(function () {
interaction = new Interaction({});
});
it('creates a new interaction', function() {
it('creates a new interaction', function () {
expect(interaction).to.be.a(Interaction);
expect(interaction).to.be.a(EventTarget);
});
it('creates an active interaction', function() {
it('creates an active interaction', function () {
expect(interaction.getActive()).to.be(true);
});
});
describe('#getMap()', function() {
it('retrieves the associated map', function() {
describe('#getMap()', function () {
it('retrieves the associated map', function () {
const map = new Map({});
const interaction = new Interaction({});
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('returns null if no map', function() {
it('returns null if no map', function () {
const interaction = new Interaction({});
expect(interaction.getMap()).to.be(null);
});
});
describe('#setMap()', function() {
it('allows a map to be set', function() {
describe('#setMap()', function () {
it('allows a map to be set', function () {
const map = new Map({});
const interaction = new Interaction({});
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('accepts null', function() {
it('accepts null', function () {
const interaction = new Interaction({});
interaction.setMap(null);
expect(interaction.getMap()).to.be(null);
});
});
describe('#handleEvent()', function() {
describe('#handleEvent()', function () {
class MockInteraction extends Interaction {
constructor() {
super(...arguments);
@@ -68,25 +63,23 @@ describe('ol.interaction.Interaction', function() {
}
}
it('has a default event handler', function() {
it('has a default event handler', function () {
const interaction = new Interaction({});
expect(interaction.handleEvent()).to.be(true);
});
it('allows event handler overrides via options', function() {
it('allows event handler overrides via options', function () {
const interaction = new Interaction({
handleEvent: FALSE
handleEvent: FALSE,
});
expect(interaction.handleEvent()).to.be(false);
});
it('allows event handler overrides via class extension', function() {
it('allows event handler overrides via class extension', function () {
const interaction = new MockInteraction({});
expect(interaction.handleEvent()).to.be(false);
});
});
});
describe('zoomByDelta - useGeographic', () => {
@@ -96,7 +89,7 @@ describe('zoomByDelta - useGeographic', () => {
it('works with a user projection set', () => {
const view = new View({
center: [0, 0],
zoom: 0
zoom: 0,
});
const spy = sinon.spy(view, 'animate');
+9 -10
View File
@@ -1,34 +1,34 @@
import Event from '../../../../src/ol/events/Event.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
import View from '../../../../src/ol/View.js';
import Event from '../../../../src/ol/events/Event.js';
describe('ol.interaction.KeyboardPan', function() {
describe('ol.interaction.KeyboardPan', function () {
let map;
beforeEach(function() {
beforeEach(function () {
map = new Map({
target: createMapDiv(100, 100),
view: new View({
center: [0, 0],
resolutions: [1],
zoom: 0
})
zoom: 0,
}),
});
map.renderSync();
});
afterEach(function() {
afterEach(function () {
disposeMap(map);
});
describe('handleEvent()', function() {
it('pans on arrow keys', function() {
describe('handleEvent()', function () {
it('pans on arrow keys', function () {
const view = map.getView();
const spy = sinon.spy(view, 'animateInternal');
const event = new MapBrowserEvent('keydown', map, {
type: 'keydown',
target: map.getTargetElement(),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
event.originalEvent.keyCode = 40; // DOWN
@@ -54,5 +54,4 @@ describe('ol.interaction.KeyboardPan', function() {
view.animateInternal.restore();
});
});
});
+11 -13
View File
@@ -1,34 +1,34 @@
import Event from '../../../../src/ol/events/Event.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
import View from '../../../../src/ol/View.js';
import Event from '../../../../src/ol/events/Event.js';
describe('ol.interaction.KeyboardZoom', function() {
describe('ol.interaction.KeyboardZoom', function () {
let map;
beforeEach(function() {
beforeEach(function () {
map = new Map({
target: createMapDiv(100, 100),
view: new View({
center: [0, 0],
resolutions: [4, 2, 1],
zoom: 1
})
zoom: 1,
}),
});
map.renderSync();
});
afterEach(function() {
afterEach(function () {
disposeMap(map);
});
describe('handleEvent()', function() {
it('zooms on + and - keys', function() {
describe('handleEvent()', function () {
it('zooms on + and - keys', function () {
const view = map.getView();
const spy = sinon.spy(view, 'animateInternal');
const event = new MapBrowserEvent('keydown', map, {
type: 'keydown',
target: map.getTargetElement(),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
event.originalEvent.charCode = '+'.charCodeAt(0);
@@ -44,20 +44,18 @@ describe('ol.interaction.KeyboardZoom', function() {
view.animateInternal.restore();
});
it('does nothing if the target is editable', function() {
it('does nothing if the target is editable', function () {
const view = map.getView();
const spy = sinon.spy(view, 'animateInternal');
const event = new MapBrowserEvent('keydown', map, {
type: 'keydown',
target: document.createElement('input'),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
event.originalEvent.charCode = '+'.charCodeAt(0);
map.handleMapBrowserEvent(event);
expect(spy.called).to.be(false);
});
});
});
+182 -147
View File
@@ -1,30 +1,31 @@
import Circle from '../../../../src/ol/geom/Circle.js';
import Collection from '../../../../src/ol/Collection.js';
import Event from '../../../../src/ol/events/Event.js';
import Feature from '../../../../src/ol/Feature.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js';
import {doubleClick} from '../../../../src/ol/events/condition.js';
import Circle from '../../../../src/ol/geom/Circle.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js';
import Point from '../../../../src/ol/geom/Point.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js';
import Snap from '../../../../src/ol/interaction/Snap.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import Event from '../../../../src/ol/events/Event.js';
import View from '../../../../src/ol/View.js';
import {
clearUserProjection,
setUserProjection,
} from '../../../../src/ol/proj.js';
import {doubleClick} from '../../../../src/ol/events/condition.js';
import {getValues} from '../../../../src/ol/obj.js';
import {clearUserProjection, setUserProjection} from '../../../../src/ol/proj.js';
describe('ol.interaction.Modify', function() {
describe('ol.interaction.Modify', function () {
let target, map, source, features;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
@@ -38,13 +39,19 @@ describe('ol.interaction.Modify', function() {
features = [
new Feature({
geometry: new Polygon([
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
])
})
[
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
],
]),
}),
];
source = new VectorSource({
features: features
features: features,
});
const layer = new VectorLayer({source: source});
@@ -55,16 +62,16 @@ describe('ol.interaction.Modify', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.once('postrender', function() {
map.once('postrender', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
clearUserProjection();
@@ -92,7 +99,7 @@ describe('ol.interaction.Modify', function() {
pointerEvent.shiftKey = modifiers.shift || false;
pointerEvent.altKey = modifiers.alt || false;
pointerEvent.pointerId = 1;
pointerEvent.preventDefault = function() {};
pointerEvent.preventDefault = function () {};
pointerEvent.button = button;
pointerEvent.isPrimary = true;
const event = new MapBrowserPointerEvent(type, map, pointerEvent);
@@ -108,27 +115,26 @@ describe('ol.interaction.Modify', function() {
*/
function trackEvents(feature, interaction) {
const events = [];
feature.on('change', function(event) {
feature.on('change', function (event) {
events.push('change');
});
interaction.on('modifystart', function(event) {
interaction.on('modifystart', function (event) {
events.push(event);
});
interaction.on('modifyend', function(event) {
interaction.on('modifyend', function (event) {
events.push(event);
});
return events;
}
/**
* Validates the event array to verify proper event sequence. Checks
* that first and last event are correct ModifyEvents and that feature
* modifications event are in between.
* @param {Array<ModifyEvent|string>} events The events.
* @param {Array<ol.Feature>} features The features.
*/
* Validates the event array to verify proper event sequence. Checks
* that first and last event are correct ModifyEvents and that feature
* modifications event are in between.
* @param {Array<ModifyEvent|string>} events The events.
* @param {Array<ol.Feature>} features The features.
*/
function validateEvents(events, features) {
const startevent = events[0];
const endevent = events[events.length - 1];
@@ -152,24 +158,23 @@ describe('ol.interaction.Modify', function() {
expect(endevent.features.getArray()).to.eql(features);
}
describe('constructor', function() {
it('adds features to the RTree', function() {
const feature = new Feature(
new Point([0, 0]));
describe('constructor', function () {
it('adds features to the RTree', function () {
const feature = new Feature(new Point([0, 0]));
const features = new Collection([feature]);
const modify = new Modify({
features: features
features: features,
});
const rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(1);
expect(rbushEntries[0].feature).to.be(feature);
});
it('accepts feature without geometry', function() {
it('accepts feature without geometry', function () {
const feature = new Feature();
const features = new Collection([feature]);
const modify = new Modify({
features: features
features: features,
});
let rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(0);
@@ -180,21 +185,18 @@ describe('ol.interaction.Modify', function() {
expect(rbushEntries[0].feature).to.be(feature);
});
it('accepts a source', function() {
const feature = new Feature(
new Point([0, 0]));
it('accepts a source', function () {
const feature = new Feature(new Point([0, 0]));
const source = new VectorSource({features: [feature]});
const modify = new Modify({source: source});
const rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(1);
expect(rbushEntries[0].feature).to.be(feature);
});
});
describe('vertex deletion', function() {
it('works when clicking on a shared vertex', function() {
describe('vertex deletion', function () {
it('works when clicking on a shared vertex', function () {
features.push(features[0].clone());
const first = features[0];
@@ -203,7 +205,7 @@ describe('ol.interaction.Modify', function() {
const secondRevision = second.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -227,11 +229,15 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('deletes first vertex of a LineString', function() {
it('deletes first vertex of a LineString', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
geometry: new LineString([
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
]),
});
features.length = 0;
features.push(lineFeature);
@@ -241,7 +247,7 @@ describe('ol.interaction.Modify', function() {
const firstRevision = first.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -263,11 +269,15 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('deletes last vertex of a LineString', function() {
it('deletes last vertex of a LineString', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
geometry: new LineString([
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
]),
});
features.length = 0;
features.push(lineFeature);
@@ -277,7 +287,7 @@ describe('ol.interaction.Modify', function() {
const firstRevision = first.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -299,11 +309,15 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('deletes vertex of a LineString programmatically', function() {
it('deletes vertex of a LineString programmatically', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
geometry: new LineString([
[0, 0],
[10, 20],
[0, 40],
[40, 40],
[40, 0],
]),
});
features.length = 0;
features.push(lineFeature);
@@ -313,7 +327,7 @@ describe('ol.interaction.Modify', function() {
const firstRevision = first.getGeometry().getRevision();
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -335,23 +349,24 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
});
describe('vertex modification', function() {
it('keeps the third dimension', function() {
describe('vertex modification', function () {
it('keeps the third dimension', function () {
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0, 10], [10, 20, 20], [0, 40, 30], [40, 40, 40], [40, 0, 50]]
)
geometry: new LineString([
[0, 0, 10],
[10, 20, 20],
[0, 40, 30],
[40, 40, 40],
[40, 0, 50],
]),
});
features.length = 0;
features.push(lineFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -380,17 +395,16 @@ describe('ol.interaction.Modify', function() {
expect(lineFeature.getGeometry().getCoordinates()[2][2]).to.equal(30);
expect(lineFeature.getGeometry().getCoordinates()[4][2]).to.equal(50);
});
});
describe('circle modification', function() {
it('changes the circle radius and center', function() {
describe('circle modification', function () {
it('changes the circle radius and center', function () {
const circleFeature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -425,17 +439,19 @@ describe('ol.interaction.Modify', function() {
expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]);
});
it('changes the circle radius and center in a user projection', function() {
it('changes the circle radius and center in a user projection', function () {
const userProjection = 'EPSG:3857';
setUserProjection(userProjection);
const viewProjection = map.getView().getProjection();
const circleFeature = new Feature(new Circle([10, 10], 20).transform(viewProjection, userProjection));
const circleFeature = new Feature(
new Circle([10, 10], 20).transform(viewProjection, userProjection)
);
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -446,7 +462,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -5, null, 0);
simulateEvent('pointerup', 5, -5, null, 0);
const geometry1 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry1 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry1.getRadius()).to.roughlyEqual(20, 1e-9);
expect(geometry1.getCenter()).to.eql([5, 5]);
@@ -457,7 +476,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 30, -5, null, 0);
simulateEvent('pointerup', 30, -5, null, 0);
const geometry2 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry2 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry2.getRadius()).to.roughlyEqual(25, 1e-9);
expect(geometry2.getCenter()).to.eql([5, 5]);
@@ -468,18 +490,21 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -35, null, 0);
simulateEvent('pointerup', 5, -35, null, 0);
const geometry3 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry3 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry3.getRadius()).to.roughlyEqual(30, 1e-9);
expect(geometry3.getCenter()).to.eql([5, 5]);
});
});
describe('boundary modification', function() {
describe('boundary modification', function () {
let modify, feature, events;
beforeEach(function() {
beforeEach(function () {
modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -488,7 +513,7 @@ describe('ol.interaction.Modify', function() {
events = trackEvents(feature, modify);
});
it('clicking vertex should delete it and +r1', function() {
it('clicking vertex should delete it and +r1', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -503,7 +528,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('single clicking boundary should add vertex and +r1', function() {
it('single clicking boundary should add vertex and +r1', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -518,7 +543,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('single clicking on created vertex should delete it again', function() {
it('single clicking on created vertex should delete it again', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -544,7 +569,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('clicking with drag should add vertex and +r3', function() {
it('clicking with drag should add vertex and +r3', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -560,7 +585,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, [feature]);
});
it('clicking with right button should not add a vertex', function() {
it('clicking with right button should not add a vertex', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -575,17 +600,15 @@ describe('ol.interaction.Modify', function() {
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
expect(events).to.have.length(0);
});
});
describe('double click deleteCondition', function() {
describe('double click deleteCondition', function () {
let modify, feature, events;
beforeEach(function() {
beforeEach(function () {
modify = new Modify({
features: new Collection(features),
deleteCondition: doubleClick
deleteCondition: doubleClick,
});
map.addInteraction(modify);
@@ -594,8 +617,7 @@ describe('ol.interaction.Modify', function() {
events = trackEvents(feature, modify);
});
it('should delete vertex on double click', function() {
it('should delete vertex on double click', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -613,8 +635,7 @@ describe('ol.interaction.Modify', function() {
validateEvents(events, features);
});
it('should do nothing on single click', function() {
it('should do nothing on single click', function () {
expect(feature.getGeometry().getRevision()).to.equal(1);
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -630,15 +651,15 @@ describe('ol.interaction.Modify', function() {
});
});
describe('insertVertexCondition', function() {
it('calls the callback function', function() {
const listenerSpy = sinon.spy(function(event) {
describe('insertVertexCondition', function () {
it('calls the callback function', function () {
const listenerSpy = sinon.spy(function (event) {
return false;
});
const modify = new Modify({
features: new Collection(features),
insertVertexCondition: listenerSpy
insertVertexCondition: listenerSpy,
});
map.addInteraction(modify);
const feature = features[0];
@@ -664,26 +685,26 @@ describe('ol.interaction.Modify', function() {
});
});
describe('handle feature change', function() {
describe('handle feature change', function () {
let getModifyListeners;
beforeEach(function() {
getModifyListeners = function(feature, modify) {
beforeEach(function () {
getModifyListeners = function (feature, modify) {
const listeners = feature.listeners_['change'];
const candidates = getValues(modify);
return listeners.filter(function(listener) {
return listeners.filter(function (listener) {
return candidates.indexOf(listener) !== -1;
});
};
});
it('updates circle segment data', function() {
it('updates circle segment data', function () {
const feature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(feature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -694,10 +715,11 @@ describe('ol.interaction.Modify', function() {
let firstSegmentData;
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([10, 10]);
expect(firstSegmentData.segment[1]).to.eql([10, 10]);
@@ -706,10 +728,11 @@ describe('ol.interaction.Modify', function() {
center[1] = 1;
feature.getGeometry().setCenter(center);
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([1, 1]);
expect(firstSegmentData.segment[1]).to.eql([1, 1]);
@@ -717,9 +740,9 @@ describe('ol.interaction.Modify', function() {
expect(listeners).to.have.length(1);
});
it('updates polygon segment data', function() {
it('updates polygon segment data', function () {
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
@@ -731,10 +754,11 @@ describe('ol.interaction.Modify', function() {
let firstSegmentData;
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([0, 0]);
expect(firstSegmentData.segment[1]).to.eql([10, 20]);
@@ -744,10 +768,11 @@ describe('ol.interaction.Modify', function() {
firstVertex[1] = 1;
feature.getGeometry().setCoordinates(coordinates);
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], function (
node
) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([1, 1]);
expect(firstSegmentData.segment[1]).to.eql([10, 20]);
@@ -756,11 +781,11 @@ describe('ol.interaction.Modify', function() {
});
});
describe('handle feature removal during down-up sequence', function() {
it('removes segment data of removed features from dragSegments_', function() {
describe('handle feature removal during down-up sequence', function () {
it('removes segment data of removed features from dragSegments_', function () {
const collection = new Collection(features);
const modify = new Modify({
features: collection
features: collection,
});
map.addInteraction(modify);
simulateEvent('pointermove', 0, 0, null, 0);
@@ -768,16 +793,16 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointermove', -10, -10, null, 0);
simulateEvent('pointerdrag', -10, -10, null, 0);
collection.remove(features[0]);
expect(function() {
expect(function () {
simulateEvent('pointerup', -10, -10, null, 0);
}).to.not.throwException();
});
});
describe('#setActive', function() {
it('removes the vertexFeature of deactivation', function() {
describe('#setActive', function () {
it('removes the vertexFeature of deactivation', function () {
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
expect(modify.vertexFeature_).to.be(null);
@@ -790,29 +815,29 @@ describe('ol.interaction.Modify', function() {
});
});
describe('#getOverlay', function() {
it('returns the feature overlay layer', function() {
describe('#getOverlay', function () {
it('returns the feature overlay layer', function () {
const modify = new Modify({
features: new Collection()
features: new Collection(),
});
expect (modify.getOverlay()).to.eql(modify.overlay_);
expect(modify.getOverlay()).to.eql(modify.overlay_);
});
});
describe('circle modification with snap', function() {
it('changes the circle radius and center', function() {
describe('circle modification with snap', function () {
it('changes the circle radius and center', function () {
const circleFeature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
const snap = new Snap({
features: new Collection(features),
pixelTolerance: 1
pixelTolerance: 1,
});
map.addInteraction(snap);
@@ -847,23 +872,25 @@ describe('ol.interaction.Modify', function() {
expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]);
});
it('changes the circle radius and center in a user projection', function() {
it('changes the circle radius and center in a user projection', function () {
const userProjection = 'EPSG:3857';
setUserProjection(userProjection);
const viewProjection = map.getView().getProjection();
const circleFeature = new Feature(new Circle([10, 10], 20).transform(viewProjection, userProjection));
const circleFeature = new Feature(
new Circle([10, 10], 20).transform(viewProjection, userProjection)
);
features.length = 0;
features.push(circleFeature);
const modify = new Modify({
features: new Collection(features)
features: new Collection(features),
});
map.addInteraction(modify);
const snap = new Snap({
features: new Collection(features),
pixelTolerance: 1
pixelTolerance: 1,
});
map.addInteraction(snap);
@@ -874,7 +901,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -5, null, 0);
simulateEvent('pointerup', 5, -5, null, 0);
const geometry1 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry1 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry1.getRadius()).to.roughlyEqual(20, 1e-9);
expect(geometry1.getCenter()).to.eql([5, 5]);
@@ -885,7 +915,10 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 30, -5, null, 0);
simulateEvent('pointerup', 30, -5, null, 0);
const geometry2 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry2 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry2.getRadius()).to.roughlyEqual(25, 1e-9);
expect(geometry2.getCenter()).to.eql([5, 5]);
@@ -896,10 +929,12 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdrag', 5, -35, null, 0);
simulateEvent('pointerup', 5, -35, null, 0);
const geometry3 = circleFeature.getGeometry().clone().transform(userProjection, viewProjection);
const geometry3 = circleFeature
.getGeometry()
.clone()
.transform(userProjection, viewProjection);
expect(geometry3.getRadius()).to.roughlyEqual(30, 1e-9);
expect(geometry3.getCenter()).to.eql([5, 5]);
});
});
});
+30 -34
View File
@@ -1,15 +1,16 @@
import Event from '../../../../src/ol/events/Event.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
import MouseWheelZoom, {
Mode,
} from '../../../../src/ol/interaction/MouseWheelZoom.js';
import View from '../../../../src/ol/View.js';
import Event from '../../../../src/ol/events/Event.js';
import {DEVICE_PIXEL_RATIO, FIREFOX} from '../../../../src/ol/has.js';
import MouseWheelZoom, {Mode} from '../../../../src/ol/interaction/MouseWheelZoom.js';
describe('ol.interaction.MouseWheelZoom', function() {
describe('ol.interaction.MouseWheelZoom', function () {
let map, interaction;
beforeEach(function() {
beforeEach(function () {
interaction = new MouseWheelZoom();
map = new Map({
target: createMapDiv(100, 100),
@@ -17,35 +18,35 @@ describe('ol.interaction.MouseWheelZoom', function() {
view: new View({
center: [0, 0],
resolutions: [2, 1, 0.5],
zoom: 1
})
zoom: 1,
}),
});
map.renderSync();
});
afterEach(function() {
afterEach(function () {
disposeMap(map);
map = null;
interaction = null;
});
describe('timeout duration', function() {
describe('timeout duration', function () {
let clock;
beforeEach(function() {
beforeEach(function () {
sinon.spy(interaction, 'handleWheelZoom_');
clock = sinon.useFakeTimers();
});
afterEach(function() {
afterEach(function () {
clock.restore();
interaction.handleWheelZoom_.restore();
});
it('works with the default value', function(done) {
it('works with the default value', function (done) {
const event = new MapBrowserEvent('wheel', map, {
type: 'wheel',
target: map.getViewport(),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
map.handleMapBrowserEvent(event);
@@ -58,14 +59,12 @@ describe('ol.interaction.MouseWheelZoom', function() {
done();
});
});
describe('handleEvent()', function() {
describe('handleEvent()', function () {
if (FIREFOX) {
it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function(done) {
map.once('postrender', function() {
it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
map.once('postrender', function () {
expect(interaction.mode_).to.be(Mode.TRACKPAD);
done();
});
@@ -74,7 +73,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
deltaMode: WheelEvent.DOM_DELTA_PIXEL,
deltaY: DEVICE_PIXEL_RATIO,
target: map.getViewport(),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
event.coordinate = [0, 0];
map.handleMapBrowserEvent(event);
@@ -82,8 +81,8 @@ describe('ol.interaction.MouseWheelZoom', function() {
}
if (!FIREFOX) {
it('works in DOM_DELTA_PIXEL mode (trackpad)', function(done) {
map.once('postrender', function() {
it('works in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
map.once('postrender', function () {
expect(interaction.mode_).to.be(Mode.TRACKPAD);
done();
});
@@ -92,26 +91,26 @@ describe('ol.interaction.MouseWheelZoom', function() {
deltaMode: WheelEvent.DOM_DELTA_PIXEL,
deltaY: 1,
target: map.getViewport(),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
event.coordinate = [0, 0];
map.handleMapBrowserEvent(event);
});
}
describe('spying on view.animateInternal()', function() {
describe('spying on view.animateInternal()', function () {
let view;
beforeEach(function() {
beforeEach(function () {
view = map.getView();
sinon.spy(view, 'animateInternal');
});
afterEach(function() {
afterEach(function () {
view.animateInternal.restore();
});
it('works in DOM_DELTA_LINE mode (wheel)', function(done) {
map.once('postrender', function() {
it('works in DOM_DELTA_LINE mode (wheel)', function (done) {
map.once('postrender', function () {
const call = view.animateInternal.getCall(0);
expect(call.args[0].resolution).to.be(2);
expect(call.args[0].anchor).to.eql([0, 0]);
@@ -123,15 +122,15 @@ describe('ol.interaction.MouseWheelZoom', function() {
deltaMode: WheelEvent.DOM_DELTA_LINE,
deltaY: 20,
target: map.getViewport(),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
event.coordinate = [0, 0];
map.handleMapBrowserEvent(event);
});
it('works on all browsers (wheel)', function(done) {
map.once('postrender', function() {
it('works on all browsers (wheel)', function (done) {
map.once('postrender', function () {
const call = view.animateInternal.getCall(0);
expect(call.args[0].resolution).to.be(2);
expect(call.args[0].anchor).to.eql([0, 0]);
@@ -142,15 +141,12 @@ describe('ol.interaction.MouseWheelZoom', function() {
type: 'wheel',
deltaY: 300,
target: map.getViewport(),
preventDefault: Event.prototype.preventDefault
preventDefault: Event.prototype.preventDefault,
});
event.coordinate = [0, 0];
map.handleMapBrowserEvent(event);
});
});
});
});
+21 -26
View File
@@ -1,65 +1,62 @@
import Event from '../../../../src/ol/events/Event.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import Event from '../../../../src/ol/events/Event.js';
import PointerInteraction from '../../../../src/ol/interaction/Pointer.js';
describe('ol.interaction.Pointer', function() {
describe('#handleEvent', function() {
describe('ol.interaction.Pointer', function () {
describe('#handleEvent', function () {
let event;
let defaultPrevented;
beforeEach(function() {
beforeEach(function () {
const type = 'pointerdown';
const pointerEvent = new Event();
pointerEvent.type = type;
pointerEvent.pointerId = 0;
pointerEvent.preventDefault = function() {
pointerEvent.preventDefault = function () {
defaultPrevented = true;
};
event = new MapBrowserPointerEvent(type, new Map(), pointerEvent);
defaultPrevented = false;
});
it('does not prevent default on handled down event', function() {
it('does not prevent default on handled down event', function () {
const interaction = new PointerInteraction({
handleDownEvent: function() {
handleDownEvent: function () {
return true;
}
},
});
interaction.handleEvent(event);
expect(defaultPrevented).to.be(false);
});
it('does not prevent default on unhandled down event', function() {
it('does not prevent default on unhandled down event', function () {
const interaction = new PointerInteraction({
handleDownEvent: function() {
handleDownEvent: function () {
return false;
}
},
});
interaction.handleEvent(event);
expect(defaultPrevented).to.be(false);
});
});
describe('event handlers', function() {
describe('event handlers', function () {
let handleDownCalled, handleDragCalled, handleMoveCalled, handleUpCalled;
const flagHandleDown = function() {
const flagHandleDown = function () {
handleDownCalled = true;
};
const flagHandleDrag = function() {
const flagHandleDrag = function () {
handleDragCalled = true;
};
const flagHandleMove = function() {
const flagHandleMove = function () {
handleMoveCalled = true;
};
const flagHandleUp = function() {
const flagHandleUp = function () {
handleUpCalled = true;
};
@@ -83,25 +80,25 @@ describe('ol.interaction.Pointer', function() {
}
}
beforeEach(function() {
beforeEach(function () {
handleDownCalled = false;
handleDragCalled = false;
handleMoveCalled = false;
handleUpCalled = false;
});
it('has default event handlers', function() {
it('has default event handlers', function () {
const interaction = new PointerInteraction({});
expect(interaction.handleDownEvent()).to.be(false);
expect(interaction.handleUpEvent()).to.be(false);
});
it('allows event handler overrides via options', function() {
it('allows event handler overrides via options', function () {
const interaction = new PointerInteraction({
handleDownEvent: flagHandleDown,
handleDragEvent: flagHandleDrag,
handleMoveEvent: flagHandleMove,
handleUpEvent: flagHandleUp
handleUpEvent: flagHandleUp,
});
interaction.handleDownEvent();
@@ -117,7 +114,7 @@ describe('ol.interaction.Pointer', function() {
expect(handleUpCalled).to.be(true);
});
it('allows event handler overrides via class extension', function() {
it('allows event handler overrides via class extension', function () {
const interaction = new MockPointerInteraction({});
interaction.handleDownEvent();
@@ -132,7 +129,5 @@ describe('ol.interaction.Pointer', function() {
interaction.handleUpEvent();
expect(handleUpCalled).to.be(true);
});
});
});
+114 -111
View File
@@ -1,24 +1,23 @@
import Collection from '../../../../src/ol/Collection.js';
import Feature from '../../../../src/ol/Feature.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserEventType from '../../../../src/ol/MapBrowserEventType.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
import Select from '../../../../src/ol/interaction/Select.js';
import Style from '../../../../src/ol/style/Style.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import Style from '../../../../src/ol/style/Style.js';
import View from '../../../../src/ol/View.js';
describe('ol.interaction.Select', function() {
describe('ol.interaction.Select', function () {
let target, map, layer, source;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
@@ -29,7 +28,14 @@ describe('ol.interaction.Select', function() {
style.height = height + 'px';
document.body.appendChild(target);
const geometry = new Polygon([[[0, 0], [0, 40], [40, 40], [40, 0]]]);
const geometry = new Polygon([
[
[0, 0],
[0, 40],
[40, 40],
[40, 0],
],
]);
// Four overlapping features, two features of type "foo" and two features
// of type "bar". The rendering order is, from top to bottom, foo -> bar
@@ -38,23 +44,24 @@ describe('ol.interaction.Select', function() {
features.push(
new Feature({
geometry: geometry,
type: 'bar'
type: 'bar',
}),
new Feature({
geometry: geometry,
type: 'foo'
type: 'foo',
}),
new Feature({
geometry: geometry,
type: 'bar'
type: 'bar',
}),
new Feature({
geometry: geometry,
type: 'foo'
}));
type: 'foo',
})
);
source = new VectorSource({
features: features
features: features,
});
layer = new VectorLayer({source: source});
@@ -65,16 +72,16 @@ describe('ol.interaction.Select', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.once('postrender', function() {
map.once('postrender', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
});
@@ -97,41 +104,37 @@ describe('ol.interaction.Select', function() {
target: viewport.firstChild,
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
shiftKey: shiftKey
shiftKey: shiftKey,
};
map.handleMapBrowserEvent(new MapBrowserPointerEvent(type, map, event));
}
describe('constructor', function() {
it('creates a new interaction', function() {
describe('constructor', function () {
it('creates a new interaction', function () {
const select = new Select();
expect(select).to.be.a(Select);
expect(select).to.be.a(Interaction);
});
describe('user-provided collection', function() {
it('uses the user-provided collection', function() {
describe('user-provided collection', function () {
it('uses the user-provided collection', function () {
const features = new Collection();
const select = new Select({features: features});
expect(select.getFeatures()).to.be(features);
});
});
});
describe('selecting a polygon', function() {
describe('selecting a polygon', function () {
let select;
beforeEach(function() {
beforeEach(function () {
select = new Select();
map.addInteraction(select);
});
it('select with single-click', function() {
const listenerSpy = sinon.spy(function(e) {
it('select with single-click', function () {
const listenerSpy = sinon.spy(function (e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -144,8 +147,8 @@ describe('ol.interaction.Select', function() {
expect(features.getLength()).to.equal(1);
});
it('single-click outside the geometry', function() {
const listenerSpy = sinon.spy(function(e) {
it('single-click outside the geometry', function () {
const listenerSpy = sinon.spy(function (e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -158,8 +161,8 @@ describe('ol.interaction.Select', function() {
expect(features.getLength()).to.equal(0);
});
it('select twice with single-click', function() {
const listenerSpy = sinon.spy(function(e) {
it('select twice with single-click', function () {
const listenerSpy = sinon.spy(function (e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -173,8 +176,8 @@ describe('ol.interaction.Select', function() {
expect(features.getLength()).to.equal(1);
});
it('select with shift single-click', function() {
const listenerSpy = sinon.spy(function(e) {
it('select with shift single-click', function () {
const listenerSpy = sinon.spy(function (e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -188,18 +191,18 @@ describe('ol.interaction.Select', function() {
});
});
describe('multiselecting polygons', function() {
describe('multiselecting polygons', function () {
let select;
beforeEach(function() {
beforeEach(function () {
select = new Select({
multi: true
multi: true,
});
map.addInteraction(select);
});
it('select with single-click', function() {
const listenerSpy = sinon.spy(function(e) {
it('select with single-click', function () {
const listenerSpy = sinon.spy(function (e) {
expect(e.selected).to.have.length(4);
});
select.on('select', listenerSpy);
@@ -212,8 +215,8 @@ describe('ol.interaction.Select', function() {
expect(features.getLength()).to.equal(4);
});
it('select with shift single-click', function() {
const listenerSpy = sinon.spy(function(e) {
it('select with shift single-click', function () {
const listenerSpy = sinon.spy(function (e) {
expect(e.selected).to.have.length(4);
});
select.on('select', listenerSpy);
@@ -237,17 +240,17 @@ describe('ol.interaction.Select', function() {
});
});
describe('toggle selecting polygons', function() {
describe('toggle selecting polygons', function () {
let select;
beforeEach(function() {
beforeEach(function () {
select = new Select({
multi: true
multi: true,
});
map.addInteraction(select);
});
it('with SHIFT + single-click', function() {
it('with SHIFT + single-click', function () {
const listenerSpy = sinon.spy();
select.on('select', listenerSpy);
@@ -269,16 +272,14 @@ describe('ol.interaction.Select', function() {
});
});
describe('filter features using the filter option', function() {
describe('with multi set to true', function() {
it('only selects features that pass the filter', function() {
describe('filter features using the filter option', function () {
describe('with multi set to true', function () {
it('only selects features that pass the filter', function () {
const select = new Select({
multi: true,
filter: function(feature, layer) {
filter: function (feature, layer) {
return feature.get('type') === 'bar';
}
},
});
map.addInteraction(select);
@@ -289,33 +290,34 @@ describe('ol.interaction.Select', function() {
expect(features.item(1).get('type')).to.be('bar');
});
it('only selects features that pass the filter ' +
'using shift single-click', function() {
const select = new Select({
multi: true,
filter: function(feature, layer) {
return feature.get('type') === 'bar';
}
});
map.addInteraction(select);
it(
'only selects features that pass the filter ' +
'using shift single-click',
function () {
const select = new Select({
multi: true,
filter: function (feature, layer) {
return feature.get('type') === 'bar';
},
});
map.addInteraction(select);
simulateEvent('singleclick', 10, -20,
true);
const features = select.getFeatures();
expect(features.getLength()).to.equal(2);
expect(features.item(0).get('type')).to.be('bar');
expect(features.item(1).get('type')).to.be('bar');
});
simulateEvent('singleclick', 10, -20, true);
const features = select.getFeatures();
expect(features.getLength()).to.equal(2);
expect(features.item(0).get('type')).to.be('bar');
expect(features.item(1).get('type')).to.be('bar');
}
);
});
describe('with multi set to false', function() {
it('only selects the first feature that passes the filter', function() {
describe('with multi set to false', function () {
it('only selects the first feature that passes the filter', function () {
const select = new Select({
multi: false,
filter: function(feature, layer) {
filter: function (feature, layer) {
return feature.get('type') === 'bar';
}
},
});
map.addInteraction(select);
simulateEvent('singleclick', 10, -20);
@@ -324,37 +326,39 @@ describe('ol.interaction.Select', function() {
expect(features.item(0).get('type')).to.be('bar');
});
it('only selects the first feature that passes the filter ' +
'using shift single-click', function() {
const select = new Select({
multi: false,
filter: function(feature, layer) {
return feature.get('type') === 'bar';
}
});
map.addInteraction(select);
simulateEvent('singleclick', 10, -20,
true);
const features = select.getFeatures();
expect(features.getLength()).to.equal(1);
expect(features.item(0).get('type')).to.be('bar');
});
it(
'only selects the first feature that passes the filter ' +
'using shift single-click',
function () {
const select = new Select({
multi: false,
filter: function (feature, layer) {
return feature.get('type') === 'bar';
},
});
map.addInteraction(select);
simulateEvent('singleclick', 10, -20, true);
const features = select.getFeatures();
expect(features.getLength()).to.equal(1);
expect(features.item(0).get('type')).to.be('bar');
}
);
});
});
describe('#getLayer(feature)', function() {
describe('#getLayer(feature)', function () {
let interaction;
beforeEach(function() {
beforeEach(function () {
interaction = new Select();
map.addInteraction(interaction);
});
afterEach(function() {
afterEach(function () {
map.removeInteraction(interaction);
});
it('returns a layer from a selected feature', function() {
const listenerSpy = sinon.spy(function(e) {
it('returns a layer from a selected feature', function () {
const listenerSpy = sinon.spy(function (e) {
const feature = e.selected[0];
const layer_ = interaction.getLayer(feature);
expect(e.selected).to.have.length(1);
@@ -370,10 +374,10 @@ describe('ol.interaction.Select', function() {
});
});
describe('#setActive()', function() {
describe('#setActive()', function () {
let interaction;
beforeEach(function() {
beforeEach(function () {
interaction = new Select();
expect(interaction.getActive()).to.be(true);
@@ -383,35 +387,34 @@ describe('ol.interaction.Select', function() {
simulateEvent('singleclick', 10, -20);
});
afterEach(function() {
afterEach(function () {
map.removeInteraction(interaction);
});
describe('#setActive(false)', function() {
it('keeps the the selection', function() {
describe('#setActive(false)', function () {
it('keeps the the selection', function () {
interaction.setActive(false);
expect(interaction.getFeatures().getLength()).to.equal(1);
});
});
describe('#setActive(true)', function() {
beforeEach(function() {
describe('#setActive(true)', function () {
beforeEach(function () {
interaction.setActive(false);
});
it('fires change:active', function() {
it('fires change:active', function () {
const listenerSpy = sinon.spy();
interaction.on('change:active', listenerSpy);
interaction.setActive(true);
expect(listenerSpy.callCount).to.be(1);
});
});
});
describe('clear event listeners on interaction removal', function() {
describe('clear event listeners on interaction removal', function () {
let firstInteraction, secondInteraction, feature;
beforeEach(function() {
beforeEach(function () {
feature = source.getFeatures()[3]; // top feature is selected
const style = new Style({});
@@ -421,14 +424,14 @@ describe('ol.interaction.Select', function() {
secondInteraction = new Select({style, features});
});
afterEach(function() {
afterEach(function () {
map.removeInteraction(secondInteraction);
map.removeInteraction(firstInteraction);
});
// The base case
describe('with a single interaction added', function() {
it('changes the selected feature once', function() {
describe('with a single interaction added', function () {
it('changes the selected feature once', function () {
map.addInteraction(firstInteraction);
const listenerSpy = sinon.spy();
@@ -441,8 +444,8 @@ describe('ol.interaction.Select', function() {
});
// The "difficult" case. To prevent regression
describe('with a replaced interaction', function() {
it('changes the selected feature once', function() {
describe('with a replaced interaction', function () {
it('changes the selected feature once', function () {
map.addInteraction(firstInteraction);
map.removeInteraction(firstInteraction);
map.addInteraction(secondInteraction);
+104 -63
View File
@@ -1,33 +1,34 @@
import Circle from '../../../../src/ol/geom/Circle.js';
import Collection from '../../../../src/ol/Collection.js';
import Feature from '../../../../src/ol/Feature.js';
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import Circle from '../../../../src/ol/geom/Circle.js';
import Point from '../../../../src/ol/geom/Point.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Map from '../../../../src/ol/Map.js';
import Point from '../../../../src/ol/geom/Point.js';
import Snap from '../../../../src/ol/interaction/Snap.js';
import {useGeographic, clearUserProjection, setUserProjection, transform} from '../../../../src/ol/proj.js';
import View from '../../../../src/ol/View.js';
import {
clearUserProjection,
setUserProjection,
transform,
useGeographic,
} from '../../../../src/ol/proj.js';
import {overrideRAF} from '../../util.js';
describe('ol.interaction.Snap', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.interaction.Snap', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new Snap();
expect(instance).to.be.an(Snap);
});
});
describe('handleEvent', function() {
describe('handleEvent', function () {
let target, map;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
@@ -43,166 +44,207 @@ describe('ol.interaction.Snap', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.once('postrender', function() {
map.once('postrender', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
clearUserProjection();
});
it('can handle XYZ coordinates', function() {
it('can handle XYZ coordinates', function () {
const point = new Feature(new Point([0, 0, 123]));
const snapInteraction = new Snap({
features: new Collection([point])
features: new Collection([point]),
});
snapInteraction.setMap(map);
const event = {
pixel: [width / 2, height / 2],
coordinate: [0, 0],
map: map
map: map,
};
snapInteraction.handleEvent(event);
// check that the coordinate is in XY and not XYZ
expect(event.coordinate).to.eql([0, 0]);
});
it('snaps to edges only', function() {
const point = new Feature(new LineString([[-10, 0], [10, 0]]));
it('snaps to edges only', function () {
const point = new Feature(
new LineString([
[-10, 0],
[10, 0],
])
);
const snapInteraction = new Snap({
features: new Collection([point]),
pixelTolerance: 5,
vertex: false
vertex: false,
});
snapInteraction.setMap(map);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([7, 0]);
});
it('snaps to vertices only', function() {
const point = new Feature(new LineString([[-10, 0], [10, 0]]));
it('snaps to vertices only', function () {
const point = new Feature(
new LineString([
[-10, 0],
[10, 0],
])
);
const snapInteraction = new Snap({
features: new Collection([point]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
it('snaps to circle', function() {
it('snaps to circle', function () {
const circle = new Feature(new Circle([0, 0], 10));
const snapInteraction = new Snap({
features: new Collection([circle]),
pixelTolerance: 5
pixelTolerance: 5,
});
snapInteraction.setMap(map);
const event = {
pixel: [5 + width / 2, height / 2 - 5],
coordinate: [5, 5],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate[0]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
expect(event.coordinate[1]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
expect(event.coordinate[0]).to.roughlyEqual(
Math.sin(Math.PI / 4) * 10,
1e-10
);
expect(event.coordinate[1]).to.roughlyEqual(
Math.sin(Math.PI / 4) * 10,
1e-10
);
});
it('snaps to circle in a user projection', function() {
it('snaps to circle in a user projection', function () {
const userProjection = 'EPSG:3857';
setUserProjection(userProjection);
const viewProjection = map.getView().getProjection();
const circle = new Feature(new Circle([0, 0], 10).transform(viewProjection, userProjection));
const circle = new Feature(
new Circle([0, 0], 10).transform(viewProjection, userProjection)
);
const snapInteraction = new Snap({
features: new Collection([circle]),
pixelTolerance: 5
pixelTolerance: 5,
});
snapInteraction.setMap(map);
const event = {
pixel: [5 + width / 2, height / 2 - 5],
coordinate: transform([5, 5], viewProjection, userProjection),
map: map
map: map,
};
snapInteraction.handleEvent(event);
const coordinate = transform([Math.sin(Math.PI / 4) * 10, Math.sin(Math.PI / 4) * 10], viewProjection, userProjection);
const coordinate = transform(
[Math.sin(Math.PI / 4) * 10, Math.sin(Math.PI / 4) * 10],
viewProjection,
userProjection
);
expect(event.coordinate[0]).to.roughlyEqual(coordinate[0], 1e-10);
expect(event.coordinate[1]).to.roughlyEqual(coordinate[1], 1e-10);
});
it('handle feature without geometry', function() {
it('handle feature without geometry', function () {
const feature = new Feature();
const snapInteraction = new Snap({
features: new Collection([feature]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
feature.setGeometry(new LineString([[-10, 0], [10, 0]]));
feature.setGeometry(
new LineString([
[-10, 0],
[10, 0],
])
);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
it('handle geometry changes', function() {
const line = new Feature(new LineString([[-10, 0], [0, 0]]));
it('handle geometry changes', function () {
const line = new Feature(
new LineString([
[-10, 0],
[0, 0],
])
);
const snapInteraction = new Snap({
features: new Collection([line]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
line.getGeometry().setCoordinates([[-10, 0], [10, 0]]);
line.getGeometry().setCoordinates([
[-10, 0],
[10, 0],
]);
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
it('handle geometry name changes', function() {
it('handle geometry name changes', function () {
const line = new Feature({
geometry: new LineString([[-10, 0], [0, 0]]),
alt_geometry: new LineString([[-10, 0], [10, 0]])
geometry: new LineString([
[-10, 0],
[0, 0],
]),
alt_geometry: new LineString([
[-10, 0],
[10, 0],
]),
});
const snapInteraction = new Snap({
features: new Collection([line]),
pixelTolerance: 5,
edge: false
edge: false,
});
snapInteraction.setMap(map);
@@ -211,12 +253,11 @@ describe('ol.interaction.Snap', function() {
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
map: map,
};
snapInteraction.handleEvent(event);
expect(event.coordinate).to.eql([10, 0]);
});
});
describe('handleEvent - useGeographic', () => {
@@ -225,7 +266,7 @@ describe('ol.interaction.Snap', function() {
let restoreRAF;
beforeEach(done => {
beforeEach((done) => {
restoreRAF = overrideRAF();
useGeographic();
@@ -236,7 +277,7 @@ describe('ol.interaction.Snap', function() {
top: 0,
left: 0,
width: `${size}px`,
height: `${size}px`
height: `${size}px`,
});
document.body.appendChild(target);
@@ -244,8 +285,8 @@ describe('ol.interaction.Snap', function() {
target: target,
view: new View({
center: [0, 0],
zoom: 0
})
zoom: 0,
}),
});
map.once('postrender', () => {
@@ -266,11 +307,13 @@ describe('ol.interaction.Snap', function() {
const point = new Feature(new Point([lon, lat]));
const snap = new Snap({
features: new Collection([point])
features: new Collection([point]),
});
snap.setMap(map);
const expectedPixel = map.getPixelFromCoordinate([lon, lat]).map(value => Math.round(value));
const expectedPixel = map
.getPixelFromCoordinate([lon, lat])
.map((value) => Math.round(value));
const delta = 5;
const pixel = expectedPixel.slice();
@@ -282,14 +325,12 @@ describe('ol.interaction.Snap', function() {
const event = {
pixel: pixel,
coordinate: coordinate,
map: map
map: map,
};
snap.handleEvent(event);
expect(event.coordinate).to.eql([lon, lat]);
expect(event.pixel).to.eql(expectedPixel);
});
});
});
+49 -53
View File
@@ -1,22 +1,23 @@
import Collection from '../../../../src/ol/Collection.js';
import Feature from '../../../../src/ol/Feature.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js';
import Point from '../../../../src/ol/geom/Point.js';
import Translate, {TranslateEvent} from '../../../../src/ol/interaction/Translate.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
import Translate, {
TranslateEvent,
} from '../../../../src/ol/interaction/Translate.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import View from '../../../../src/ol/View.js';
describe('ol.interaction.Translate', function() {
describe('ol.interaction.Translate', function () {
let target, map, source, features;
const width = 360;
const height = 180;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
const style = target.style;
style.position = 'absolute';
@@ -26,11 +27,14 @@ describe('ol.interaction.Translate', function() {
style.height = height + 'px';
document.body.appendChild(target);
source = new VectorSource();
features = [new Feature({
geometry: new Point([10, -20])
}), new Feature({
geometry: new Point([20, -30])
})];
features = [
new Feature({
geometry: new Point([10, -20]),
}),
new Feature({
geometry: new Point([20, -30]),
}),
];
source.addFeatures(features);
const layer = new VectorLayer({source: source});
map = new Map({
@@ -39,15 +43,15 @@ describe('ol.interaction.Translate', function() {
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
resolution: 1,
}),
});
map.once('postrender', function() {
map.once('postrender', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
});
@@ -72,7 +76,7 @@ describe('ol.interaction.Translate', function() {
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
shiftKey: shiftKey,
preventDefault: function() {}
preventDefault: function () {},
});
map.handleMapBrowserEvent(event);
}
@@ -86,13 +90,13 @@ describe('ol.interaction.Translate', function() {
*/
function trackEvents(feature, interaction) {
const events = [];
feature.on('change', function(event) {
feature.on('change', function (event) {
events.push('change');
});
interaction.on('translatestart', function(event) {
interaction.on('translatestart', function (event) {
events.push(event);
});
interaction.on('translateend', function(event) {
interaction.on('translateend', function (event) {
events.push(event);
});
return events;
@@ -106,7 +110,6 @@ describe('ol.interaction.Translate', function() {
* @param {Array<ol.Feature>} features The features.
*/
function validateEvents(events, features) {
const startevent = events[0];
const endevent = events[events.length - 1];
@@ -130,43 +133,38 @@ describe('ol.interaction.Translate', function() {
expect(endevent.features.getArray()).to.eql(features);
}
describe('constructor', function() {
it('creates a new interaction', function() {
describe('constructor', function () {
it('creates a new interaction', function () {
const translate = new Translate({
features: features
features: features,
});
expect(translate).to.be.a(Translate);
expect(translate).to.be.a(Interaction);
});
});
describe('setActive', function() {
it('works when the map is not set', function() {
describe('setActive', function () {
it('works when the map is not set', function () {
const translate = new Translate({
features: features
features: features,
});
expect(translate.getActive()).to.be(true);
translate.setActive(false);
expect(translate.getActive()).to.be(false);
});
});
describe('moving features, with features option', function() {
describe('moving features, with features option', function () {
let translate;
beforeEach(function() {
beforeEach(function () {
translate = new Translate({
features: new Collection([features[0]])
features: new Collection([features[0]]),
});
map.addInteraction(translate);
});
it('moves a selected feature', function() {
it('moves a selected feature', function () {
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 10, 20);
@@ -180,7 +178,7 @@ describe('ol.interaction.Translate', function() {
validateEvents(events, [features[0]]);
});
it('does not move an unselected feature', function() {
it('does not move an unselected feature', function () {
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 20, 30);
@@ -195,15 +193,15 @@ describe('ol.interaction.Translate', function() {
});
});
describe('moving features, without features option', function() {
describe('moving features, without features option', function () {
let translate;
beforeEach(function() {
beforeEach(function () {
translate = new Translate();
map.addInteraction(translate);
});
it('moves only targeted feature', function() {
it('moves only targeted feature', function () {
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 10, 20);
@@ -217,19 +215,19 @@ describe('ol.interaction.Translate', function() {
});
});
describe('moving features, with filter option', function() {
describe('moving features, with filter option', function () {
let translate;
beforeEach(function() {
beforeEach(function () {
translate = new Translate({
filter: function(feature, layer) {
filter: function (feature, layer) {
return feature == features[0];
}
},
});
map.addInteraction(translate);
});
it('moves a filter-passing feature', function() {
it('moves a filter-passing feature', function () {
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 10, 20);
@@ -243,7 +241,7 @@ describe('ol.interaction.Translate', function() {
validateEvents(events, [features[0]]);
});
it('does not move a filter-discarded feature', function() {
it('does not move a filter-discarded feature', function () {
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 20, 30);
@@ -258,16 +256,16 @@ describe('ol.interaction.Translate', function() {
});
});
describe('changes css cursor', function() {
describe('changes css cursor', function () {
let element, translate;
beforeEach(function() {
beforeEach(function () {
translate = new Translate();
map.addInteraction(translate);
element = map.getViewport();
});
it('changes css cursor', function() {
it('changes css cursor', function () {
expect(element.classList.contains('ol-grabbing')).to.be(false);
expect(element.classList.contains('ol-grab')).to.be(false);
@@ -288,7 +286,7 @@ describe('ol.interaction.Translate', function() {
expect(element.classList.contains('ol-grab')).to.be(false);
});
it('resets css cursor when interaction is deactivated while pointer is on feature', function() {
it('resets css cursor when interaction is deactivated while pointer is on feature', function () {
simulateEvent('pointermove', 10, 20);
expect(element.classList.contains('ol-grabbing')).to.be(false);
expect(element.classList.contains('ol-grab')).to.be(true);
@@ -300,7 +298,7 @@ describe('ol.interaction.Translate', function() {
expect(element.classList.contains('ol-grab')).to.be(false);
});
it('resets css cursor interaction is removed while pointer is on feature', function() {
it('resets css cursor interaction is removed while pointer is on feature', function () {
simulateEvent('pointermove', 10, 20);
expect(element.classList.contains('ol-grabbing')).to.be(false);
expect(element.classList.contains('ol-grab')).to.be(true);
@@ -312,7 +310,7 @@ describe('ol.interaction.Translate', function() {
expect(element.classList.contains('ol-grab')).to.be(false);
});
it('resets css cursor to existing cursor interaction is removed while pointer is on feature', function() {
it('resets css cursor to existing cursor interaction is removed while pointer is on feature', function () {
element.style.cursor = 'pointer';
simulateEvent('pointermove', 10, 20);
@@ -325,7 +323,5 @@ describe('ol.interaction.Translate', function() {
expect(element.classList.contains('ol-grabbing')).to.be(false);
expect(element.classList.contains('ol-grab')).to.be(false);
});
});
});
+91 -109
View File
@@ -1,39 +1,36 @@
import {getUid} from '../../../../src/ol/util.js';
import Collection from '../../../../src/ol/Collection.js';
import {getIntersection} from '../../../../src/ol/extent.js';
import LayerGroup from '../../../../src/ol/layer/Group.js';
import Layer from '../../../../src/ol/layer/Layer.js';
import {assign} from '../../../../src/ol/obj.js';
import LayerGroup from '../../../../src/ol/layer/Group.js';
import Source from '../../../../src/ol/source/Source.js';
import {assign} from '../../../../src/ol/obj.js';
import {getIntersection} from '../../../../src/ol/extent.js';
import {getUid} from '../../../../src/ol/util.js';
describe('ol.layer.Group', function() {
describe('constructor (defaults)', function() {
describe('ol.layer.Group', function () {
describe('constructor (defaults)', function () {
let layerGroup;
beforeEach(function() {
beforeEach(function () {
layerGroup = new LayerGroup();
});
afterEach(function() {
afterEach(function () {
layerGroup.dispose();
});
it('creates an instance', function() {
it('creates an instance', function () {
expect(layerGroup).to.be.a(LayerGroup);
});
it('provides default opacity', function() {
it('provides default opacity', function () {
expect(layerGroup.getOpacity()).to.be(1);
});
it('provides default visibility', function() {
it('provides default visibility', function () {
expect(layerGroup.getVisible()).to.be(true);
});
it('provides default layerState', function() {
it('provides default layerState', function () {
expect(layerGroup.getLayerState()).to.eql({
layer: layerGroup,
opacity: 1,
@@ -45,45 +42,43 @@ describe('ol.layer.Group', function() {
maxResolution: Infinity,
minResolution: 0,
minZoom: -Infinity,
maxZoom: Infinity
maxZoom: Infinity,
});
});
it('provides default empty layers collection', function() {
it('provides default empty layers collection', function () {
expect(layerGroup.getLayers()).to.be.a(Collection);
expect(layerGroup.getLayers().getLength()).to.be(0);
});
});
describe('generic change event', function() {
describe('generic change event', function () {
let layer, group, listener;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
});
group = new LayerGroup({
layers: [layer]
layers: [layer],
});
listener = sinon.spy();
});
afterEach(function() {
afterEach(function () {
group.dispose();
layer.dispose();
});
it('is dispatched by the group when layer opacity changes', function() {
it('is dispatched by the group when layer opacity changes', function () {
group.on('change', listener);
layer.setOpacity(0.5);
expect(listener.calledOnce).to.be(true);
});
it('is dispatched by the group when layer visibility changes', function() {
it('is dispatched by the group when layer visibility changes', function () {
group.on('change', listener);
layer.setVisible(false);
@@ -92,37 +87,35 @@ describe('ol.layer.Group', function() {
layer.setVisible(true);
expect(listener.callCount).to.be(2);
});
});
describe('property change event', function() {
describe('property change event', function () {
let layer, group, listener;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
});
group = new LayerGroup({
layers: [layer]
layers: [layer],
});
listener = sinon.spy();
});
afterEach(function() {
afterEach(function () {
group.dispose();
layer.dispose();
});
it('is dispatched by the group when group opacity changes', function() {
it('is dispatched by the group when group opacity changes', function () {
group.on('propertychange', listener);
group.setOpacity(0.5);
expect(listener.calledOnce).to.be(true);
});
it('is dispatched by the group when group visibility changes', function() {
it('is dispatched by the group when group visibility changes', function () {
group.on('propertychange', listener);
group.setVisible(false);
@@ -131,16 +124,14 @@ describe('ol.layer.Group', function() {
group.setVisible(true);
expect(listener.callCount).to.be(2);
});
});
describe('constructor (options)', function() {
it('accepts options', function() {
describe('constructor (options)', function () {
it('accepts options', function () {
const layer = new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
});
const layerGroup = new LayerGroup({
layers: [layer],
@@ -150,7 +141,7 @@ describe('ol.layer.Group', function() {
maxResolution: 500,
minResolution: 0.25,
minZoom: 1,
maxZoom: 10
maxZoom: 10,
});
expect(layerGroup.getOpacity()).to.be(0.5);
@@ -170,7 +161,7 @@ describe('ol.layer.Group', function() {
maxResolution: 500,
minResolution: 0.25,
minZoom: 1,
maxZoom: 10
maxZoom: 10,
});
expect(layerGroup.getLayers()).to.be.a(Collection);
expect(layerGroup.getLayers().getLength()).to.be(1);
@@ -180,11 +171,11 @@ describe('ol.layer.Group', function() {
layerGroup.dispose();
});
it('accepts an extent option', function() {
it('accepts an extent option', function () {
const layer = new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
});
const groupExtent = [-10, -5, 10, 5];
@@ -194,7 +185,7 @@ describe('ol.layer.Group', function() {
visible: false,
extent: groupExtent,
maxResolution: 500,
minResolution: 0.25
minResolution: 0.25,
});
expect(layerGroup.getOpacity()).to.be(0.5);
@@ -213,7 +204,7 @@ describe('ol.layer.Group', function() {
maxResolution: 500,
minResolution: 0.25,
minZoom: -Infinity,
maxZoom: Infinity
maxZoom: Infinity,
});
expect(layerGroup.getLayers()).to.be.a(Collection);
expect(layerGroup.getLayers().getLength()).to.be(1);
@@ -224,19 +215,18 @@ describe('ol.layer.Group', function() {
});
});
describe('#getLayerState', function() {
describe('#getLayerState', function () {
let layerGroup;
beforeEach(function() {
beforeEach(function () {
layerGroup = new LayerGroup();
});
afterEach(function() {
afterEach(function () {
layerGroup.dispose();
});
it('returns a layerState from the properties values', function() {
it('returns a layerState from the properties values', function () {
layerGroup.setOpacity(0.3);
layerGroup.setVisible(false);
layerGroup.setZIndex(10);
@@ -257,11 +247,11 @@ describe('ol.layer.Group', function() {
maxResolution: 500,
minResolution: 0.25,
minZoom: 5,
maxZoom: 10
maxZoom: 10,
});
});
it('returns a layerState with clamped values', function() {
it('returns a layerState with clamped values', function () {
layerGroup.setOpacity(-1.5);
layerGroup.setVisible(false);
expect(layerGroup.getLayerState()).to.eql({
@@ -275,7 +265,7 @@ describe('ol.layer.Group', function() {
maxResolution: Infinity,
minResolution: 0,
minZoom: -Infinity,
maxZoom: Infinity
maxZoom: Infinity,
});
layerGroup.setOpacity(3);
@@ -291,18 +281,16 @@ describe('ol.layer.Group', function() {
maxResolution: Infinity,
minResolution: 0,
minZoom: -Infinity,
maxZoom: Infinity
maxZoom: Infinity,
});
});
});
describe('layers events', function() {
it('listen / unlisten for layers added to the collection', function() {
describe('layers events', function () {
it('listen / unlisten for layers added to the collection', function () {
const layers = new Collection();
const layerGroup = new LayerGroup({
layers: layers
layers: layers,
});
expect(Object.keys(layerGroup.listenerKeys_).length).to.eql(0);
const layer = new Layer({});
@@ -320,16 +308,14 @@ describe('ol.layer.Group', function() {
expect(listeners[0].listener).to.be(undefined);
expect(listeners[1].listener).to.be(undefined);
});
});
describe('#setLayers', function() {
it('sets layers property', function() {
describe('#setLayers', function () {
it('sets layers property', function () {
const layer = new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
});
const layers = new Collection([layer]);
const layerGroup = new LayerGroup();
@@ -341,43 +327,40 @@ describe('ol.layer.Group', function() {
layer.dispose();
layers.dispose();
});
});
describe('#getLayerStatesArray', function() {
describe('#getLayerStatesArray', function () {
let layer1, layer2, layer3;
beforeEach(function() {
beforeEach(function () {
layer1 = new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
});
layer2 = new Layer({
source: new Source({
projection: 'EPSG:4326'
projection: 'EPSG:4326',
}),
opacity: 0.5,
visible: false,
maxResolution: 500,
minResolution: 0.25
minResolution: 0.25,
});
layer3 = new Layer({
source: new Source({
projection: 'EPSG:4326'
projection: 'EPSG:4326',
}),
extent: [-5, -2, 5, 2]
extent: [-5, -2, 5, 2],
});
});
afterEach(function() {
afterEach(function () {
layer1.dispose();
layer2.dispose();
layer3.dispose();
});
it('returns an empty array if no layer', function() {
it('returns an empty array if no layer', function () {
const layerGroup = new LayerGroup();
const layerStatesArray = layerGroup.getLayerStatesArray();
@@ -387,9 +370,9 @@ describe('ol.layer.Group', function() {
layerGroup.dispose();
});
it('does not transform layerStates by default', function() {
it('does not transform layerStates by default', function () {
const layerGroup = new LayerGroup({
layers: [layer1, layer2]
layers: [layer1, layer2],
});
const layerStatesArray = layerGroup.getLayerStatesArray();
@@ -409,36 +392,37 @@ describe('ol.layer.Group', function() {
layerGroup.dispose();
});
it('uses the layer group extent if layer has no extent', function() {
it('uses the layer group extent if layer has no extent', function () {
const groupExtent = [-10, -5, 10, 5];
const layerGroup = new LayerGroup({
extent: groupExtent,
layers: [layer1]
layers: [layer1],
});
const layerStatesArray = layerGroup.getLayerStatesArray();
expect(layerStatesArray[0].extent).to.eql(groupExtent);
layerGroup.dispose();
});
it('uses the intersection of group and child extent', function() {
it('uses the intersection of group and child extent', function () {
const groupExtent = [-10, -5, 10, 5];
const layerGroup = new LayerGroup({
extent: groupExtent,
layers: [layer3]
layers: [layer3],
});
const layerStatesArray = layerGroup.getLayerStatesArray();
expect(layerStatesArray[0].extent).to.eql(
getIntersection(layer3.getExtent(), groupExtent));
getIntersection(layer3.getExtent(), groupExtent)
);
layerGroup.dispose();
});
it('transforms layerStates correctly', function() {
it('transforms layerStates correctly', function () {
const layerGroup = new LayerGroup({
layers: [layer1, layer2],
opacity: 0.5,
visible: false,
maxResolution: 150,
minResolution: 0.2
minResolution: 0.2,
});
const layerStatesArray = layerGroup.getLayerStatesArray();
@@ -465,56 +449,54 @@ describe('ol.layer.Group', function() {
maxResolution: 150,
minResolution: 0.25,
minZoom: -Infinity,
maxZoom: Infinity
maxZoom: Infinity,
});
layerGroup.dispose();
});
it('returns max minZoom', function() {
it('returns max minZoom', function () {
const group = new LayerGroup({
minZoom: 5,
layers: [
new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
}),
new Layer({
source: new Source({
projection: 'EPSG:4326'
projection: 'EPSG:4326',
}),
minZoom: 10
})
]
minZoom: 10,
}),
],
});
expect(group.getLayerStatesArray()[0].minZoom).to.be(5);
expect(group.getLayerStatesArray()[1].minZoom).to.be(10);
});
it('returns min maxZoom of layers', function() {
it('returns min maxZoom of layers', function () {
const group = new LayerGroup({
maxZoom: 5,
layers: [
new Layer({
source: new Source({
projection: 'EPSG:4326'
})
projection: 'EPSG:4326',
}),
}),
new Layer({
source: new Source({
projection: 'EPSG:4326'
projection: 'EPSG:4326',
}),
maxZoom: 2
})
]
maxZoom: 2,
}),
],
});
expect(group.getLayerStatesArray()[0].maxZoom).to.be(5);
expect(group.getLayerStatesArray()[1].maxZoom).to.be(2);
});
});
});
+22 -21
View File
@@ -1,48 +1,51 @@
import HeatmapLayer from '../../../../src/ol/layer/Heatmap.js';
import Feature from '../../../../src/ol/Feature.js';
import HeatmapLayer from '../../../../src/ol/layer/Heatmap.js';
import Map from '../../../../src/ol/Map.js';
import Point from '../../../../src/ol/geom/Point.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
describe('ol.layer.Heatmap', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
describe('ol.layer.Heatmap', function () {
describe('constructor', function () {
it('can be constructed without arguments', function () {
const instance = new HeatmapLayer();
expect(instance).to.be.an(HeatmapLayer);
});
});
describe('hit detection', function() {
it('hit detects two distinct features', function(done) {
describe('hit detection', function () {
it('hit detects two distinct features', function (done) {
const target = document.createElement('div');
target.style.width = '300px';
target.style.height = '300px';
document.body.appendChild(target);
const feature = new Feature({geometry: new Point([0, 0]), id: 1, weight: 10});
const feature2 = new Feature({geometry: new Point([14, 14]), id: 2, weight: 10});
const feature = new Feature({
geometry: new Point([0, 0]),
id: 1,
weight: 10,
});
const feature2 = new Feature({
geometry: new Point([14, 14]),
id: 2,
weight: 10,
});
const source = new VectorSource({
features: [feature, feature2]
features: [feature, feature2],
});
const layer = new HeatmapLayer({
source: source,
blur: 10,
radius: 10
radius: 10,
});
const map = new Map({
layers: [layer],
view: new View({
center: [0, 0],
resolution: 0.1
resolution: 0.1,
}),
target: target
target: target,
});
map.render();
@@ -54,7 +57,7 @@ describe('ol.layer.Heatmap', function() {
}
const renderer = layer.getRenderer();
renderer.worker_.addEventListener('message', function(event) {
renderer.worker_.addEventListener('message', function (event) {
if (!renderer.hitRenderInstructions_) {
return;
}
@@ -75,7 +78,5 @@ describe('ol.layer.Heatmap', function() {
done();
});
});
});
});
+293 -263
View File
@@ -1,57 +1,54 @@
import Map from '../../../../src/ol/Map.js';
import Layer, {inView} from '../../../../src/ol/layer/Layer.js';
import {get as getProjection} from '../../../../src/ol/proj.js';
import Map from '../../../../src/ol/Map.js';
import RenderEvent from '../../../../src/ol/render/Event.js';
import Source from '../../../../src/ol/source/Source.js';
import {get as getProjection} from '../../../../src/ol/proj.js';
describe('ol.layer.Layer', function() {
describe('constructor (defaults)', function() {
describe('ol.layer.Layer', function () {
describe('constructor (defaults)', function () {
let layer;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
source: new Source({
projection: getProjection('EPSG:4326')
})
projection: getProjection('EPSG:4326'),
}),
});
});
afterEach(function() {
afterEach(function () {
layer.dispose();
});
it('creates an instance', function() {
it('creates an instance', function () {
expect(layer).to.be.a(Layer);
});
it('provides default opacity', function() {
it('provides default opacity', function () {
expect(layer.getOpacity()).to.be(1);
});
it('provides default visibility', function() {
it('provides default visibility', function () {
expect(layer.getVisible()).to.be(true);
});
it('provides default max resolution', function() {
it('provides default max resolution', function () {
expect(layer.getMaxResolution()).to.be(Infinity);
});
it('provides default min resolution', function() {
it('provides default min resolution', function () {
expect(layer.getMinResolution()).to.be(0);
});
it('provides default min zoom', function() {
it('provides default min zoom', function () {
expect(layer.getMinZoom()).to.be(-Infinity);
});
it('provides default max zoom', function() {
it('provides default max zoom', function () {
expect(layer.getMaxZoom()).to.be(Infinity);
});
it('provides default layerState', function() {
it('provides default layerState', function () {
expect(layer.getLayerState()).to.eql({
layer: layer,
opacity: 1,
@@ -63,18 +60,16 @@ describe('ol.layer.Layer', function() {
maxResolution: Infinity,
minResolution: 0,
minZoom: -Infinity,
maxZoom: Infinity
maxZoom: Infinity,
});
});
});
describe('constructor (options)', function() {
it('accepts options', function() {
describe('constructor (options)', function () {
it('accepts options', function () {
const layer = new Layer({
source: new Source({
projection: getProjection('EPSG:4326')
projection: getProjection('EPSG:4326'),
}),
opacity: 0.5,
visible: false,
@@ -83,7 +78,7 @@ describe('ol.layer.Layer', function() {
minResolution: 0.25,
minZoom: 1,
maxZoom: 10,
foo: 42
foo: 42,
});
expect(layer.getOpacity()).to.be(0.5);
@@ -104,224 +99,271 @@ describe('ol.layer.Layer', function() {
maxResolution: 500,
minResolution: 0.25,
minZoom: 1,
maxZoom: 10
maxZoom: 10,
});
layer.dispose();
});
it('throws on non-numeric opacity', function() {
it('throws on non-numeric opacity', function () {
function create() {
new Layer({
source: new Source({
projection: 'EPSG:4326'
projection: 'EPSG:4326',
}),
opacity: 'foo'
opacity: 'foo',
});
}
expect(create).to.throwException();
});
it('accepts a custom render function', function() {
it('accepts a custom render function', function () {
let called = false;
const layer = new Layer({
render: function() {
render: function () {
called = true;
}
},
});
layer.render();
expect(called).to.eql(true);
});
});
describe('inView', function() {
describe('inView', function () {
let layer;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
source: new Source({
projection: getProjection('EPSG:4326')
})
projection: getProjection('EPSG:4326'),
}),
});
});
afterEach(function() {
afterEach(function () {
layer.dispose();
});
const cases = [{
when: 'layer is not visible',
visible: false,
view: {
resolution: 4, zoom: 4
const cases = [
{
when: 'layer is not visible',
visible: false,
view: {
resolution: 4,
zoom: 4,
},
inView: false,
},
inView: false
}, {
when: 'layer is not visible (with min/max zoom and resolution)',
visible: false,
minZoom: 2,
maxZoom: 6,
minResolution: 2,
maxResolution: 6,
view: {
resolution: 4, zoom: 4
{
when: 'layer is not visible (with min/max zoom and resolution)',
visible: false,
minZoom: 2,
maxZoom: 6,
minResolution: 2,
maxResolution: 6,
view: {
resolution: 4,
zoom: 4,
},
inView: false,
},
inView: false
}, {
when: 'view zoom is less than minZoom',
minZoom: 2,
view: {
resolution: 1, zoom: 1
{
when: 'view zoom is less than minZoom',
minZoom: 2,
view: {
resolution: 1,
zoom: 1,
},
inView: false,
},
inView: false
}, {
when: 'view zoom is less than minZoom (with maxZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 1, zoom: 1
{
when: 'view zoom is less than minZoom (with maxZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 1,
zoom: 1,
},
inView: false,
},
inView: false
}, {
when: 'view zoom is equal to minZoom',
minZoom: 2,
view: {
resolution: 2, zoom: 2
{
when: 'view zoom is equal to minZoom',
minZoom: 2,
view: {
resolution: 2,
zoom: 2,
},
inView: false,
},
inView: false
}, {
when: 'view zoom is equal to minZoom (with maxZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 2, zoom: 2
{
when: 'view zoom is equal to minZoom (with maxZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 2,
zoom: 2,
},
inView: false,
},
inView: false
}, {
when: 'view zoom is greater than minZoom',
minZoom: 2,
view: {
resolution: 3, zoom: 3
{
when: 'view zoom is greater than minZoom',
minZoom: 2,
view: {
resolution: 3,
zoom: 3,
},
inView: true,
},
inView: true
}, {
when: 'view zoom is greater than minZoom (with maxZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 3, zoom: 3
{
when: 'view zoom is greater than minZoom (with maxZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 3,
zoom: 3,
},
inView: true,
},
inView: true
}, {
when: 'view zoom is equal to maxZoom',
maxZoom: 4,
view: {
resolution: 4, zoom: 4
{
when: 'view zoom is equal to maxZoom',
maxZoom: 4,
view: {
resolution: 4,
zoom: 4,
},
inView: true,
},
inView: true
}, {
when: 'view zoom is equal to maxZoom (with minZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 4, zoom: 4
{
when: 'view zoom is equal to maxZoom (with minZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 4,
zoom: 4,
},
inView: true,
},
inView: true
}, {
when: 'view zoom is greater than maxZoom',
maxZoom: 4,
view: {
resolution: 5, zoom: 5
{
when: 'view zoom is greater than maxZoom',
maxZoom: 4,
view: {
resolution: 5,
zoom: 5,
},
inView: false,
},
inView: false
}, {
when: 'view zoom is greater than maxZoom (with minZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 5, zoom: 5
{
when: 'view zoom is greater than maxZoom (with minZoom)',
minZoom: 2,
maxZoom: 4,
view: {
resolution: 5,
zoom: 5,
},
inView: false,
},
inView: false
}, {
when: 'view resolution is less than minResolution',
minResolution: 2,
view: {
resolution: 1, zoom: 1
{
when: 'view resolution is less than minResolution',
minResolution: 2,
view: {
resolution: 1,
zoom: 1,
},
inView: false,
},
inView: false
}, {
when: 'view resolution is less than minResolution (with maxResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 1, zoom: 1
{
when: 'view resolution is less than minResolution (with maxResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 1,
zoom: 1,
},
inView: false,
},
inView: false
}, {
when: 'view resolution is equal to minResolution',
minResolution: 2,
view: {
resolution: 2, zoom: 2
{
when: 'view resolution is equal to minResolution',
minResolution: 2,
view: {
resolution: 2,
zoom: 2,
},
inView: true,
},
inView: true
}, {
when: 'view resolution is equal to minResolution (with maxResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 2, zoom: 2
{
when: 'view resolution is equal to minResolution (with maxResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 2,
zoom: 2,
},
inView: true,
},
inView: true
}, {
when: 'view resolution is greater than minResolution',
minResolution: 2,
view: {
resolution: 3, zoom: 3
{
when: 'view resolution is greater than minResolution',
minResolution: 2,
view: {
resolution: 3,
zoom: 3,
},
inView: true,
},
inView: true
}, {
when: 'view resolution is greater than minResolution (with maxResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 3, zoom: 3
{
when:
'view resolution is greater than minResolution (with maxResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 3,
zoom: 3,
},
inView: true,
},
inView: true
}, {
when: 'view resolution is equal to maxResolution',
maxResolution: 4,
view: {
resolution: 4, zoom: 4
{
when: 'view resolution is equal to maxResolution',
maxResolution: 4,
view: {
resolution: 4,
zoom: 4,
},
inView: false,
},
inView: false
}, {
when: 'view resolution is equal to maxResolution (with minResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 4, zoom: 4
{
when: 'view resolution is equal to maxResolution (with minResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 4,
zoom: 4,
},
inView: false,
},
inView: false
}, {
when: 'view resolution is greater than maxResolution',
maxResolution: 4,
view: {
resolution: 5, zoom: 5
{
when: 'view resolution is greater than maxResolution',
maxResolution: 4,
view: {
resolution: 5,
zoom: 5,
},
inView: false,
},
inView: false
}, {
when: 'view resolution is greater than maxResolution (with minResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 5, zoom: 5
{
when:
'view resolution is greater than maxResolution (with minResolution)',
minResolution: 2,
maxResolution: 4,
view: {
resolution: 5,
zoom: 5,
},
inView: false,
},
inView: false
}];
];
cases.forEach(function(c, i) {
it('returns ' + c.inView + ' when ' + c.when, function() {
cases.forEach(function (c, i) {
it('returns ' + c.inView + ' when ' + c.when, function () {
if ('visible' in c) {
layer.setVisible(c.visible);
}
@@ -341,26 +383,24 @@ describe('ol.layer.Layer', function() {
expect(inView(layerState, c.view)).to.be(c.inView);
});
});
});
describe('#getLayerState', function() {
describe('#getLayerState', function () {
let layer;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
source: new Source({
projection: getProjection('EPSG:4326')
})
projection: getProjection('EPSG:4326'),
}),
});
});
afterEach(function() {
afterEach(function () {
layer.dispose();
});
it('returns a layerState from the properties values', function() {
it('returns a layerState from the properties values', function () {
layer.setOpacity(1 / 3);
layer.setVisible(false);
layer.setMaxResolution(500);
@@ -377,11 +417,11 @@ describe('ol.layer.Layer', function() {
maxResolution: 500,
minResolution: 0.25,
minZoom: -Infinity,
maxZoom: Infinity
maxZoom: Infinity,
});
});
it('returns a layerState with clamped values', function() {
it('returns a layerState with clamped values', function () {
layer.setOpacity(-1.5);
layer.setVisible(false);
let state = layer.getLayerState();
@@ -394,25 +434,22 @@ describe('ol.layer.Layer', function() {
expect(state.opacity).to.be(1);
expect(state.visible).to.be(true);
});
});
describe('#getSource', function() {
it('gets the layer source', function() {
describe('#getSource', function () {
it('gets the layer source', function () {
const source = new Source({projection: getProjection('EPSG:4326')});
const layer = new Layer({source: source});
expect(layer.getSource()).to.be(source);
});
});
describe('#set("source", source)', function() {
describe('#set("source", source)', function () {
const projection = getProjection('EPSG:4326');
it('sets the layer source', function() {
it('sets the layer source', function () {
const layer = new Layer({
source: new Source({projection: projection})
source: new Source({projection: projection}),
});
const source = new Source({projection: projection});
@@ -420,9 +457,9 @@ describe('ol.layer.Layer', function() {
expect(layer.getSource()).to.be(source);
});
it('calls changed', function() {
it('calls changed', function () {
const layer = new Layer({
source: new Source({projection: projection})
source: new Source({projection: projection}),
});
sinon.spy(layer, 'changed');
@@ -431,7 +468,7 @@ describe('ol.layer.Layer', function() {
expect(layer.changed.calledOnce).to.be(true);
});
it('sets up event listeners', function() {
it('sets up event listeners', function () {
sinon.spy(Layer.prototype, 'handleSourceChange_');
const first = new Source({projection: projection});
@@ -450,15 +487,14 @@ describe('ol.layer.Layer', function() {
// remove spy
Layer.prototype.handleSourceChange_.restore();
});
});
describe('#setSource()', function() {
describe('#setSource()', function () {
const projection = getProjection('EPSG:4326');
it('sets the layer source', function() {
it('sets the layer source', function () {
const layer = new Layer({
source: new Source({projection: projection})
source: new Source({projection: projection}),
});
const source = new Source({projection: projection});
@@ -466,9 +502,9 @@ describe('ol.layer.Layer', function() {
expect(layer.getSource()).to.be(source);
});
it('calls changed', function() {
it('calls changed', function () {
const layer = new Layer({
source: new Source({projection: projection})
source: new Source({projection: projection}),
});
sinon.spy(layer, 'changed');
@@ -477,7 +513,7 @@ describe('ol.layer.Layer', function() {
expect(layer.changed.calledOnce).to.be(true);
});
it('sets up event listeners', function() {
it('sets up event listeners', function () {
sinon.spy(Layer.prototype, 'handleSourceChange_');
const first = new Source({projection: projection});
@@ -496,64 +532,58 @@ describe('ol.layer.Layer', function() {
// remove spy
Layer.prototype.handleSourceChange_.restore();
});
});
describe('#setOpacity', function() {
describe('#setOpacity', function () {
let layer;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
source: new Source({
projection: getProjection('EPSG:4326')
})
projection: getProjection('EPSG:4326'),
}),
});
});
afterEach(function() {
afterEach(function () {
layer.dispose();
});
it('accepts a positive number', function() {
it('accepts a positive number', function () {
layer.setOpacity(0.3);
expect(layer.getOpacity()).to.be(0.3);
});
it('throws on types other than number', function() {
it('throws on types other than number', function () {
function set() {
layer.setOpacity('foo');
}
expect(set).to.throwException();
});
it('triggers a change event', function() {
it('triggers a change event', function () {
const listener = sinon.spy();
layer.on('propertychange', listener);
layer.setOpacity(0.4);
expect(listener.calledOnce).to.be(true);
});
});
describe('#setVisible', function() {
describe('#setVisible', function () {
let layer;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
source: new Source({
projection: getProjection('EPSG:4326')
})
projection: getProjection('EPSG:4326'),
}),
});
});
afterEach(function() {
afterEach(function () {
layer.dispose();
});
it('sets visible property', function() {
it('sets visible property', function () {
layer.setVisible(false);
expect(layer.getVisible()).to.be(false);
@@ -561,7 +591,7 @@ describe('ol.layer.Layer', function() {
expect(layer.getVisible()).to.be(true);
});
it('fires a change event', function() {
it('fires a change event', function () {
const listener = sinon.spy();
layer.on('propertychange', listener);
@@ -571,43 +601,44 @@ describe('ol.layer.Layer', function() {
layer.setVisible(true);
expect(listener.callCount).to.be(2);
});
});
describe('#setMap (unmanaged layer)', function() {
describe('#setMap (unmanaged layer)', function () {
let map;
beforeEach(function() {
beforeEach(function () {
map = new Map({});
});
describe('with map in constructor options', function() {
it('renders the layer', function() {
describe('with map in constructor options', function () {
it('renders the layer', function () {
const layer = new Layer({
map: map
map: map,
});
const frameState = {
layerStatesArray: []
layerStatesArray: [],
};
map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
map.dispatchEvent(
new RenderEvent('precompose', null, frameState, null)
);
expect(frameState.layerStatesArray.length).to.be(1);
const layerState = frameState.layerStatesArray[0];
expect(layerState.layer).to.equal(layer);
});
});
describe('setMap sequences', function() {
describe('setMap sequences', function () {
let mapRenderSpy;
beforeEach(function() {
beforeEach(function () {
mapRenderSpy = sinon.spy(map, 'render');
});
afterEach(function() {
afterEach(function () {
mapRenderSpy.restore();
});
it('requests a render frame', function() {
it('requests a render frame', function () {
const layer = new Layer({});
layer.setMap(map);
@@ -619,44 +650,43 @@ describe('ol.layer.Layer', function() {
layer.setMap(map);
expect(mapRenderSpy.callCount).to.be(3);
});
});
describe('zIndex for unmanaged layers', function() {
describe('zIndex for unmanaged layers', function () {
let frameState, layer;
beforeEach(function() {
beforeEach(function () {
layer = new Layer({
map: map
map: map,
});
frameState = {
layerStatesArray: []
layerStatesArray: [],
};
});
afterEach(function() {
afterEach(function () {
layer.setMap(null);
});
it('has Infinity as zIndex when not configured otherwise', function() {
map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
it('has Infinity as zIndex when not configured otherwise', function () {
map.dispatchEvent(
new RenderEvent('precompose', null, frameState, null)
);
const layerState = frameState.layerStatesArray[0];
expect(layerState.zIndex).to.be(Infinity);
});
it('respects the configured zIndex', function() {
[-5, 0, 42].forEach(index => {
it('respects the configured zIndex', function () {
[-5, 0, 42].forEach((index) => {
layer.setZIndex(index);
map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
map.dispatchEvent(
new RenderEvent('precompose', null, frameState, null)
);
const layerState = frameState.layerStatesArray[0];
frameState.layerStatesArray.length = 0;
expect(layerState.zIndex).to.be(index);
});
});
});
});
});
+25 -29
View File
@@ -1,80 +1,76 @@
import {Map, View} from '../../../../src/ol/index.js';
import TileLayer from '../../../../src/ol/layer/Tile.js';
import {Map, View} from '../../../../src/ol/index.js';
import {OSM, XYZ} from '../../../../src/ol/source.js';
describe('ol.layer.Tile', function() {
describe('constructor (defaults)', function() {
describe('ol.layer.Tile', function () {
describe('constructor (defaults)', function () {
let layer;
beforeEach(function() {
beforeEach(function () {
layer = new TileLayer({
source: new OSM()
source: new OSM(),
});
});
afterEach(function() {
afterEach(function () {
layer.dispose();
});
it('creates an instance', function() {
it('creates an instance', function () {
expect(layer).to.be.a(TileLayer);
});
it('provides default preload', function() {
it('provides default preload', function () {
expect(layer.getPreload()).to.be(0);
});
it('provides default useInterimTilesOnError', function() {
it('provides default useInterimTilesOnError', function () {
expect(layer.getUseInterimTilesOnError()).to.be(true);
});
});
describe('frameState.animate after tile transition with layer opacity', function() {
describe('frameState.animate after tile transition with layer opacity', function () {
let target, map;
beforeEach(function(done) {
beforeEach(function (done) {
target = document.createElement('div');
Object.assign(target.style, {
position: 'absolute',
left: '-1000px',
top: '-1000px',
width: '256px',
height: '256px'
height: '256px',
});
document.body.appendChild(target);
map = new Map({
target: target,
view: new View({center: [0, 0], zoom: 1})
view: new View({center: [0, 0], zoom: 1}),
});
map.once('rendercomplete', function() {
map.once('rendercomplete', function () {
done();
});
});
afterEach(function() {
afterEach(function () {
map.dispose();
document.body.removeChild(target);
});
it('sets frameState.animate to false when opacity is 1', function(done) {
it('sets frameState.animate to false when opacity is 1', function (done) {
let lastFrameState;
const layer = new TileLayer({
opacity: 1,
source: new XYZ({
url: 'spec/ol/data/osm-0-0-0.png'
})
url: 'spec/ol/data/osm-0-0-0.png',
}),
});
layer.on('postrender', function(event) {
layer.on('postrender', function (event) {
lastFrameState = event.frameState;
});
map.once('rendercomplete', function() {
map.once('rendercomplete', function () {
expect(lastFrameState.animate).to.be(false);
done();
});
@@ -82,19 +78,19 @@ describe('ol.layer.Tile', function() {
map.addLayer(layer);
});
it('sets frameState.animate to false when opacity is 0.5', function(done) {
it('sets frameState.animate to false when opacity is 0.5', function (done) {
let lastFrameState;
const layer = new TileLayer({
opacity: 0.5,
source: new XYZ({
url: 'spec/ol/data/osm-0-0-0.png'
})
url: 'spec/ol/data/osm-0-0-0.png',
}),
});
layer.on('postrender', function(event) {
layer.on('postrender', function (event) {
lastFrameState = event.frameState;
});
map.once('rendercomplete', function() {
map.once('rendercomplete', function () {
expect(lastFrameState.animate).to.be(false);
done();
});
+49 -61
View File
@@ -1,113 +1,106 @@
import Feature from '../../../../src/ol/Feature.js';
import ImageStyle from '../../../../src/ol/style/Image.js';
import Layer from '../../../../src/ol/layer/Layer.js';
import Map from '../../../../src/ol/Map.js';
import Point from '../../../../src/ol/geom/Point.js';
import Style, {createDefaultStyle} from '../../../../src/ol/style/Style.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import Style, {createDefaultStyle} from '../../../../src/ol/style/Style.js';
import Feature from '../../../../src/ol/Feature.js';
import Point from '../../../../src/ol/geom/Point.js';
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import ImageStyle from '../../../../src/ol/style/Image.js';
describe('ol.layer.Vector', function() {
describe('constructor', function() {
describe('ol.layer.Vector', function () {
describe('constructor', function () {
const source = new VectorSource();
const style = new Style();
it('creates a new layer', function() {
it('creates a new layer', function () {
const layer = new VectorLayer({source: source});
expect(layer).to.be.a(VectorLayer);
expect(layer).to.be.a(Layer);
});
it('accepts a style option with a single style', function() {
it('accepts a style option with a single style', function () {
const layer = new VectorLayer({
source: source,
style: style
style: style,
});
const styleFunction = layer.getStyleFunction();
expect(styleFunction()).to.eql([style]);
});
it('accepts a style option with an array of styles', function() {
it('accepts a style option with an array of styles', function () {
const layer = new VectorLayer({
source: source,
style: [style]
style: [style],
});
const styleFunction = layer.getStyleFunction();
expect(styleFunction()).to.eql([style]);
});
it('accepts a style option with a style function', function() {
it('accepts a style option with a style function', function () {
const layer = new VectorLayer({
source: source,
style: function(feature, resolution) {
style: function (feature, resolution) {
return [style];
}
},
});
const styleFunction = layer.getStyleFunction();
expect(styleFunction()).to.eql([style]);
});
});
describe('#setStyle()', function() {
describe('#setStyle()', function () {
let layer, style;
beforeEach(function() {
beforeEach(function () {
layer = new VectorLayer({
source: new VectorSource()
source: new VectorSource(),
});
style = new Style();
});
it('allows the style to be set after construction', function() {
it('allows the style to be set after construction', function () {
layer.setStyle(style);
expect(layer.getStyle()).to.be(style);
});
it('dispatches the change event', function(done) {
layer.on('change', function() {
it('dispatches the change event', function (done) {
layer.on('change', function () {
done();
});
layer.setStyle(style);
});
it('updates the internal style function', function() {
it('updates the internal style function', function () {
expect(layer.getStyleFunction()).to.be(createDefaultStyle);
layer.setStyle(style);
expect(layer.getStyleFunction()).not.to.be(
createDefaultStyle);
expect(layer.getStyleFunction()).not.to.be(createDefaultStyle);
});
it('allows setting an null style', function() {
it('allows setting an null style', function () {
layer.setStyle(null);
expect(layer.getStyle()).to.be(null);
expect(layer.getStyleFunction()).to.be(undefined);
});
it('sets the default style when passing undefined', function() {
it('sets the default style when passing undefined', function () {
layer.setStyle(style);
layer.setStyle(undefined);
expect(layer.getStyle()).to.be(createDefaultStyle);
expect(layer.getStyleFunction()).to.be(createDefaultStyle);
});
});
describe('#getStyle()', function() {
describe('#getStyle()', function () {
const source = new VectorSource();
const style = new Style();
it('returns what is provided to setStyle', function() {
it('returns what is provided to setStyle', function () {
const layer = new VectorLayer({
source: source
source: source,
});
expect(layer.getStyle()).to.be(createDefaultStyle);
@@ -118,56 +111,55 @@ describe('ol.layer.Vector', function() {
layer.setStyle([style]);
expect(layer.getStyle()).to.eql([style]);
const styleFunction = function(feature, resolution) {
const styleFunction = function (feature, resolution) {
return [style];
};
layer.setStyle(styleFunction);
expect(layer.getStyle()).to.be(styleFunction);
});
});
describe('#getFeatures()', function() {
describe('#getFeatures()', function () {
let map, layer;
beforeEach(function() {
beforeEach(function () {
const source = new VectorSource({
features: [
new Feature({
geometry: new Point([-1000000, 0]),
name: 'feature1'
name: 'feature1',
}),
new Feature({
geometry: new Point([1000000, 0]),
name: 'feature2'
})
]
name: 'feature2',
}),
],
});
const feature = new Feature({
geometry: new Point([-1000000, 0]),
name: 'feature with no size'
name: 'feature with no size',
});
const testImage = new ImageStyle({
opacity: 1,
displacement: []
displacement: [],
});
testImage.getImageState = () => {};
testImage.listenImageChange = () => {};
testImage.getImageSize = () => {};
feature.setStyle([new Style({
image: testImage
})]);
feature.setStyle([
new Style({
image: testImage,
}),
]);
source.addFeature(feature);
layer = new VectorLayer({
source
source,
});
const container = document.createElement('div');
container.style.width = '256px';
@@ -175,31 +167,27 @@ describe('ol.layer.Vector', function() {
document.body.appendChild(container);
map = new Map({
target: container,
layers: [
layer
],
layers: [layer],
view: new View({
zoom: 2,
center: [0, 0]
})
center: [0, 0],
}),
});
});
afterEach(function() {
afterEach(function () {
document.body.removeChild(map.getTargetElement());
map.setTarget(null);
});
it('detects features properly', function(done) {
it('detects features properly', function (done) {
map.renderSync();
const pixel = map.getPixelFromCoordinate([-1000000, 0]);
layer.getFeatures(pixel).then(function(features) {
layer.getFeatures(pixel).then(function (features) {
expect(features.length).to.equal(1);
expect(features[0].get('name')).to.be('feature1');
done();
});
});
});
});
+16 -22
View File
@@ -1,30 +1,28 @@
import Feature from '../../../../src/ol/Feature.js';
import Point from '../../../../src/ol/geom/Point.js';
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import Point from '../../../../src/ol/geom/Point.js';
import VectorImageLayer from '../../../../src/ol/layer/VectorImage.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import View from '../../../../src/ol/View.js';
describe('ol/layer/VectorImage', function() {
describe('#getFeatures()', function() {
describe('ol/layer/VectorImage', function () {
describe('#getFeatures()', function () {
let map, layer;
beforeEach(function() {
beforeEach(function () {
layer = new VectorImageLayer({
source: new VectorSource({
features: [
new Feature({
geometry: new Point([-1000000, 0]),
name: 'feature1'
name: 'feature1',
}),
new Feature({
geometry: new Point([1000000, 0]),
name: 'feture2'
})
]
})
name: 'feture2',
}),
],
}),
});
const container = document.createElement('div');
container.style.width = '256px';
@@ -32,30 +30,26 @@ describe('ol/layer/VectorImage', function() {
document.body.appendChild(container);
map = new Map({
target: container,
layers: [
layer
],
layers: [layer],
view: new View({
zoom: 2,
center: [0, 0]
})
center: [0, 0],
}),
});
});
afterEach(function() {
afterEach(function () {
document.body.removeChild(map.getTargetElement());
map.setTarget(null);
});
it('detects features properly', function(done) {
it('detects features properly', function (done) {
map.renderSync();
const pixel = map.getPixelFromCoordinate([-1000000, 0]);
layer.getFeatures(pixel).then(function(features) {
layer.getFeatures(pixel).then(function (features) {
expect(features[0].get('name')).to.be('feature1');
done();
});
});
});
});
+53 -54
View File
@@ -1,71 +1,66 @@
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
import Map from '../../../../src/ol/Map.js';
import VectorTileLayer from '../../../../src/ol/layer/VectorTile.js';
import VectorTileSource from '../../../../src/ol/source/VectorTile.js';
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
import View from '../../../../src/ol/View.js';
import Map from '../../../../src/ol/Map.js';
import {fromLonLat} from '../../../../src/ol/proj.js';
describe('ol.layer.VectorTile', function() {
describe('constructor (defaults)', function() {
describe('ol.layer.VectorTile', function () {
describe('constructor (defaults)', function () {
let layer;
beforeEach(function() {
beforeEach(function () {
layer = new VectorTileLayer({
source: new VectorTileSource({})
source: new VectorTileSource({}),
});
});
afterEach(function() {
afterEach(function () {
layer.dispose();
});
it('creates an instance', function() {
it('creates an instance', function () {
expect(layer).to.be.a(VectorTileLayer);
});
it('provides default preload', function() {
it('provides default preload', function () {
expect(layer.getPreload()).to.be(0);
});
it('provides default useInterimTilesOnError', function() {
it('provides default useInterimTilesOnError', function () {
expect(layer.getUseInterimTilesOnError()).to.be(true);
});
it('provides default renderMode', function() {
it('provides default renderMode', function () {
expect(layer.getRenderMode()).to.be('hybrid');
});
});
describe('constructor (options)', function() {
it('works with options', function() {
describe('constructor (options)', function () {
it('works with options', function () {
let layer = new VectorTileLayer({
renderMode: 'hybrid',
source: new VectorTileSource({})
source: new VectorTileSource({}),
});
expect(layer.getRenderMode()).to.be('hybrid');
layer = new VectorTileLayer({
renderMode: 'image',
source: new VectorTileSource({})
source: new VectorTileSource({}),
});
expect(layer.getRenderMode()).to.be('image');
expect(function() {
expect(function () {
layer = new VectorTileLayer({
renderMode: 'foo',
source: new VectorTileSource({})
source: new VectorTileSource({}),
});
}).to.throwException();
});
});
describe('#getFeatures()', function() {
describe('#getFeatures()', function () {
let map, layer;
beforeEach(function() {
beforeEach(function () {
layer = new VectorTileLayer({
source: new VectorTileSource({
format: new GeoJSON(),
@@ -95,8 +90,8 @@ describe('ol.layer.VectorTile', function() {
}
]
}
`
})
`,
}),
});
const container = document.createElement('div');
container.style.width = '256px';
@@ -104,56 +99,60 @@ describe('ol.layer.VectorTile', function() {
document.body.appendChild(container);
map = new Map({
target: container,
layers: [
layer
],
layers: [layer],
view: new View({
zoom: 0,
center: [0, 0]
})
center: [0, 0],
}),
});
});
afterEach(function() {
afterEach(function () {
document.body.removeChild(map.getTargetElement());
map.setTarget(null);
});
it('detects features properly', function(done) {
map.once('rendercomplete', function() {
it('detects features properly', function (done) {
map.once('rendercomplete', function () {
const pixel = map.getPixelFromCoordinate(fromLonLat([-36, 0]));
layer.getFeatures(pixel).then(function(features) {
expect(features[0].get('name')).to.be('feature1');
done();
}).catch(done);
layer
.getFeatures(pixel)
.then(function (features) {
expect(features[0].get('name')).to.be('feature1');
done();
})
.catch(done);
});
});
it('does not give false positives', function(done) {
map.once('rendercomplete', function() {
it('does not give false positives', function (done) {
map.once('rendercomplete', function () {
const pixel = map.getPixelFromCoordinate(fromLonLat([0, 0]));
layer.getFeatures(pixel).then(function(features) {
expect(features.length).to.be(0);
done();
}).catch(done);
layer
.getFeatures(pixel)
.then(function (features) {
expect(features.length).to.be(0);
done();
})
.catch(done);
});
});
it('stores separate hit detection data for each layer that uses the source', function(done) {
it('stores separate hit detection data for each layer that uses the source', function (done) {
const layer2 = new VectorTileLayer({
source: layer.getSource()
source: layer.getSource(),
});
map.addLayer(layer2);
map.once('rendercomplete', function() {
map.once('rendercomplete', function () {
const pixel = map.getPixelFromCoordinate(fromLonLat([-36, 0]));
Promise.all([layer.getFeatures(pixel), layer2.getFeatures(pixel)]).then(function(result) {
const tile = layer.getSource().tileCache.get('0/0/0');
expect(Object.keys(tile.hitDetectionImageData).length).to.be(2);
done();
}).catch(done);
Promise.all([layer.getFeatures(pixel), layer2.getFeatures(pixel)])
.then(function (result) {
const tile = layer.getSource().tileCache.get('0/0/0');
expect(Object.keys(tile.hitDetectionImageData).length).to.be(2);
done();
})
.catch(done);
});
});
});
});
+265 -239
View File
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More