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:
@@ -18,8 +18,8 @@ import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
* @param {Object.<string, ol.TileState>} tileStates Lookup of tile key to
|
||||
* tile state.
|
||||
*/
|
||||
var MockTile = function(tileStates) {
|
||||
var tileGrid = new TileGrid({
|
||||
const MockTile = function(tileStates) {
|
||||
const tileGrid = new TileGrid({
|
||||
resolutions: [360 / 256, 180 / 256, 90 / 256, 45 / 256],
|
||||
origin: [-180, -180],
|
||||
tileSize: 256
|
||||
@@ -30,7 +30,7 @@ var MockTile = function(tileStates) {
|
||||
tileGrid: tileGrid
|
||||
});
|
||||
|
||||
for (var key in tileStates) {
|
||||
for (const key in tileStates) {
|
||||
this.tileCache.set(key, new Tile(key.split('/'), tileStates[key]));
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ inherits(MockTile, TileSource);
|
||||
* @inheritDoc
|
||||
*/
|
||||
MockTile.prototype.getTile = function(z, x, y) {
|
||||
var key = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
const key = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(key)) {
|
||||
return /** @type {!ol.Tile} */ (this.tileCache.get(key));
|
||||
} else {
|
||||
var tile = new Tile(key, 0); // IDLE
|
||||
const tile = new Tile(key, 0); // IDLE
|
||||
this.tileCache.set(key, tile);
|
||||
return tile;
|
||||
}
|
||||
@@ -56,15 +56,15 @@ describe('ol.source.Tile', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('returns a tile source', function() {
|
||||
var source = new TileSource({
|
||||
const source = new TileSource({
|
||||
projection: getProjection('EPSG:4326')
|
||||
});
|
||||
expect(source).to.be.a(Source);
|
||||
expect(source).to.be.a(TileSource);
|
||||
});
|
||||
it('sets a custom cache size', function() {
|
||||
var projection = getProjection('EPSG:4326');
|
||||
var source = new TileSource({
|
||||
const projection = getProjection('EPSG:4326');
|
||||
const source = new TileSource({
|
||||
projection: projection,
|
||||
cacheSize: 42
|
||||
});
|
||||
@@ -74,10 +74,10 @@ describe('ol.source.Tile', function() {
|
||||
|
||||
describe('#setKey()', function() {
|
||||
it('sets the source key', function() {
|
||||
var source = new TileSource({});
|
||||
const source = new TileSource({});
|
||||
expect(source.getKey()).to.equal('');
|
||||
|
||||
var key = 'foo';
|
||||
const key = 'foo';
|
||||
source.setKey(key);
|
||||
expect(source.getKey()).to.equal(key);
|
||||
});
|
||||
@@ -85,9 +85,9 @@ describe('ol.source.Tile', function() {
|
||||
|
||||
describe('#setKey()', function() {
|
||||
it('dispatches a change event', function(done) {
|
||||
var source = new TileSource({});
|
||||
const source = new TileSource({});
|
||||
|
||||
var key = 'foo';
|
||||
const key = 'foo';
|
||||
source.once('change', function() {
|
||||
done();
|
||||
});
|
||||
@@ -95,9 +95,9 @@ describe('ol.source.Tile', function() {
|
||||
});
|
||||
|
||||
it('does not dispatch change if key does not change', function(done) {
|
||||
var source = new TileSource({});
|
||||
const source = new TileSource({});
|
||||
|
||||
var key = 'foo';
|
||||
const key = 'foo';
|
||||
source.once('change', function() {
|
||||
source.once('change', function() {
|
||||
done(new Error('Unexpected change event after source.setKey()'));
|
||||
@@ -115,29 +115,29 @@ describe('ol.source.Tile', function() {
|
||||
|
||||
describe('#forEachLoadedTile()', function() {
|
||||
|
||||
var callback;
|
||||
let callback;
|
||||
beforeEach(function() {
|
||||
callback = sinon.spy();
|
||||
});
|
||||
|
||||
it('does not call the callback if no tiles are loaded', function() {
|
||||
var source = new MockTile({});
|
||||
var grid = source.getTileGrid();
|
||||
var extent = [-180, -180, 180, 180];
|
||||
var zoom = 3;
|
||||
var range = grid.getTileRangeForExtentAndZ(extent, zoom);
|
||||
const source = new MockTile({});
|
||||
const grid = source.getTileGrid();
|
||||
const extent = [-180, -180, 180, 180];
|
||||
const zoom = 3;
|
||||
const range = grid.getTileRangeForExtentAndZ(extent, zoom);
|
||||
|
||||
source.forEachLoadedTile(source.getProjection(), zoom, range, callback);
|
||||
expect(callback.callCount).to.be(0);
|
||||
});
|
||||
|
||||
it('does not call getTile() if no tiles are loaded', function() {
|
||||
var source = new MockTile({});
|
||||
const source = new MockTile({});
|
||||
sinon.spy(source, 'getTile');
|
||||
var grid = source.getTileGrid();
|
||||
var extent = [-180, -180, 180, 180];
|
||||
var zoom = 3;
|
||||
var range = grid.getTileRangeForExtentAndZ(extent, zoom);
|
||||
const grid = source.getTileGrid();
|
||||
const extent = [-180, -180, 180, 180];
|
||||
const zoom = 3;
|
||||
const range = grid.getTileRangeForExtentAndZ(extent, zoom);
|
||||
|
||||
source.forEachLoadedTile(source.getProjection(), zoom, range, callback);
|
||||
expect(source.getTile.callCount).to.be(0);
|
||||
@@ -146,15 +146,15 @@ describe('ol.source.Tile', function() {
|
||||
|
||||
|
||||
it('calls callback for each loaded tile', function() {
|
||||
var source = new MockTile({
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED
|
||||
'1/0/1': 2, // LOADED
|
||||
'1/1/0': 1, // LOADING,
|
||||
'1/1/1': 2 // LOADED
|
||||
});
|
||||
|
||||
var zoom = 1;
|
||||
var range = new TileRange(0, 1, 0, 1);
|
||||
const zoom = 1;
|
||||
const range = new TileRange(0, 1, 0, 1);
|
||||
|
||||
source.forEachLoadedTile(source.getProjection(), zoom, range, callback);
|
||||
expect(callback.callCount).to.be(3);
|
||||
@@ -162,61 +162,61 @@ describe('ol.source.Tile', function() {
|
||||
|
||||
it('returns true if range is fully loaded', function() {
|
||||
// a source with no loaded tiles
|
||||
var source = new MockTile({
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED,
|
||||
'1/0/1': 2, // LOADED,
|
||||
'1/1/0': 2, // LOADED,
|
||||
'1/1/1': 2 // LOADED
|
||||
});
|
||||
|
||||
var zoom = 1;
|
||||
var range = new TileRange(0, 1, 0, 1);
|
||||
const zoom = 1;
|
||||
const range = new TileRange(0, 1, 0, 1);
|
||||
|
||||
var covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom, range,
|
||||
function() {
|
||||
return true;
|
||||
});
|
||||
const covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom, range,
|
||||
function() {
|
||||
return true;
|
||||
});
|
||||
expect(covered).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if range is not fully loaded', function() {
|
||||
// a source with no loaded tiles
|
||||
var source = new MockTile({
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED,
|
||||
'1/0/1': 2, // LOADED,
|
||||
'1/1/0': 1, // LOADING,
|
||||
'1/1/1': 2 // LOADED
|
||||
});
|
||||
|
||||
var zoom = 1;
|
||||
var range = new TileRange(0, 1, 0, 1);
|
||||
const zoom = 1;
|
||||
const range = new TileRange(0, 1, 0, 1);
|
||||
|
||||
var covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom,
|
||||
range, function() {
|
||||
return true;
|
||||
});
|
||||
const covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom,
|
||||
range, function() {
|
||||
return true;
|
||||
});
|
||||
expect(covered).to.be(false);
|
||||
});
|
||||
|
||||
it('allows callback to override loaded check', function() {
|
||||
// a source with no loaded tiles
|
||||
var source = new MockTile({
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2, // LOADED,
|
||||
'1/0/1': 2, // LOADED,
|
||||
'1/1/0': 2, // LOADED,
|
||||
'1/1/1': 2 // LOADED
|
||||
});
|
||||
|
||||
var zoom = 1;
|
||||
var range = new TileRange(0, 1, 0, 1);
|
||||
const zoom = 1;
|
||||
const range = new TileRange(0, 1, 0, 1);
|
||||
|
||||
var covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom, range,
|
||||
function() {
|
||||
return false;
|
||||
});
|
||||
const covered = source.forEachLoadedTile(
|
||||
source.getProjection(), zoom, range,
|
||||
function() {
|
||||
return false;
|
||||
});
|
||||
expect(covered).to.be(false);
|
||||
});
|
||||
|
||||
@@ -225,12 +225,12 @@ describe('ol.source.Tile', function() {
|
||||
describe('#getTileCoordForTileUrlFunction()', function() {
|
||||
|
||||
it('returns the expected tile coordinate - {wrapX: true}', function() {
|
||||
var tileSource = new TileSource({
|
||||
const tileSource = new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
wrapX: true
|
||||
});
|
||||
|
||||
var tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, -23]);
|
||||
let tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, -23]);
|
||||
expect(tileCoord).to.eql([6, 33, -23]);
|
||||
|
||||
tileCoord = tileSource.getTileCoordForTileUrlFunction([6, 33, -23]);
|
||||
@@ -241,12 +241,12 @@ describe('ol.source.Tile', function() {
|
||||
});
|
||||
|
||||
it('returns the expected tile coordinate - {wrapX: false}', function() {
|
||||
var tileSource = new TileSource({
|
||||
const tileSource = new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
wrapX: false
|
||||
});
|
||||
|
||||
var tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, -23]);
|
||||
let tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, -23]);
|
||||
expect(tileCoord).to.eql(null);
|
||||
|
||||
tileCoord = tileSource.getTileCoordForTileUrlFunction([6, 33, -23]);
|
||||
@@ -257,7 +257,7 @@ describe('ol.source.Tile', function() {
|
||||
});
|
||||
|
||||
it('works with wrapX and custom projection without extent', function() {
|
||||
var tileSource = new TileSource({
|
||||
const tileSource = new TileSource({
|
||||
projection: new Projection({
|
||||
code: 'foo',
|
||||
global: true,
|
||||
@@ -266,7 +266,7 @@ describe('ol.source.Tile', function() {
|
||||
wrapX: true
|
||||
});
|
||||
|
||||
var tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, -23]);
|
||||
const tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, -23]);
|
||||
expect(tileCoord).to.eql([6, 33, -23]);
|
||||
});
|
||||
});
|
||||
@@ -274,11 +274,11 @@ describe('ol.source.Tile', function() {
|
||||
describe('#refresh()', function() {
|
||||
it('checks clearing of internal state', function() {
|
||||
// create a source with one loaded tile
|
||||
var source = new MockTile({
|
||||
const source = new MockTile({
|
||||
'1/0/0': 2 // LOADED
|
||||
});
|
||||
// check the loaded tile is there
|
||||
var tile = source.getTile(1, 0, 0);
|
||||
const tile = source.getTile(1, 0, 0);
|
||||
expect(tile).to.be.a(Tile);
|
||||
// check tile cache is filled
|
||||
expect(source.tileCache.getCount()).to.eql(1);
|
||||
@@ -296,7 +296,7 @@ describe('MockTile', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a tile source', function() {
|
||||
var source = new MockTile({});
|
||||
const source = new MockTile({});
|
||||
expect(source).to.be.a(TileSource);
|
||||
expect(source).to.be.a(MockTile);
|
||||
});
|
||||
@@ -304,11 +304,11 @@ describe('MockTile', function() {
|
||||
|
||||
describe('#getTile()', function() {
|
||||
it('returns a tile with state based on constructor arg', function() {
|
||||
var source = new MockTile({
|
||||
const source = new MockTile({
|
||||
'0/0/0': 2, // LOADED,
|
||||
'1/0/0': 2 // LOADED
|
||||
});
|
||||
var tile;
|
||||
let tile;
|
||||
|
||||
// check a loaded tile
|
||||
tile = source.getTile(0, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user