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:
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user