Use blocked scoped variables

In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions
+11 -11
View File
@@ -7,7 +7,7 @@ import DragAndDrop from '../../../../src/ol/interaction/DragAndDrop.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
where('FileReader').describe('ol.interaction.DragAndDrop', function() {
var viewport, map, interaction;
let viewport, map, interaction;
beforeEach(function() {
viewport = new EventTarget();
@@ -27,7 +27,7 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var interaction = new DragAndDrop();
const interaction = new DragAndDrop();
expect(interaction).to.be.an(DragAndDrop);
});
@@ -36,8 +36,8 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
});
it('accepts a source option', function() {
var source = new VectorSource();
var drop = new DragAndDrop({
const source = new VectorSource();
const drop = new DragAndDrop({
formatConstructors: [GeoJSON],
source: source
});
@@ -72,7 +72,7 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
});
it('registers and unregisters listeners on a custom target', function() {
var customTarget = new EventTarget();
const customTarget = new EventTarget();
interaction = new DragAndDrop({
formatConstructors: [GeoJSON],
target: customTarget
@@ -89,7 +89,7 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
});
describe('#handleDrop_', function() {
var OrigFileReader;
let OrigFileReader;
beforeEach(function() {
OrigFileReader = FileReader;
@@ -114,7 +114,7 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
done();
});
interaction.setMap(map);
var event = new Event();
const event = new Event();
event.dataTransfer = {};
event.type = 'dragenter';
viewport.dispatchEvent(event);
@@ -136,20 +136,20 @@ where('FileReader').describe('ol.interaction.DragAndDrop', function() {
});
it('adds dropped features to a source', function(done) {
var source = new VectorSource();
var drop = new DragAndDrop({
const source = new VectorSource();
const drop = new DragAndDrop({
formatConstructors: [GeoJSON],
source: source
});
drop.setMap(map);
drop.on('addfeatures', function(evt) {
var features = source.getFeatures();
const features = source.getFeatures();
expect(features.length).to.be(1);
done();
});
var event = new Event();
const event = new Event();
event.dataTransfer = {};
event.type = 'dragenter';
viewport.dispatchEvent(event);
@@ -12,7 +12,7 @@ describe('ol.interaction.DragRotateAndZoom', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new DragRotateAndZoom();
const instance = new DragRotateAndZoom();
expect(instance).to.be.an(DragRotateAndZoom);
});
@@ -20,22 +20,22 @@ describe('ol.interaction.DragRotateAndZoom', function() {
describe('#handleDragEvent_()', function() {
var target, map, interaction;
let target, map, interaction;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function(done) {
target = document.createElement('div');
var style = target.style;
const style = target.style;
style.position = 'absolute';
style.left = '-1000px';
style.top = '-1000px';
style.width = width + 'px';
style.height = height + 'px';
document.body.appendChild(target);
var source = new VectorSource();
var layer = new VectorLayer({source: source});
const source = new VectorSource();
const layer = new VectorLayer({source: source});
interaction = new DragRotateAndZoom();
map = new Map({
target: target,
@@ -58,11 +58,11 @@ describe('ol.interaction.DragRotateAndZoom', function() {
});
it('does not rotate when rotation is disabled on the view', function() {
var event = new MapBrowserPointerEvent('pointermove', map,
new PointerEvent('pointermove', {clientX: 20, clientY: 10}, {pointerType: 'mouse'}),
true);
let event = new MapBrowserPointerEvent('pointermove', map,
new PointerEvent('pointermove', {clientX: 20, clientY: 10}, {pointerType: 'mouse'}),
true);
interaction.lastAngle_ = Math.PI;
var spy = sinon.spy(Interaction, 'rotateWithoutConstraints');
const spy = sinon.spy(Interaction, 'rotateWithoutConstraints');
interaction.handleDragEvent_(event);
expect(spy.callCount).to.be(1);
expect(interaction.lastAngle_).to.be(-0.8308214428190254);
@@ -73,8 +73,8 @@ describe('ol.interaction.DragRotateAndZoom', function() {
enableRotation: false
}));
event = new MapBrowserPointerEvent('pointermove', map,
new PointerEvent('pointermove', {clientX: 24, clientY: 16}, {pointerType: 'mouse'}),
true);
new PointerEvent('pointermove', {clientX: 24, clientY: 16}, {pointerType: 'mouse'}),
true);
interaction.handleDragEvent_(event);
expect(spy.callCount).to.be(1);
Interaction.rotateWithoutConstraints.restore();
+18 -18
View File
@@ -10,14 +10,14 @@ import VectorSource from '../../../../src/ol/source/Vector.js';
describe('ol.interaction.DragZoom', function() {
var target, map, source;
let target, map, source;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function(done) {
target = document.createElement('div');
var style = target.style;
const style = target.style;
style.position = 'absolute';
style.left = '-1000px';
style.top = '-1000px';
@@ -25,7 +25,7 @@ describe('ol.interaction.DragZoom', function() {
style.height = height + 'px';
document.body.appendChild(target);
source = new VectorSource();
var layer = new VectorLayer({source: source});
const layer = new VectorLayer({source: source});
map = new Map({
target: target,
layers: [layer],
@@ -48,15 +48,15 @@ describe('ol.interaction.DragZoom', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new DragZoom();
const instance = new DragZoom();
expect(instance).to.be.an(DragZoom);
});
it('sets "ol-dragzoom" as box className', function() {
var instance = new DragZoom();
const instance = new DragZoom();
expect(instance.box_.element_.className).to.be('ol-box ol-dragzoom');
});
it('sets a custom box className', function() {
var instance = new DragZoom({className: 'test-dragzoom'});
const instance = new DragZoom({className: 'test-dragzoom'});
expect(instance.box_.element_.className).to.be('ol-box test-dragzoom');
});
@@ -65,20 +65,20 @@ describe('ol.interaction.DragZoom', function() {
describe('#onBoxEnd()', function() {
it('centers the view on the box geometry', function(done) {
var interaction = new DragZoom({
const interaction = new DragZoom({
duration: 10
});
map.addInteraction(interaction);
var box = new _ol_render_Box_();
var extent = [-110, 40, -90, 60];
const box = new _ol_render_Box_();
const extent = [-110, 40, -90, 60];
box.geometry_ = polygonFromExtent(extent);
interaction.box_ = box;
interaction.onBoxEnd();
setTimeout(function() {
var view = map.getView();
var center = view.getCenter();
const view = map.getView();
const center = view.getCenter();
expect(center).to.eql(_ol_extent_.getCenter(extent));
done();
}, 50);
@@ -86,14 +86,14 @@ describe('ol.interaction.DragZoom', function() {
});
it('sets new resolution while zooming out', function(done) {
var interaction = new DragZoom({
const interaction = new DragZoom({
duration: 10,
out: true
});
map.addInteraction(interaction);
var box = new _ol_render_Box_();
var extent = [-11.25, -11.25, 11.25, 11.25];
const box = new _ol_render_Box_();
const extent = [-11.25, -11.25, 11.25, 11.25];
box.geometry_ = polygonFromExtent(extent);
interaction.box_ = box;
@@ -101,8 +101,8 @@ describe('ol.interaction.DragZoom', function() {
setTimeout(function() {
interaction.onBoxEnd();
setTimeout(function() {
var view = map.getView();
var resolution = view.getResolution();
const view = map.getView();
const resolution = view.getResolution();
expect(resolution).to.eql(view.constrainResolution(0.5));
done();
}, 50);
+94 -94
View File
@@ -20,14 +20,14 @@ import VectorSource from '../../../../src/ol/source/Vector.js';
describe('ol.interaction.Draw', function() {
var target, map, source;
let target, map, source;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function(done) {
target = document.createElement('div');
var style = target.style;
const style = target.style;
style.position = 'absolute';
style.left = '-1000px';
style.top = '-1000px';
@@ -35,7 +35,7 @@ describe('ol.interaction.Draw', function() {
style.height = height + 'px';
document.body.appendChild(target);
source = new VectorSource();
var layer = new VectorLayer({source: source});
const layer = new VectorLayer({source: source});
map = new Map({
target: target,
layers: [layer],
@@ -64,11 +64,11 @@ describe('ol.interaction.Draw', function() {
* @param {boolean=} opt_shiftKey Shift key is pressed.
*/
function simulateEvent(type, x, y, opt_shiftKey) {
var viewport = map.getViewport();
const viewport = map.getViewport();
// calculated in case body has top < 0 (test runner with small window)
var position = viewport.getBoundingClientRect();
var shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
var event = new PointerEvent(type, {
const position = viewport.getBoundingClientRect();
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
const event = new PointerEvent(type, {
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
shiftKey: shiftKey
@@ -79,7 +79,7 @@ describe('ol.interaction.Draw', function() {
describe('constructor', function() {
it('creates a new interaction', function() {
var draw = new Draw({
const draw = new Draw({
source: source,
type: 'Point'
});
@@ -88,13 +88,13 @@ describe('ol.interaction.Draw', function() {
});
it('accepts a freehand option', function() {
var draw = new Draw({
const draw = new Draw({
source: source,
type: 'LineString',
freehand: true
});
var event = new PointerEvent('pointerdown', {
const event = new PointerEvent('pointerdown', {
clientX: 0,
clientY: 0,
shiftKey: false
@@ -108,7 +108,7 @@ describe('ol.interaction.Draw', function() {
describe('specifying a geometryName', function() {
beforeEach(function() {
var draw = new Draw({
const draw = new Draw({
source: source,
geometryName: 'the_geom',
type: 'Point'
@@ -120,8 +120,8 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerup', 10, 20);
var features = source.getFeatures();
var geometry = features[0].getGeometry();
const features = source.getFeatures();
const geometry = features[0].getGeometry();
expect(features[0].getGeometryName()).to.equal('the_geom');
expect(geometry).to.be.a(Point);
});
@@ -129,7 +129,7 @@ describe('ol.interaction.Draw', function() {
describe('specifying a clickTolerance', function() {
beforeEach(function() {
var draw = new Draw({
const draw = new Draw({
source: source,
type: 'Point',
clickTolerance: 6
@@ -138,7 +138,7 @@ describe('ol.interaction.Draw', function() {
});
it('adds a point when below the tolerance', function() {
var features;
let features;
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
@@ -155,7 +155,7 @@ describe('ol.interaction.Draw', function() {
});
describe('drawing points', function() {
var draw;
let draw;
beforeEach(function() {
draw = new Draw({
@@ -169,9 +169,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerup', 10, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Point);
expect(geometry.getCoordinates()).to.eql([10, -20]);
});
@@ -181,7 +181,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointermove', 18, 20);
simulateEvent('pointerup', 18, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(0);
});
@@ -189,13 +189,13 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20, true);
simulateEvent('pointerup', 10, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(0);
});
it('triggers draw events', function() {
var ds = sinon.spy();
var de = sinon.spy();
const ds = sinon.spy();
const de = sinon.spy();
_ol_events_.listen(draw, 'drawstart', ds);
_ol_events_.listen(draw, 'drawend', de);
simulateEvent('pointermove', 10, 20);
@@ -209,16 +209,16 @@ describe('ol.interaction.Draw', function() {
});
it('triggers drawend event before inserting the feature', function() {
var receivedEvents = {
const receivedEvents = {
end: 0,
addfeature: 0
};
_ol_events_.listen(draw, 'drawend',
function() {
expect(receivedEvents.end).to.be(0);
expect(receivedEvents.addfeature).to.be(0);
++receivedEvents.end;
});
function() {
expect(receivedEvents.end).to.be(0);
expect(receivedEvents.addfeature).to.be(0);
++receivedEvents.end;
});
source.on('addfeature', function() {
expect(receivedEvents.end).to.be(1);
expect(receivedEvents.addfeature).to.be(0);
@@ -246,9 +246,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointermove', 30, 15);
simulateEvent('pointerdown', 30, 15);
simulateEvent('pointerup', 30, 15);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(MultiPoint);
expect(geometry.getCoordinates()).to.eql([[30, -15]]);
});
@@ -256,7 +256,7 @@ describe('ol.interaction.Draw', function() {
});
describe('drawing linestrings', function() {
var draw;
let draw;
beforeEach(function() {
draw = new Draw({
@@ -281,9 +281,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 30, 20);
simulateEvent('pointerup', 30, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(LineString);
expect(geometry.getCoordinates()).to.eql([[10, -20], [30, -20]]);
});
@@ -323,12 +323,12 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdrag', 20, 40, true);
simulateEvent('pointerup', 20, 40, true);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(LineString);
expect(geometry.getCoordinates()).to.eql(
[[10, -20], [20, -30], [20, -40]]);
[[10, -20], [20, -30], [20, -40]]);
});
it('allows freehand mode for part of the drawing', function() {
@@ -360,12 +360,12 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 60, 70);
simulateEvent('pointerup', 60, 70);
var features = source.getFeatures();
const features = source.getFeatures();
// expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(LineString);
expect(geometry.getCoordinates()).to.eql(
[[10, -20], [20, -30], [30, -40], [40, -50], [50, -60], [60, -70]]);
[[10, -20], [20, -30], [30, -40], [40, -50], [50, -60], [60, -70]]);
});
it('does not add a point with a significant drag', function() {
@@ -389,16 +389,16 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 30, 20);
simulateEvent('pointerup', 30, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(LineString);
expect(geometry.getCoordinates()).to.eql([[10, -20], [30, -20]]);
});
it('triggers draw events', function() {
var ds = sinon.spy();
var de = sinon.spy();
const ds = sinon.spy();
const de = sinon.spy();
_ol_events_.listen(draw, 'drawstart', ds);
_ol_events_.listen(draw, 'drawend', de);
@@ -427,7 +427,7 @@ describe('ol.interaction.Draw', function() {
describe('drawing with a finishCondition', function() {
beforeEach(function() {
var draw = new Draw({
const draw = new Draw({
source: source,
type: 'LineString',
finishCondition: function(event) {
@@ -441,7 +441,7 @@ describe('ol.interaction.Draw', function() {
});
it('draws a linestring failing to finish it first, the finishes it', function() {
var features;
let features;
// first point
simulateEvent('pointermove', 10, 20);
@@ -498,9 +498,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 30, 20);
simulateEvent('pointerup', 30, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(MultiLineString);
expect(geometry.getCoordinates()).to.eql([[[10, -20], [30, -20]]]);
});
@@ -508,7 +508,7 @@ describe('ol.interaction.Draw', function() {
});
describe('drawing polygons', function() {
var draw;
let draw;
beforeEach(function() {
draw = new Draw({
@@ -519,8 +519,8 @@ describe('ol.interaction.Draw', function() {
});
function isClosed(polygon) {
var first = polygon.getFirstCoordinate();
var last = polygon.getLastCoordinate();
const first = polygon.getFirstCoordinate();
const last = polygon.getLastCoordinate();
expect(first).to.eql(last);
}
@@ -548,9 +548,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerup', 10, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Polygon);
expect(geometry.getCoordinates()).to.eql([
@@ -626,9 +626,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 40, 10);
simulateEvent('pointerup', 40, 10);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Polygon);
expect(geometry.getCoordinates()).to.eql([
@@ -650,9 +650,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 40, 10);
simulateEvent('pointerup', 40, 10);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Polygon);
expect(geometry.getCoordinates()).to.eql([
@@ -661,8 +661,8 @@ describe('ol.interaction.Draw', function() {
});
it('triggers draw events', function() {
var ds = sinon.spy();
var de = sinon.spy();
const ds = sinon.spy();
const de = sinon.spy();
_ol_events_.listen(draw, 'drawstart', ds);
_ol_events_.listen(draw, 'drawend', de);
@@ -724,11 +724,11 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerup', 10, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(MultiPolygon);
var coordinates = geometry.getCoordinates();
const coordinates = geometry.getCoordinates();
expect(coordinates).to.have.length(1);
expect(coordinates[0]).to.eql([
@@ -756,11 +756,11 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 40, 10);
simulateEvent('pointerup', 40, 10);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(MultiPolygon);
var coordinates = geometry.getCoordinates();
const coordinates = geometry.getCoordinates();
expect(coordinates).to.have.length(1);
expect(coordinates[0]).to.eql([
@@ -771,7 +771,7 @@ describe('ol.interaction.Draw', function() {
});
describe('drawing circles', function() {
var draw;
let draw;
beforeEach(function() {
draw = new Draw({
@@ -792,9 +792,9 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 30, 20);
simulateEvent('pointerup', 30, 20);
var features = source.getFeatures();
const features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Circle);
expect(geometry.getCenter()).to.eql([10, -20]);
expect(geometry.getRadius()).to.eql(20);
@@ -819,8 +819,8 @@ describe('ol.interaction.Draw', function() {
});
it('triggers draw events', function() {
var ds = sinon.spy();
var de = sinon.spy();
const ds = sinon.spy();
const de = sinon.spy();
_ol_events_.listen(draw, 'drawstart', ds);
_ol_events_.listen(draw, 'drawend', de);
@@ -843,7 +843,7 @@ describe('ol.interaction.Draw', function() {
});
describe('#setActive()', function() {
var interaction;
let interaction;
beforeEach(function() {
interaction = new Draw({
@@ -868,7 +868,7 @@ describe('ol.interaction.Draw', function() {
describe('#setActive(false)', function() {
it('unsets the map from the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
const spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setActive(false);
expect(spy.getCall(0).args[0]).to.be(null);
});
@@ -877,8 +877,8 @@ describe('ol.interaction.Draw', function() {
expect(interaction.sketchFeature_).to.be(null);
});
it('fires change:active', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
var listenerSpy = sinon.spy(function() {
const spy = sinon.spy(interaction.overlay_, 'setMap');
const listenerSpy = sinon.spy(function() {
// test that the interaction's change:active listener is called first
expect(spy.getCall(0).args[0]).to.be(null);
});
@@ -893,13 +893,13 @@ describe('ol.interaction.Draw', function() {
interaction.setActive(false);
});
it('sets the map into the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
const spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setActive(true);
expect(spy.getCall(0).args[0]).to.be(map);
});
it('fires change:active', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
var listenerSpy = sinon.spy(function() {
const spy = sinon.spy(interaction.overlay_, 'setMap');
const listenerSpy = sinon.spy(function() {
// test that the interaction's change:active listener is called first
expect(spy.getCall(0).args[0]).to.be(map);
});
@@ -912,7 +912,7 @@ describe('ol.interaction.Draw', function() {
});
describe('#setMap()', function() {
var interaction;
let interaction;
beforeEach(function() {
interaction = new Draw({
@@ -935,7 +935,7 @@ describe('ol.interaction.Draw', function() {
});
describe('#setMap(null) when interaction is active', function() {
it('unsets the map from the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
const spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setMap(null);
expect(spy.getCall(0).args[0]).to.be(null);
});
@@ -949,7 +949,7 @@ describe('ol.interaction.Draw', function() {
describe('#setMap(map)', function() {
describe('#setMap(map) when interaction is active', function() {
it('sets the map into the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
const spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setMap(map);
expect(spy.getCall(0).args[0]).to.be(map);
});
@@ -957,7 +957,7 @@ describe('ol.interaction.Draw', function() {
describe('#setMap(map) when interaction is not active', function() {
it('does not set the map into the feature overlay', function() {
interaction.setActive(false);
var spy = sinon.spy(interaction.overlay_, 'setMap');
const spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setMap(map);
expect(spy.getCall(0).args[0]).to.be(null);
});
@@ -968,7 +968,7 @@ describe('ol.interaction.Draw', function() {
describe('ol.interaction.Draw.createRegularPolygon', function() {
it('creates a regular polygon in Circle mode', function() {
var draw = new Draw({
const draw = new Draw({
source: source,
type: 'Circle',
geometryFunction:
@@ -986,10 +986,10 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 20, 20);
simulateEvent('pointerup', 20, 20);
var features = source.getFeatures();
var geometry = features[0].getGeometry();
const features = source.getFeatures();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Polygon);
var coordinates = geometry.getCoordinates();
const coordinates = geometry.getCoordinates();
expect(coordinates[0].length).to.eql(5);
expect(coordinates[0][0][0]).to.roughlyEqual(20, 1e-9);
expect(coordinates[0][0][1]).to.roughlyEqual(20, 1e-9);
@@ -998,7 +998,7 @@ describe('ol.interaction.Draw', function() {
describe('ol.interaction.Draw.createBox', function() {
it('creates a box-shaped polygon in Circle mode', function() {
var draw = new Draw({
const draw = new Draw({
source: source,
type: 'Circle',
geometryFunction: Draw.createBox()
@@ -1015,10 +1015,10 @@ describe('ol.interaction.Draw', function() {
simulateEvent('pointerdown', 20, 20);
simulateEvent('pointerup', 20, 20);
var features = source.getFeatures();
var geometry = features[0].getGeometry();
const features = source.getFeatures();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Polygon);
var coordinates = geometry.getCoordinates();
const coordinates = geometry.getCoordinates();
expect(coordinates[0]).to.have.length(5);
expect(geometry.getArea()).to.equal(400);
expect(geometry.getExtent()).to.eql([0, -20, 20, 0]);
@@ -1026,8 +1026,8 @@ describe('ol.interaction.Draw', function() {
});
describe('extend an existing feature', function() {
var draw;
var feature;
let draw;
let feature;
beforeEach(function() {
draw = new Draw({
@@ -1036,7 +1036,7 @@ describe('ol.interaction.Draw', function() {
});
map.addInteraction(draw);
feature = new Feature(
new LineString([[0, 0], [1, 1], [2, 0]]));
new LineString([[0, 0], [1, 1], [2, 0]]));
});
it('sets the initial state', function() {
@@ -1047,7 +1047,7 @@ describe('ol.interaction.Draw', function() {
});
it('dispatches a drawstart event', function() {
var spy = sinon.spy();
const spy = sinon.spy();
_ol_events_.listen(draw, 'drawstart', spy);
draw.extend(feature);
expect(spy.callCount).to.be(1);
+9 -9
View File
@@ -5,13 +5,13 @@ import ExtentInteraction from '../../../../src/ol/interaction/Extent.js';
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
describe('ol.interaction.Extent', function() {
var map, interaction;
let map, interaction;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function() {
var target = createMapDiv(width, height);
const target = createMapDiv(width, height);
map = new Map({
target: target,
@@ -46,18 +46,18 @@ describe('ol.interaction.Extent', function() {
* @param {number} button The mouse button.
*/
function simulateEvent(type, x, y, opt_shiftKey, button) {
var viewport = map.getViewport();
const viewport = map.getViewport();
// calculated in case body has top < 0 (test runner with small window)
var position = viewport.getBoundingClientRect();
var shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
var pointerEvent = new PointerEvent(type, {
const position = viewport.getBoundingClientRect();
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
const pointerEvent = new PointerEvent(type, {
type: type,
button: button,
clientX: position.left + x + width / 2,
clientY: position.top - y + height / 2,
shiftKey: shiftKey
});
var event = new MapBrowserPointerEvent(type, map, pointerEvent);
const event = new MapBrowserPointerEvent(type, map, pointerEvent);
event.pointerEvent.pointerId = 1;
map.handleMapBrowserEvent(event);
}
+10 -10
View File
@@ -6,7 +6,7 @@ import Interaction from '../../../../src/ol/interaction/Interaction.js';
describe('ol.interaction.Interaction', function() {
describe('constructor', function() {
var interaction;
let interaction;
beforeEach(function() {
interaction = new Interaction({});
@@ -26,14 +26,14 @@ describe('ol.interaction.Interaction', function() {
describe('#getMap()', function() {
it('retrieves the associated map', function() {
var map = new Map({});
var interaction = new Interaction({});
const map = new Map({});
const interaction = new Interaction({});
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('returns null if no map', function() {
var interaction = new Interaction({});
const interaction = new Interaction({});
expect(interaction.getMap()).to.be(null);
});
@@ -42,14 +42,14 @@ describe('ol.interaction.Interaction', function() {
describe('#setMap()', function() {
it('allows a map to be set', function() {
var map = new Map({});
var interaction = new Interaction({});
const map = new Map({});
const interaction = new Interaction({});
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('accepts null', function() {
var interaction = new Interaction({});
const interaction = new Interaction({});
interaction.setMap(null);
expect(interaction.getMap()).to.be(null);
});
@@ -59,7 +59,7 @@ describe('ol.interaction.Interaction', function() {
describe('zoomByDelta()', function() {
it('changes view resolution', function() {
var view = new View({
const view = new View({
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
});
@@ -78,7 +78,7 @@ describe('ol.interaction.Interaction', function() {
});
it('changes view resolution and center relative to the anchor', function() {
var view = new View({
const view = new View({
center: [0, 0],
resolution: 1,
resolutions: [4, 2, 1, 0.5, 0.25]
@@ -98,7 +98,7 @@ describe('ol.interaction.Interaction', function() {
});
it('changes view resolution and center relative to the anchor, while respecting the extent', function() {
var view = new View({
const view = new View({
center: [0, 0],
extent: [-2.5, -2.5, 2.5, 2.5],
resolution: 1,
+3 -3
View File
@@ -5,7 +5,7 @@ import Event from '../../../../src/ol/events/Event.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
describe('ol.interaction.KeyboardPan', function() {
var map;
let map;
beforeEach(function() {
map = new Map({
@@ -24,8 +24,8 @@ describe('ol.interaction.KeyboardPan', function() {
describe('handleEvent()', function() {
it('pans on arrow keys', function() {
var spy = sinon.spy(Interaction, 'pan');
var event = new MapBrowserEvent('keydown', map, {
const spy = sinon.spy(Interaction, 'pan');
const event = new MapBrowserEvent('keydown', map, {
type: 'keydown',
target: map.getTargetElement(),
preventDefault: Event.prototype.preventDefault
@@ -5,7 +5,7 @@ import Event from '../../../../src/ol/events/Event.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js';
describe('ol.interaction.KeyboardZoom', function() {
var map;
let map;
beforeEach(function() {
map = new Map({
@@ -24,8 +24,8 @@ describe('ol.interaction.KeyboardZoom', function() {
describe('handleEvent()', function() {
it('zooms on + and - keys', function() {
var spy = sinon.spy(Interaction, 'zoomByDelta');
var event = new MapBrowserEvent('keydown', map, {
const spy = sinon.spy(Interaction, 'zoomByDelta');
const event = new MapBrowserEvent('keydown', map, {
type: 'keydown',
target: map.getTargetElement(),
preventDefault: Event.prototype.preventDefault
+89 -89
View File
@@ -17,15 +17,15 @@ import VectorSource from '../../../../src/ol/source/Vector.js';
describe('ol.interaction.Modify', function() {
var target, map, source, features;
let target, map, source, features;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function(done) {
target = document.createElement('div');
var style = target.style;
const style = target.style;
style.position = 'absolute';
style.left = '-1000px';
style.top = '-1000px';
@@ -45,7 +45,7 @@ describe('ol.interaction.Modify', function() {
features: features
});
var layer = new VectorLayer({source: source});
const layer = new VectorLayer({source: source});
map = new Map({
target: target,
@@ -78,10 +78,10 @@ describe('ol.interaction.Modify', function() {
*/
function simulateEvent(type, x, y, modifiers, button) {
modifiers = modifiers || {};
var viewport = map.getViewport();
const viewport = map.getViewport();
// calculated in case body has top < 0 (test runner with small window)
var position = viewport.getBoundingClientRect();
var pointerEvent = new PointerEvent(type, {
const position = viewport.getBoundingClientRect();
const pointerEvent = new PointerEvent(type, {
type: type,
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
@@ -91,7 +91,7 @@ describe('ol.interaction.Modify', function() {
button: button,
isPrimary: true
});
var event = new MapBrowserPointerEvent(type, map, pointerEvent);
const event = new MapBrowserPointerEvent(type, map, pointerEvent);
event.pointerEvent.pointerId = 1;
map.handleMapBrowserEvent(event);
}
@@ -104,7 +104,7 @@ describe('ol.interaction.Modify', function() {
* @return {Array<ol.interaction.Modify.Event|string>} events
*/
function trackEvents(feature, interaction) {
var events = [];
const events = [];
feature.on('change', function(event) {
events.push('change');
});
@@ -126,8 +126,8 @@ describe('ol.interaction.Modify', function() {
*/
function validateEvents(events, features) {
var startevent = events[0];
var endevent = events[events.length - 1];
const startevent = events[0];
const endevent = events[events.length - 1];
// first event should be modifystary
expect(startevent).to.be.an(Modify.Event);
@@ -140,7 +140,7 @@ describe('ol.interaction.Modify', function() {
// make sure we get change events to events array
expect(events.length > 2).to.be(true);
// middle events should be feature modification events
for (var i = 1; i < events.length - 1; i++) {
for (let i = 1; i < events.length - 1; i++) {
expect(events[i]).to.equal('change');
}
@@ -151,24 +151,24 @@ describe('ol.interaction.Modify', function() {
describe('constructor', function() {
it('adds features to the RTree', function() {
var feature = new Feature(
new Point([0, 0]));
var features = new Collection([feature]);
var modify = new Modify({
const feature = new Feature(
new Point([0, 0]));
const features = new Collection([feature]);
const modify = new Modify({
features: features
});
var rbushEntries = modify.rBush_.getAll();
const rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(1);
expect(rbushEntries[0].feature).to.be(feature);
});
it('accepts feature without geometry', function() {
var feature = new Feature();
var features = new Collection([feature]);
var modify = new Modify({
const feature = new Feature();
const features = new Collection([feature]);
const modify = new Modify({
features: features
});
var rbushEntries = modify.rBush_.getAll();
let rbushEntries = modify.rBush_.getAll();
expect(rbushEntries.length).to.be(0);
feature.setGeometry(new Point([0, 10]));
@@ -178,11 +178,11 @@ describe('ol.interaction.Modify', function() {
});
it('accepts a source', function() {
var feature = new Feature(
new Point([0, 0]));
var source = new VectorSource({features: [feature]});
var modify = new Modify({source: source});
var rbushEntries = modify.rBush_.getAll();
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);
});
@@ -194,17 +194,17 @@ describe('ol.interaction.Modify', function() {
it('works when clicking on a shared vertex', function() {
features.push(features[0].clone());
var first = features[0];
var firstRevision = first.getGeometry().getRevision();
var second = features[1];
var secondRevision = second.getGeometry().getRevision();
const first = features[0];
const firstRevision = first.getGeometry().getRevision();
const second = features[1];
const secondRevision = second.getGeometry().getRevision();
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
var events = trackEvents(first, modify);
const events = trackEvents(first, modify);
expect(first.getGeometry().getRevision()).to.equal(firstRevision);
expect(first.getGeometry().getCoordinates()[0]).to.have.length(5);
@@ -225,24 +225,24 @@ describe('ol.interaction.Modify', function() {
});
it('deletes first vertex of a LineString', function() {
var lineFeature = new Feature({
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
});
features.length = 0;
features.push(lineFeature);
features.push(lineFeature.clone());
var first = features[0];
var firstRevision = first.getGeometry().getRevision();
const first = features[0];
const firstRevision = first.getGeometry().getRevision();
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
var events = trackEvents(first, modify);
const events = trackEvents(first, modify);
expect(first.getGeometry().getRevision()).to.equal(firstRevision);
expect(first.getGeometry().getCoordinates()).to.have.length(5);
@@ -261,24 +261,24 @@ describe('ol.interaction.Modify', function() {
});
it('deletes last vertex of a LineString', function() {
var lineFeature = new Feature({
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
});
features.length = 0;
features.push(lineFeature);
features.push(lineFeature.clone());
var first = features[0];
var firstRevision = first.getGeometry().getRevision();
const first = features[0];
const firstRevision = first.getGeometry().getRevision();
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
var events = trackEvents(first, modify);
const events = trackEvents(first, modify);
expect(first.getGeometry().getRevision()).to.equal(firstRevision);
expect(first.getGeometry().getCoordinates()).to.have.length(5);
@@ -297,24 +297,24 @@ describe('ol.interaction.Modify', function() {
});
it('deletes vertex of a LineString programmatically', function() {
var lineFeature = new Feature({
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
)
});
features.length = 0;
features.push(lineFeature);
features.push(lineFeature.clone());
var first = features[0];
var firstRevision = first.getGeometry().getRevision();
const first = features[0];
const firstRevision = first.getGeometry().getRevision();
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
var events = trackEvents(first, modify);
const events = trackEvents(first, modify);
expect(first.getGeometry().getRevision()).to.equal(firstRevision);
expect(first.getGeometry().getCoordinates()).to.have.length(5);
@@ -322,7 +322,7 @@ describe('ol.interaction.Modify', function() {
simulateEvent('pointerdown', 40, 0, null, 0);
simulateEvent('pointerup', 40, 0, null, 0);
var removed = modify.removePoint();
const removed = modify.removePoint();
expect(removed).to.be(true);
expect(first.getGeometry().getRevision()).to.equal(firstRevision + 1);
@@ -339,15 +339,15 @@ describe('ol.interaction.Modify', function() {
describe('vertex modification', function() {
it('keeps the third dimension', function() {
var lineFeature = new Feature({
const lineFeature = new Feature({
geometry: new LineString(
[[0, 0, 10], [10, 20, 20], [0, 40, 30], [40, 40, 40], [40, 0, 50]]
[[0, 0, 10], [10, 20, 20], [0, 40, 30], [40, 40, 40], [40, 0, 50]]
)
});
features.length = 0;
features.push(lineFeature);
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
@@ -382,11 +382,11 @@ describe('ol.interaction.Modify', function() {
describe('circle modification', function() {
it('changes the circle radius and center', function() {
var circleFeature = new Feature(new Circle([10, 10], 20));
const circleFeature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(circleFeature);
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
@@ -414,7 +414,7 @@ describe('ol.interaction.Modify', function() {
});
describe('boundary modification', function() {
var modify, feature, events;
let modify, feature, events;
beforeEach(function() {
modify = new Modify({
@@ -519,7 +519,7 @@ describe('ol.interaction.Modify', function() {
describe('double click deleteCondition', function() {
var modify, feature, events;
let modify, feature, events;
beforeEach(function() {
modify = new Modify({
@@ -571,16 +571,16 @@ describe('ol.interaction.Modify', function() {
describe('insertVertexCondition', function() {
it('calls the callback function', function() {
var listenerSpy = sinon.spy(function(event) {
const listenerSpy = sinon.spy(function(event) {
return false;
});
var modify = new Modify({
const modify = new Modify({
features: new Collection(features),
insertVertexCondition: listenerSpy
});
map.addInteraction(modify);
var feature = features[0];
const feature = features[0];
// move first vertex
simulateEvent('pointermove', 0, 0, null, 0);
@@ -604,12 +604,12 @@ describe('ol.interaction.Modify', function() {
});
describe('handle feature change', function() {
var getListeners;
let getListeners;
beforeEach(function() {
getListeners = function(feature, modify) {
var listeners = _ol_events_.getListeners(
feature, 'change');
const listeners = _ol_events_.getListeners(
feature, 'change');
return listeners.filter(function(listener) {
return listener.bindTo === modify;
});
@@ -617,38 +617,38 @@ describe('ol.interaction.Modify', function() {
});
it('updates circle segment data', function() {
var feature = new Feature(new Circle([10, 10], 20));
const feature = new Feature(new Circle([10, 10], 20));
features.length = 0;
features.push(feature);
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
var listeners;
let listeners;
listeners = getListeners(feature, modify);
expect(listeners).to.have.length(1);
var firstSegmentData;
let firstSegmentData;
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
function(node) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([10, 10]);
expect(firstSegmentData.segment[1]).to.eql([10, 10]);
var center = feature.getGeometry().getCenter();
const center = feature.getGeometry().getCenter();
center[0] = 1;
center[1] = 1;
feature.getGeometry().setCenter(center);
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
function(node) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([1, 1]);
expect(firstSegmentData.segment[1]).to.eql([1, 1]);
@@ -657,36 +657,36 @@ describe('ol.interaction.Modify', function() {
});
it('updates polygon segment data', function() {
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
var feature = features[0];
var listeners;
const feature = features[0];
let listeners;
listeners = getListeners(feature, modify);
expect(listeners).to.have.length(1);
var firstSegmentData;
let firstSegmentData;
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
function(node) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([0, 0]);
expect(firstSegmentData.segment[1]).to.eql([10, 20]);
var coordinates = feature.getGeometry().getCoordinates();
var firstVertex = coordinates[0][0];
const coordinates = feature.getGeometry().getCoordinates();
const firstVertex = coordinates[0][0];
firstVertex[0] = 1;
firstVertex[1] = 1;
feature.getGeometry().setCoordinates(coordinates);
firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5],
function(node) {
return node;
});
function(node) {
return node;
});
expect(firstSegmentData.segment[0]).to.eql([1, 1]);
expect(firstSegmentData.segment[1]).to.eql([10, 20]);
@@ -697,7 +697,7 @@ describe('ol.interaction.Modify', function() {
describe('#setActive', function() {
it('removes the vertexFeature of deactivation', function() {
var modify = new Modify({
const modify = new Modify({
features: new Collection(features)
});
map.addInteraction(modify);
+15 -15
View File
@@ -8,7 +8,7 @@ import MouseWheelZoom from '../../../../src/ol/interaction/MouseWheelZoom.js';
describe('ol.interaction.MouseWheelZoom', function() {
var map, interaction;
let map, interaction;
beforeEach(function() {
interaction = new MouseWheelZoom();
@@ -31,7 +31,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
});
describe('timeout duration', function() {
var clock;
let clock;
beforeEach(function() {
sinon.spy(Interaction, 'zoomByDelta');
clock = sinon.useFakeTimers();
@@ -43,7 +43,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
});
it('works with the defaut value', function(done) {
var event = new MapBrowserEvent('mousewheel', map, {
const event = new MapBrowserEvent('mousewheel', map, {
type: 'mousewheel',
target: map.getViewport(),
preventDefault: Event.prototype.preventDefault
@@ -63,14 +63,14 @@ describe('ol.interaction.MouseWheelZoom', function() {
describe('handleEvent()', function() {
it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function(done) {
var origHasFirefox = _ol_has_.FIREFOX;
const origHasFirefox = _ol_has_.FIREFOX;
_ol_has_.FIREFOX = true;
map.once('postrender', function() {
expect(interaction.mode_).to.be(MouseWheelZoom.Mode_.TRACKPAD);
_ol_has_.FIREFOX = origHasFirefox;
done();
});
var event = new MapBrowserEvent('wheel', map, {
const event = new MapBrowserEvent('wheel', map, {
type: 'wheel',
deltaMode: WheelEvent.DOM_DELTA_PIXEL,
deltaY: _ol_has_.DEVICE_PIXEL_RATIO,
@@ -82,14 +82,14 @@ describe('ol.interaction.MouseWheelZoom', function() {
});
it('works in DOM_DELTA_PIXEL mode (trackpad)', function(done) {
var origHasFirefox = _ol_has_.FIREFOX;
const origHasFirefox = _ol_has_.FIREFOX;
_ol_has_.FIREFOX = false;
map.once('postrender', function() {
expect(interaction.mode_).to.be(MouseWheelZoom.Mode_.TRACKPAD);
_ol_has_.FIREFOX = origHasFirefox;
done();
});
var event = new MapBrowserEvent('wheel', map, {
const event = new MapBrowserEvent('wheel', map, {
type: 'wheel',
deltaMode: WheelEvent.DOM_DELTA_PIXEL,
deltaY: 1,
@@ -110,12 +110,12 @@ describe('ol.interaction.MouseWheelZoom', function() {
it('works in DOM_DELTA_LINE mode (wheel)', function(done) {
map.once('postrender', function() {
var call = Interaction.zoomByDelta.getCall(0);
const call = Interaction.zoomByDelta.getCall(0);
expect(call.args[1]).to.be(-1);
expect(call.args[2]).to.eql([0, 0]);
done();
});
var event = new MapBrowserEvent('wheel', map, {
const event = new MapBrowserEvent('wheel', map, {
type: 'wheel',
deltaMode: WheelEvent.DOM_DELTA_LINE,
deltaY: 3.714599609375,
@@ -127,16 +127,16 @@ describe('ol.interaction.MouseWheelZoom', function() {
});
it('works on Safari (wheel)', function(done) {
var origHasSafari = _ol_has_.SAFARI;
const origHasSafari = _ol_has_.SAFARI;
_ol_has_.SAFARI = true;
map.once('postrender', function() {
var call = Interaction.zoomByDelta.getCall(0);
const call = Interaction.zoomByDelta.getCall(0);
expect(call.args[1]).to.be(-1);
expect(call.args[2]).to.eql([0, 0]);
_ol_has_.SAFARI = origHasSafari;
done();
});
var event = new MapBrowserEvent('mousewheel', map, {
const event = new MapBrowserEvent('mousewheel', map, {
type: 'mousewheel',
wheelDeltaY: -50,
target: map.getViewport(),
@@ -147,16 +147,16 @@ describe('ol.interaction.MouseWheelZoom', function() {
});
it('works on other browsers (wheel)', function(done) {
var origHasSafari = _ol_has_.SAFARI;
const origHasSafari = _ol_has_.SAFARI;
_ol_has_.SAFARI = false;
map.once('postrender', function() {
var call = Interaction.zoomByDelta.getCall(0);
const call = Interaction.zoomByDelta.getCall(0);
expect(call.args[1]).to.be(-1);
expect(call.args[2]).to.eql([0, 0]);
_ol_has_.SAFARI = origHasSafari;
done();
});
var event = new MapBrowserEvent('mousewheel', map, {
const event = new MapBrowserEvent('mousewheel', map, {
type: 'mousewheel',
wheelDeltaY: -120,
target: map.getViewport(),
+65 -65
View File
@@ -13,15 +13,15 @@ import VectorSource from '../../../../src/ol/source/Vector.js';
describe('ol.interaction.Select', function() {
var target, map, layer, source;
let target, map, layer, source;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function(done) {
target = document.createElement('div');
var style = target.style;
const style = target.style;
style.position = 'absolute';
style.left = '-1000px';
style.top = '-1000px';
@@ -29,29 +29,29 @@ describe('ol.interaction.Select', function() {
style.height = height + 'px';
document.body.appendChild(target);
var 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
// -> foo -> bar.
var features = [];
const features = [];
features.push(
new Feature({
geometry: geometry,
type: 'bar'
}),
new Feature({
geometry: geometry,
type: 'foo'
}),
new Feature({
geometry: geometry,
type: 'bar'
}),
new Feature({
geometry: geometry,
type: 'foo'
}));
new Feature({
geometry: geometry,
type: 'bar'
}),
new Feature({
geometry: geometry,
type: 'foo'
}),
new Feature({
geometry: geometry,
type: 'bar'
}),
new Feature({
geometry: geometry,
type: 'foo'
}));
source = new VectorSource({
features: features
@@ -88,11 +88,11 @@ describe('ol.interaction.Select', function() {
* @param {boolean=} opt_shiftKey Shift key is pressed.
*/
function simulateEvent(type, x, y, opt_shiftKey) {
var viewport = map.getViewport();
const viewport = map.getViewport();
// calculated in case body has top < 0 (test runner with small window)
var position = viewport.getBoundingClientRect();
var shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
var event = new PointerEvent(type, {
const position = viewport.getBoundingClientRect();
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
const event = new PointerEvent(type, {
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
shiftKey: shiftKey
@@ -103,7 +103,7 @@ describe('ol.interaction.Select', function() {
describe('constructor', function() {
it('creates a new interaction', function() {
var select = new Select();
const select = new Select();
expect(select).to.be.a(Select);
expect(select).to.be.a(Interaction);
});
@@ -111,8 +111,8 @@ describe('ol.interaction.Select', function() {
describe('user-provided collection', function() {
it('uses the user-provided collection', function() {
var features = new Collection();
var select = new Select({features: features});
const features = new Collection();
const select = new Select({features: features});
expect(select.getFeatures()).to.be(features);
});
@@ -121,7 +121,7 @@ describe('ol.interaction.Select', function() {
});
describe('selecting a polygon', function() {
var select;
let select;
beforeEach(function() {
select = new Select();
@@ -129,7 +129,7 @@ describe('ol.interaction.Select', function() {
});
it('select with single-click', function() {
var listenerSpy = sinon.spy(function(e) {
const listenerSpy = sinon.spy(function(e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -138,12 +138,12 @@ describe('ol.interaction.Select', function() {
expect(listenerSpy.callCount).to.be(1);
var features = select.getFeatures();
const features = select.getFeatures();
expect(features.getLength()).to.equal(1);
});
it('single-click outside the geometry', function() {
var listenerSpy = sinon.spy(function(e) {
const listenerSpy = sinon.spy(function(e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -152,12 +152,12 @@ describe('ol.interaction.Select', function() {
expect(listenerSpy.callCount).to.be(0);
var features = select.getFeatures();
const features = select.getFeatures();
expect(features.getLength()).to.equal(0);
});
it('select twice with single-click', function() {
var listenerSpy = sinon.spy(function(e) {
const listenerSpy = sinon.spy(function(e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -167,12 +167,12 @@ describe('ol.interaction.Select', function() {
expect(listenerSpy.callCount).to.be(1);
var features = select.getFeatures();
const features = select.getFeatures();
expect(features.getLength()).to.equal(1);
});
it('select with shift single-click', function() {
var listenerSpy = sinon.spy(function(e) {
const listenerSpy = sinon.spy(function(e) {
expect(e.selected).to.have.length(1);
});
select.on('select', listenerSpy);
@@ -181,13 +181,13 @@ describe('ol.interaction.Select', function() {
expect(listenerSpy.callCount).to.be(1);
var features = select.getFeatures();
const features = select.getFeatures();
expect(features.getLength()).to.equal(1);
});
});
describe('multiselecting polygons', function() {
var select;
let select;
beforeEach(function() {
select = new Select({
@@ -197,7 +197,7 @@ describe('ol.interaction.Select', function() {
});
it('select with single-click', function() {
var listenerSpy = sinon.spy(function(e) {
const listenerSpy = sinon.spy(function(e) {
expect(e.selected).to.have.length(4);
});
select.on('select', listenerSpy);
@@ -206,12 +206,12 @@ describe('ol.interaction.Select', function() {
expect(listenerSpy.callCount).to.be(1);
var features = select.getFeatures();
const features = select.getFeatures();
expect(features.getLength()).to.equal(4);
});
it('select with shift single-click', function() {
var listenerSpy = sinon.spy(function(e) {
const listenerSpy = sinon.spy(function(e) {
expect(e.selected).to.have.length(4);
});
select.on('select', listenerSpy);
@@ -220,7 +220,7 @@ describe('ol.interaction.Select', function() {
expect(listenerSpy.callCount).to.be(1);
var features = select.getFeatures();
let features = select.getFeatures();
expect(features.getLength()).to.equal(4);
expect(select.getLayer(features.item(0))).to.equal(layer);
@@ -236,7 +236,7 @@ describe('ol.interaction.Select', function() {
});
describe('toggle selecting polygons', function() {
var select;
let select;
beforeEach(function() {
select = new Select({
@@ -246,14 +246,14 @@ describe('ol.interaction.Select', function() {
});
it('with SHIFT + single-click', function() {
var listenerSpy = sinon.spy();
const listenerSpy = sinon.spy();
select.on('select', listenerSpy);
simulateEvent('singleclick', 10, -20, true);
expect(listenerSpy.callCount).to.be(1);
var features = select.getFeatures();
let features = select.getFeatures();
expect(features.getLength()).to.equal(4);
map.renderSync();
@@ -272,7 +272,7 @@ describe('ol.interaction.Select', function() {
describe('with multi set to true', function() {
it('only selects features that pass the filter', function() {
var select = new Select({
const select = new Select({
multi: true,
filter: function(feature, layer) {
return feature.get('type') === 'bar';
@@ -281,7 +281,7 @@ describe('ol.interaction.Select', function() {
map.addInteraction(select);
simulateEvent('singleclick', 10, -20);
var features = select.getFeatures();
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');
@@ -289,7 +289,7 @@ describe('ol.interaction.Select', function() {
it('only selects features that pass the filter ' +
'using shift single-click', function() {
var select = new Select({
const select = new Select({
multi: true,
filter: function(feature, layer) {
return feature.get('type') === 'bar';
@@ -298,8 +298,8 @@ describe('ol.interaction.Select', function() {
map.addInteraction(select);
simulateEvent('singleclick', 10, -20,
true);
var features = select.getFeatures();
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');
@@ -309,7 +309,7 @@ describe('ol.interaction.Select', function() {
describe('with multi set to false', function() {
it('only selects the first feature that passes the filter', function() {
var select = new Select({
const select = new Select({
multi: false,
filter: function(feature, layer) {
return feature.get('type') === 'bar';
@@ -317,14 +317,14 @@ describe('ol.interaction.Select', function() {
});
map.addInteraction(select);
simulateEvent('singleclick', 10, -20);
var features = select.getFeatures();
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() {
var select = new Select({
const select = new Select({
multi: false,
filter: function(feature, layer) {
return feature.get('type') === 'bar';
@@ -332,8 +332,8 @@ describe('ol.interaction.Select', function() {
});
map.addInteraction(select);
simulateEvent('singleclick', 10, -20,
true);
var features = select.getFeatures();
true);
const features = select.getFeatures();
expect(features.getLength()).to.equal(1);
expect(features.item(0).get('type')).to.be('bar');
});
@@ -341,7 +341,7 @@ describe('ol.interaction.Select', function() {
});
describe('#getLayer(feature)', function() {
var interaction;
let interaction;
beforeEach(function() {
interaction = new Select();
@@ -352,9 +352,9 @@ describe('ol.interaction.Select', function() {
});
it('returns a layer from a selected feature', function() {
var listenerSpy = sinon.spy(function(e) {
var feature = e.selected[0];
var layer_ = interaction.getLayer(feature);
const listenerSpy = sinon.spy(function(e) {
const feature = e.selected[0];
const layer_ = interaction.getLayer(feature);
expect(e.selected).to.have.length(1);
expect(feature).to.be.a(Feature);
expect(layer_).to.be.a(VectorLayer);
@@ -369,7 +369,7 @@ describe('ol.interaction.Select', function() {
});
describe('#setActive()', function() {
var interaction;
let interaction;
beforeEach(function() {
interaction = new Select();
@@ -399,7 +399,7 @@ describe('ol.interaction.Select', function() {
interaction.setActive(false);
});
it('fires change:active', function() {
var listenerSpy = sinon.spy();
const listenerSpy = sinon.spy();
interaction.on('change:active', listenerSpy);
interaction.setActive(true);
expect(listenerSpy.callCount).to.be(1);
@@ -409,7 +409,7 @@ describe('ol.interaction.Select', function() {
});
describe('#setMap()', function() {
var interaction;
let interaction;
beforeEach(function() {
interaction = new Select();
@@ -425,7 +425,7 @@ describe('ol.interaction.Select', function() {
});
describe('#setMap(null) when interaction is active', function() {
it('unsets the map from the feature overlay', function() {
var spy = sinon.spy(interaction.featureOverlay_, 'setMap');
const spy = sinon.spy(interaction.featureOverlay_, 'setMap');
interaction.setMap(null);
expect(spy.getCall(0).args[0]).to.be(null);
});
@@ -435,7 +435,7 @@ describe('ol.interaction.Select', function() {
describe('#setMap(map)', function() {
describe('#setMap(map) when interaction is active', function() {
it('sets the map into the feature overlay', function() {
var spy = sinon.spy(interaction.featureOverlay_, 'setMap');
const spy = sinon.spy(interaction.featureOverlay_, 'setMap');
interaction.setMap(map);
expect(spy.getCall(0).args[0]).to.be(map);
});
+26 -26
View File
@@ -13,22 +13,22 @@ describe('ol.interaction.Snap', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new Snap();
const instance = new Snap();
expect(instance).to.be.an(Snap);
});
});
describe('handleEvent_', function() {
var target, map;
let target, map;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function(done) {
target = document.createElement('div');
var style = target.style;
const style = target.style;
style.position = 'absolute';
style.left = '-1000px';
style.top = '-1000px';
@@ -56,13 +56,13 @@ describe('ol.interaction.Snap', function() {
});
it('can handle XYZ coordinates', function() {
var point = new Feature(new Point([0, 0, 123]));
var snapInteraction = new Snap({
const point = new Feature(new Point([0, 0, 123]));
const snapInteraction = new Snap({
features: new Collection([point])
});
snapInteraction.setMap(map);
var event = {
const event = {
pixel: [width / 2, height / 2],
coordinate: [0, 0],
map: map
@@ -73,15 +73,15 @@ describe('ol.interaction.Snap', function() {
});
it('snaps to edges only', function() {
var point = new Feature(new LineString([[-10, 0], [10, 0]]));
var snapInteraction = new Snap({
const point = new Feature(new LineString([[-10, 0], [10, 0]]));
const snapInteraction = new Snap({
features: new Collection([point]),
pixelTolerance: 5,
vertex: false
});
snapInteraction.setMap(map);
var event = {
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
@@ -91,15 +91,15 @@ describe('ol.interaction.Snap', function() {
});
it('snaps to vertices only', function() {
var point = new Feature(new LineString([[-10, 0], [10, 0]]));
var snapInteraction = new Snap({
const point = new Feature(new LineString([[-10, 0], [10, 0]]));
const snapInteraction = new Snap({
features: new Collection([point]),
pixelTolerance: 5,
edge: false
});
snapInteraction.setMap(map);
var event = {
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
@@ -109,14 +109,14 @@ describe('ol.interaction.Snap', function() {
});
it('snaps to circle', function() {
var circle = new Feature(new Circle([0, 0], 10));
var snapInteraction = new Snap({
const circle = new Feature(new Circle([0, 0], 10));
const snapInteraction = new Snap({
features: new Collection([circle]),
pixelTolerance: 5
});
snapInteraction.setMap(map);
var event = {
const event = {
pixel: [5 + width / 2, height / 2 - 5],
coordinate: [5, 5],
map: map
@@ -128,8 +128,8 @@ describe('ol.interaction.Snap', function() {
});
it('handle feature without geometry', function() {
var feature = new Feature();
var snapInteraction = new Snap({
const feature = new Feature();
const snapInteraction = new Snap({
features: new Collection([feature]),
pixelTolerance: 5,
edge: false
@@ -138,7 +138,7 @@ describe('ol.interaction.Snap', function() {
feature.setGeometry(new LineString([[-10, 0], [10, 0]]));
var event = {
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
@@ -148,8 +148,8 @@ describe('ol.interaction.Snap', function() {
});
it('handle geometry changes', function() {
var line = new Feature(new LineString([[-10, 0], [0, 0]]));
var snapInteraction = new Snap({
const line = new Feature(new LineString([[-10, 0], [0, 0]]));
const snapInteraction = new Snap({
features: new Collection([line]),
pixelTolerance: 5,
edge: false
@@ -158,7 +158,7 @@ describe('ol.interaction.Snap', function() {
line.getGeometry().setCoordinates([[-10, 0], [10, 0]]);
var event = {
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
@@ -168,11 +168,11 @@ describe('ol.interaction.Snap', function() {
});
it('handle geometry name changes', function() {
var line = new Feature({
const line = new Feature({
geometry: new LineString([[-10, 0], [0, 0]]),
alt_geometry: new LineString([[-10, 0], [10, 0]])
});
var snapInteraction = new Snap({
const snapInteraction = new Snap({
features: new Collection([line]),
pixelTolerance: 5,
edge: false
@@ -181,7 +181,7 @@ describe('ol.interaction.Snap', function() {
line.setGeometryName('alt_geometry');
var event = {
const event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
+28 -28
View File
@@ -12,14 +12,14 @@ import VectorSource from '../../../../src/ol/source/Vector.js';
describe('ol.interaction.Translate', function() {
var target, map, source, features;
let target, map, source, features;
var width = 360;
var height = 180;
const width = 360;
const height = 180;
beforeEach(function(done) {
target = document.createElement('div');
var style = target.style;
const style = target.style;
style.position = 'absolute';
style.left = '-1000px';
style.top = '-1000px';
@@ -33,7 +33,7 @@ describe('ol.interaction.Translate', function() {
geometry: new Point([20, -30])
})];
source.addFeatures(features);
var layer = new VectorLayer({source: source});
const layer = new VectorLayer({source: source});
map = new Map({
target: target,
layers: [layer],
@@ -62,16 +62,16 @@ describe('ol.interaction.Translate', function() {
* @param {boolean=} opt_shiftKey Shift key is pressed.
*/
function simulateEvent(type, x, y, opt_shiftKey) {
var viewport = map.getViewport();
const viewport = map.getViewport();
// calculated in case body has top < 0 (test runner with small window)
var position = viewport.getBoundingClientRect();
var shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
var event = new MapBrowserPointerEvent(type, map,
new PointerEvent(type, {
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
shiftKey: shiftKey
}));
const position = viewport.getBoundingClientRect();
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
const event = new MapBrowserPointerEvent(type, map,
new PointerEvent(type, {
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
shiftKey: shiftKey
}));
map.handleMapBrowserEvent(event);
}
@@ -83,7 +83,7 @@ describe('ol.interaction.Translate', function() {
* @return {Array<ol.interaction.Translate.Event|string>} events
*/
function trackEvents(feature, interaction) {
var events = [];
const events = [];
feature.on('change', function(event) {
events.push('change');
});
@@ -105,8 +105,8 @@ describe('ol.interaction.Translate', function() {
*/
function validateEvents(events, features) {
var startevent = events[0];
var endevent = events[events.length - 1];
const startevent = events[0];
const endevent = events[events.length - 1];
// first event should be translatestart
expect(startevent).to.be.an(_ol_interaction_Translate_.Event);
@@ -119,7 +119,7 @@ describe('ol.interaction.Translate', function() {
// make sure we get change events to events array
expect(events.length > 2).to.be(true);
// middle events should be feature modification events
for (var i = 1; i < events.length - 1; i++) {
for (let i = 1; i < events.length - 1; i++) {
expect(events[i]).to.equal('change');
}
@@ -132,7 +132,7 @@ describe('ol.interaction.Translate', function() {
describe('constructor', function() {
it('creates a new interaction', function() {
var translate = new _ol_interaction_Translate_({
const translate = new _ol_interaction_Translate_({
features: features
});
expect(translate).to.be.a(_ol_interaction_Translate_);
@@ -144,7 +144,7 @@ describe('ol.interaction.Translate', function() {
describe('setActive', function() {
it('works when the map is not set', function() {
var translate = new _ol_interaction_Translate_({
const translate = new _ol_interaction_Translate_({
features: features
});
expect(translate.getActive()).to.be(true);
@@ -155,7 +155,7 @@ describe('ol.interaction.Translate', function() {
});
describe('moving features, with features option', function() {
var translate;
let translate;
beforeEach(function() {
translate = new _ol_interaction_Translate_({
@@ -165,13 +165,13 @@ describe('ol.interaction.Translate', function() {
});
it('moves a selected feature', function() {
var events = trackEvents(features[0], translate);
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerdrag', 50, -40);
simulateEvent('pointerup', 50, -40);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Point);
expect(geometry.getCoordinates()).to.eql([50, 40]);
@@ -179,13 +179,13 @@ describe('ol.interaction.Translate', function() {
});
it('does not move an unselected feature', function() {
var events = trackEvents(features[0], translate);
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 20, 30);
simulateEvent('pointerdown', 20, 30);
simulateEvent('pointerdrag', 50, -40);
simulateEvent('pointerup', 50, -40);
var geometry = features[1].getGeometry();
const geometry = features[1].getGeometry();
expect(geometry).to.be.a(Point);
expect(geometry.getCoordinates()).to.eql([20, -30]);
@@ -194,7 +194,7 @@ describe('ol.interaction.Translate', function() {
});
describe('moving features, without features option', function() {
var translate;
let translate;
beforeEach(function() {
translate = new _ol_interaction_Translate_();
@@ -202,7 +202,7 @@ describe('ol.interaction.Translate', function() {
});
it('moves only targeted feature', function() {
var events = trackEvents(features[0], translate);
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
@@ -216,7 +216,7 @@ describe('ol.interaction.Translate', function() {
});
describe('changes css cursor', function() {
var element, translate;
let element, translate;
beforeEach(function() {
translate = new _ol_interaction_Translate_();