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,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);
|
||||
|
||||
Reference in New Issue
Block a user