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:
@@ -20,34 +20,34 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new map', function() {
|
||||
var map = new Map({});
|
||||
const map = new Map({});
|
||||
expect(map).to.be.a(Map);
|
||||
});
|
||||
|
||||
it('creates a set of default interactions', function() {
|
||||
var map = new Map({});
|
||||
var interactions = map.getInteractions();
|
||||
var length = interactions.getLength();
|
||||
const map = new Map({});
|
||||
const interactions = map.getInteractions();
|
||||
const length = interactions.getLength();
|
||||
expect(length).to.be.greaterThan(0);
|
||||
|
||||
for (var i = 0; i < length; ++i) {
|
||||
for (let i = 0; i < length; ++i) {
|
||||
expect(interactions.item(i).getMap()).to.be(map);
|
||||
}
|
||||
});
|
||||
|
||||
it('creates the viewport', function() {
|
||||
var map = new Map({});
|
||||
var viewport = map.getViewport();
|
||||
var className = 'ol-viewport' + (_ol_has_.TOUCH ? ' ol-touch' : '');
|
||||
const map = new Map({});
|
||||
const viewport = map.getViewport();
|
||||
const className = 'ol-viewport' + (_ol_has_.TOUCH ? ' ol-touch' : '');
|
||||
expect(viewport.className).to.be(className);
|
||||
});
|
||||
|
||||
it('creates the overlay containers', function() {
|
||||
var map = new Map({});
|
||||
var container = map.getOverlayContainer();
|
||||
const map = new Map({});
|
||||
const container = map.getOverlayContainer();
|
||||
expect(container.className).to.be('ol-overlaycontainer');
|
||||
|
||||
var containerStop = map.getOverlayContainerStopEvent();
|
||||
const containerStop = map.getOverlayContainerStopEvent();
|
||||
expect(containerStop.className).to.be('ol-overlaycontainer-stopevent');
|
||||
});
|
||||
|
||||
@@ -55,19 +55,19 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('#addLayer()', function() {
|
||||
it('adds a layer to the map', function() {
|
||||
var map = new Map({});
|
||||
var layer = new TileLayer();
|
||||
const map = new Map({});
|
||||
const layer = new TileLayer();
|
||||
map.addLayer(layer);
|
||||
|
||||
expect(map.getLayers().item(0)).to.be(layer);
|
||||
});
|
||||
|
||||
it('throws if a layer is added twice', function() {
|
||||
var map = new Map({});
|
||||
var layer = new TileLayer();
|
||||
const map = new Map({});
|
||||
const layer = new TileLayer();
|
||||
map.addLayer(layer);
|
||||
|
||||
var call = function() {
|
||||
const call = function() {
|
||||
map.addLayer(layer);
|
||||
};
|
||||
expect(call).to.throwException();
|
||||
@@ -76,12 +76,12 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('#addInteraction()', function() {
|
||||
it('adds an interaction to the map', function() {
|
||||
var map = new Map({});
|
||||
var interaction = new Interaction({});
|
||||
const map = new Map({});
|
||||
const interaction = new Interaction({});
|
||||
|
||||
var before = map.getInteractions().getLength();
|
||||
const before = map.getInteractions().getLength();
|
||||
map.addInteraction(interaction);
|
||||
var after = map.getInteractions().getLength();
|
||||
const after = map.getInteractions().getLength();
|
||||
expect(after).to.be(before + 1);
|
||||
expect(interaction.getMap()).to.be(map);
|
||||
});
|
||||
@@ -89,10 +89,10 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('#removeInteraction()', function() {
|
||||
it('removes an interaction from the map', function() {
|
||||
var map = new Map({});
|
||||
var interaction = new Interaction({});
|
||||
const map = new Map({});
|
||||
const interaction = new Interaction({});
|
||||
|
||||
var before = map.getInteractions().getLength();
|
||||
const before = map.getInteractions().getLength();
|
||||
map.addInteraction(interaction);
|
||||
|
||||
map.removeInteraction(interaction);
|
||||
@@ -104,12 +104,12 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('movestart/moveend event', function() {
|
||||
|
||||
var target, view, map;
|
||||
let target, view, map;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
|
||||
var style = target.style;
|
||||
const style = target.style;
|
||||
style.position = 'absolute';
|
||||
style.left = '-1000px';
|
||||
style.top = '-1000px';
|
||||
@@ -139,10 +139,10 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
it('are fired only once after view changes', function(done) {
|
||||
var center = [10, 20];
|
||||
var zoom = 3;
|
||||
var startCalls = 0;
|
||||
var endCalls = 0;
|
||||
const center = [10, 20];
|
||||
const zoom = 3;
|
||||
let startCalls = 0;
|
||||
let endCalls = 0;
|
||||
map.on('movestart', function() {
|
||||
++startCalls;
|
||||
expect(startCalls).to.be(1);
|
||||
@@ -163,9 +163,9 @@ describe('ol.Map', function() {
|
||||
view.setCenter([0, 0]);
|
||||
view.setResolution(0.703125);
|
||||
map.renderSync();
|
||||
var center = [10, 20];
|
||||
var zoom = 3;
|
||||
var calls = [];
|
||||
const center = [10, 20];
|
||||
const zoom = 3;
|
||||
const calls = [];
|
||||
map.on('movestart', function(e) {
|
||||
calls.push('start');
|
||||
expect(calls).to.eql(['start']);
|
||||
@@ -188,7 +188,7 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('#getFeaturesAtPixel', function() {
|
||||
|
||||
var target, map;
|
||||
let target, map;
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
target.style.width = target.style.height = '100px';
|
||||
@@ -212,36 +212,36 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
it('returns null if no feature was found', function() {
|
||||
var features = map.getFeaturesAtPixel([0, 0]);
|
||||
const features = map.getFeaturesAtPixel([0, 0]);
|
||||
expect(features).to.be(null);
|
||||
});
|
||||
|
||||
it('returns an array of found features', function() {
|
||||
var features = map.getFeaturesAtPixel([50, 50]);
|
||||
const features = map.getFeaturesAtPixel([50, 50]);
|
||||
expect(features).to.be.an(Array);
|
||||
expect(features[0]).to.be.an(Feature);
|
||||
});
|
||||
|
||||
it('returns an array of found features with declutter: true', function() {
|
||||
var layer = map.getLayers().item(0);
|
||||
const layer = map.getLayers().item(0);
|
||||
map.removeLayer(layer);
|
||||
var otherLayer = new VectorLayer({
|
||||
const otherLayer = new VectorLayer({
|
||||
declutter: true,
|
||||
source: layer.getSource()
|
||||
});
|
||||
map.addLayer(otherLayer);
|
||||
map.renderSync();
|
||||
var features = map.getFeaturesAtPixel([50, 50]);
|
||||
const features = map.getFeaturesAtPixel([50, 50]);
|
||||
expect(features).to.be.an(Array);
|
||||
expect(features[0]).to.be.a(Feature);
|
||||
});
|
||||
|
||||
it('respects options', function() {
|
||||
var otherLayer = new VectorLayer({
|
||||
const otherLayer = new VectorLayer({
|
||||
source: new VectorSource
|
||||
});
|
||||
map.addLayer(otherLayer);
|
||||
var features = map.getFeaturesAtPixel([50, 50], {
|
||||
const features = map.getFeaturesAtPixel([50, 50], {
|
||||
layerFilter: function(layer) {
|
||||
return layer == otherLayer;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('#forEachLayerAtPixel()', function() {
|
||||
|
||||
var target, map, original, log;
|
||||
let target, map, original, log;
|
||||
|
||||
beforeEach(function(done) {
|
||||
log = [];
|
||||
@@ -263,7 +263,7 @@ describe('ol.Map', function() {
|
||||
};
|
||||
|
||||
target = document.createElement('div');
|
||||
var style = target.style;
|
||||
const style = target.style;
|
||||
style.position = 'absolute';
|
||||
style.left = '-1000px';
|
||||
style.top = '-1000px';
|
||||
@@ -303,7 +303,7 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
it('calls each layer renderer with the same coordinate', function() {
|
||||
var pixel = [10, 20];
|
||||
const pixel = [10, 20];
|
||||
map.forEachLayerAtPixel(pixel, function() {});
|
||||
expect(log.length).to.equal(3);
|
||||
expect(log[0].length).to.equal(2);
|
||||
@@ -315,11 +315,11 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('#render()', function() {
|
||||
|
||||
var target, map;
|
||||
let target, map;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
var style = target.style;
|
||||
const style = target.style;
|
||||
style.position = 'absolute';
|
||||
style.left = '-1000px';
|
||||
style.top = '-1000px';
|
||||
@@ -342,31 +342,31 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
it('is called when the view.changed() is called', function() {
|
||||
var view = map.getView();
|
||||
const view = map.getView();
|
||||
|
||||
var spy = sinon.spy(map, 'render');
|
||||
const spy = sinon.spy(map, 'render');
|
||||
view.changed();
|
||||
expect(spy.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('is not called on view changes after the view has been removed', function() {
|
||||
var view = map.getView();
|
||||
const view = map.getView();
|
||||
map.setView(null);
|
||||
|
||||
var spy = sinon.spy(map, 'render');
|
||||
const spy = sinon.spy(map, 'render');
|
||||
view.changed();
|
||||
expect(spy.callCount).to.be(0);
|
||||
});
|
||||
|
||||
it('calls renderFrame_ and results in an postrender event', function(done) {
|
||||
|
||||
var spy = sinon.spy(map, 'renderFrame_');
|
||||
const spy = sinon.spy(map, 'renderFrame_');
|
||||
map.render();
|
||||
map.once('postrender', function(event) {
|
||||
expect(event).to.be.a(MapEvent);
|
||||
expect(typeof spy.firstCall.args[0]).to.be('number');
|
||||
spy.restore();
|
||||
var frameState = event.frameState;
|
||||
const frameState = event.frameState;
|
||||
expect(frameState).not.to.be(null);
|
||||
done();
|
||||
});
|
||||
@@ -374,9 +374,9 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
it('uses the same render frame for subsequent calls', function(done) {
|
||||
var id1, id2;
|
||||
map.render();
|
||||
id1 = map.animationDelayKey_;
|
||||
const id1 = map.animationDelayKey_;
|
||||
let id2 = null;
|
||||
map.once('postrender', function() {
|
||||
expect(id2).to.be(id1);
|
||||
done();
|
||||
@@ -386,9 +386,9 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
it('creates a new render frame after renderSync()', function(done) {
|
||||
var id1, id2;
|
||||
let id2 = null;
|
||||
map.render();
|
||||
id1 = map.animationDelayKey_;
|
||||
const id1 = map.animationDelayKey_;
|
||||
map.once('postrender', function() {
|
||||
expect(id2).to.not.be(id1);
|
||||
done();
|
||||
@@ -404,7 +404,7 @@ describe('ol.Map', function() {
|
||||
map.render();
|
||||
map.once('postrender', function(event) {
|
||||
expect(event).to.be.a(MapEvent);
|
||||
var frameState = event.frameState;
|
||||
const frameState = event.frameState;
|
||||
expect(frameState).to.be(null);
|
||||
done();
|
||||
});
|
||||
@@ -418,7 +418,7 @@ describe('ol.Map', function() {
|
||||
map.render();
|
||||
map.once('postrender', function(event) {
|
||||
expect(event).to.be.a(MapEvent);
|
||||
var frameState = event.frameState;
|
||||
const frameState = event.frameState;
|
||||
expect(frameState).to.be(null);
|
||||
done();
|
||||
});
|
||||
@@ -428,7 +428,7 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
describe('dispose', function() {
|
||||
var map;
|
||||
let map;
|
||||
|
||||
beforeEach(function() {
|
||||
map = new Map({
|
||||
@@ -448,7 +448,7 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
describe('#setTarget', function() {
|
||||
var map;
|
||||
let map;
|
||||
|
||||
beforeEach(function() {
|
||||
map = new Map({
|
||||
@@ -476,7 +476,7 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('create interactions', function() {
|
||||
|
||||
var options;
|
||||
let options;
|
||||
|
||||
beforeEach(function() {
|
||||
options = {
|
||||
@@ -494,7 +494,7 @@ describe('ol.Map', function() {
|
||||
describe('create mousewheel interaction', function() {
|
||||
it('creates mousewheel interaction', function() {
|
||||
options.mouseWheelZoom = true;
|
||||
var interactions = defaultInteractions(options);
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.getLength()).to.eql(1);
|
||||
expect(interactions.item(0)).to.be.a(MouseWheelZoom);
|
||||
expect(interactions.item(0).constrainResolution_).to.eql(false);
|
||||
@@ -507,7 +507,7 @@ describe('ol.Map', function() {
|
||||
describe('create pinchZoom interaction', function() {
|
||||
it('creates pinchZoom interaction', function() {
|
||||
options.pinchZoom = true;
|
||||
var interactions = defaultInteractions(options);
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.getLength()).to.eql(1);
|
||||
expect(interactions.item(0)).to.be.a(PinchZoom);
|
||||
expect(interactions.item(0).constrainResolution_).to.eql(false);
|
||||
@@ -519,7 +519,7 @@ describe('ol.Map', function() {
|
||||
options.pinchZoom = true;
|
||||
options.mouseWheelZoom = true;
|
||||
options.constrainResolution = true;
|
||||
var interactions = defaultInteractions(options);
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.getLength()).to.eql(2);
|
||||
expect(interactions.item(0)).to.be.a(PinchZoom);
|
||||
expect(interactions.item(0).constrainResolution_).to.eql(true);
|
||||
@@ -536,7 +536,7 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('default zoomDelta', function() {
|
||||
it('create double click interaction with default delta', function() {
|
||||
var interactions = defaultInteractions(options);
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.getLength()).to.eql(1);
|
||||
expect(interactions.item(0)).to.be.a(DoubleClickZoom);
|
||||
expect(interactions.item(0).delta_).to.eql(1);
|
||||
@@ -546,7 +546,7 @@ describe('ol.Map', function() {
|
||||
describe('set zoomDelta', function() {
|
||||
it('create double click interaction with set delta', function() {
|
||||
options.zoomDelta = 7;
|
||||
var interactions = defaultInteractions(options);
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.getLength()).to.eql(1);
|
||||
expect(interactions.item(0)).to.be.a(DoubleClickZoom);
|
||||
expect(interactions.item(0).delta_).to.eql(7);
|
||||
@@ -556,7 +556,7 @@ describe('ol.Map', function() {
|
||||
|
||||
describe('#getEventPixel', function() {
|
||||
|
||||
var target;
|
||||
let target;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
@@ -574,11 +574,11 @@ describe('ol.Map', function() {
|
||||
|
||||
it('works with touchend events', function() {
|
||||
|
||||
var map = new Map({
|
||||
const map = new Map({
|
||||
target: target
|
||||
});
|
||||
|
||||
var browserEvent = {
|
||||
const browserEvent = {
|
||||
type: 'touchend',
|
||||
target: target,
|
||||
changedTouches: [{
|
||||
@@ -586,7 +586,7 @@ describe('ol.Map', function() {
|
||||
clientY: 200
|
||||
}]
|
||||
};
|
||||
var position = map.getEventPixel(browserEvent);
|
||||
const position = map.getEventPixel(browserEvent);
|
||||
// 80 = clientX - target.style.left
|
||||
expect(position[0]).to.eql(80);
|
||||
// 190 = clientY - target.style.top
|
||||
@@ -595,11 +595,11 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
describe('#getOverlayById()', function() {
|
||||
var target, map, overlay, overlay_target;
|
||||
let target, map, overlay, overlay_target;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
var style = target.style;
|
||||
const style = target.style;
|
||||
style.position = 'absolute';
|
||||
style.left = '-1000px';
|
||||
style.top = '-1000px';
|
||||
|
||||
Reference in New Issue
Block a user