Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
+79
-71
@@ -2,19 +2,19 @@
|
||||
* @module ol/source/UTFGrid
|
||||
*/
|
||||
|
||||
import Tile from '../Tile.js';
|
||||
import TileState from '../TileState.js';
|
||||
import {createFromTemplates, nullTileUrlFunction} from '../tileurlfunction.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {listenOnce} from '../events.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {applyTransform, intersects} from '../extent.js';
|
||||
import {jsonp as requestJSONP} from '../net.js';
|
||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||
import SourceState from './State.js';
|
||||
import Tile from '../Tile.js';
|
||||
import TileSource from './Tile.js';
|
||||
import {getKeyZXY} from '../tilecoord.js';
|
||||
import TileState from '../TileState.js';
|
||||
import {applyTransform, intersects} from '../extent.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {createFromTemplates, nullTileUrlFunction} from '../tileurlfunction.js';
|
||||
import {createXYZ, extentFromProjection} from '../tilegrid.js';
|
||||
import {getKeyZXY} from '../tilecoord.js';
|
||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||
import {listenOnce} from '../events.js';
|
||||
import {jsonp as requestJSONP} from '../net.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} UTFGridJSON
|
||||
@@ -23,9 +23,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
|
||||
* @property {Object<string, Object>} [data] Optional data.
|
||||
*/
|
||||
|
||||
|
||||
export class CustomTile extends Tile {
|
||||
|
||||
/**
|
||||
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
||||
* @param {TileState} state State.
|
||||
@@ -35,7 +33,6 @@ export class CustomTile extends Tile {
|
||||
* @param {boolean} jsonp Load the tile as a script.
|
||||
*/
|
||||
constructor(tileCoord, state, src, extent, preemptive, jsonp) {
|
||||
|
||||
super(tileCoord, state);
|
||||
|
||||
/**
|
||||
@@ -74,13 +71,11 @@ export class CustomTile extends Tile {
|
||||
*/
|
||||
this.data_ = null;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.jsonp_ = jsonp;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +86,6 @@ export class CustomTile extends Tile {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Synchronously returns data at given coordinate (if available).
|
||||
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
||||
@@ -101,10 +95,10 @@ export class CustomTile extends Tile {
|
||||
if (!this.grid_ || !this.keys_) {
|
||||
return null;
|
||||
}
|
||||
const xRelative = (coordinate[0] - this.extent_[0]) /
|
||||
(this.extent_[2] - this.extent_[0]);
|
||||
const yRelative = (coordinate[1] - this.extent_[1]) /
|
||||
(this.extent_[3] - this.extent_[1]);
|
||||
const xRelative =
|
||||
(coordinate[0] - this.extent_[0]) / (this.extent_[2] - this.extent_[0]);
|
||||
const yRelative =
|
||||
(coordinate[1] - this.extent_[1]) / (this.extent_[3] - this.extent_[1]);
|
||||
|
||||
const row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)];
|
||||
|
||||
@@ -133,7 +127,6 @@ export class CustomTile extends Tile {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls the callback (synchronously by default) with the available data
|
||||
* for given coordinate (or `null` if not yet loaded).
|
||||
@@ -145,22 +138,29 @@ export class CustomTile extends Tile {
|
||||
forDataAtCoordinate(coordinate, callback, opt_request) {
|
||||
if (this.state == TileState.EMPTY && opt_request === true) {
|
||||
this.state = TileState.IDLE;
|
||||
listenOnce(this, EventType.CHANGE, function(e) {
|
||||
callback(this.getData(coordinate));
|
||||
}, this);
|
||||
listenOnce(
|
||||
this,
|
||||
EventType.CHANGE,
|
||||
function (e) {
|
||||
callback(this.getData(coordinate));
|
||||
},
|
||||
this
|
||||
);
|
||||
this.loadInternal_();
|
||||
} else {
|
||||
if (opt_request === true) {
|
||||
setTimeout(function() {
|
||||
callback(this.getData(coordinate));
|
||||
}.bind(this), 0);
|
||||
setTimeout(
|
||||
function () {
|
||||
callback(this.getData(coordinate));
|
||||
}.bind(this),
|
||||
0
|
||||
);
|
||||
} else {
|
||||
callback(this.getData(coordinate));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the key to be used for all tiles in the source.
|
||||
* @return {string} The key for all tiles.
|
||||
@@ -169,7 +169,6 @@ export class CustomTile extends Tile {
|
||||
return this.src_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -178,7 +177,6 @@ export class CustomTile extends Tile {
|
||||
this.changed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {!UTFGridJSON} json UTFGrid data.
|
||||
* @private
|
||||
@@ -192,7 +190,6 @@ export class CustomTile extends Tile {
|
||||
this.changed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -200,8 +197,11 @@ export class CustomTile extends Tile {
|
||||
if (this.state == TileState.IDLE) {
|
||||
this.state = TileState.LOADING;
|
||||
if (this.jsonp_) {
|
||||
requestJSONP(this.src_, this.handleLoad_.bind(this),
|
||||
this.handleError_.bind(this));
|
||||
requestJSONP(
|
||||
this.src_,
|
||||
this.handleLoad_.bind(this),
|
||||
this.handleError_.bind(this)
|
||||
);
|
||||
} else {
|
||||
const client = new XMLHttpRequest();
|
||||
client.addEventListener('load', this.onXHRLoad_.bind(this));
|
||||
@@ -212,7 +212,6 @@ export class CustomTile extends Tile {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event The load event.
|
||||
@@ -220,10 +219,12 @@ export class CustomTile extends Tile {
|
||||
onXHRLoad_(event) {
|
||||
const client = /** @type {XMLHttpRequest} */ (event.target);
|
||||
// status will be 0 for file:// urls
|
||||
if (!client.status || client.status >= 200 && client.status < 300) {
|
||||
if (!client.status || (client.status >= 200 && client.status < 300)) {
|
||||
let response;
|
||||
try {
|
||||
response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText));
|
||||
response = /** @type {!UTFGridJSON} */ (JSON.parse(
|
||||
client.responseText
|
||||
));
|
||||
} catch (err) {
|
||||
this.handleError_();
|
||||
return;
|
||||
@@ -234,7 +235,6 @@ export class CustomTile extends Tile {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event The error event.
|
||||
@@ -243,7 +243,6 @@ export class CustomTile extends Tile {
|
||||
this.handleError_();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
load() {
|
||||
@@ -255,7 +254,6 @@ export class CustomTile extends Tile {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {boolean} [preemptive=true]
|
||||
@@ -272,7 +270,6 @@ export class CustomTile extends Tile {
|
||||
* Request will be made through JSONP. If not provided, `tileJSON` must be configured.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Layer source for UTFGrid interaction data loaded from TileJSON format.
|
||||
@@ -285,15 +282,15 @@ class UTFGrid extends TileSource {
|
||||
constructor(options) {
|
||||
super({
|
||||
projection: getProjection('EPSG:3857'),
|
||||
state: SourceState.LOADING
|
||||
state: SourceState.LOADING,
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.preemptive_ = options.preemptive !== undefined ?
|
||||
options.preemptive : true;
|
||||
this.preemptive_ =
|
||||
options.preemptive !== undefined ? options.preemptive : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -315,8 +312,11 @@ class UTFGrid extends TileSource {
|
||||
|
||||
if (options.url) {
|
||||
if (this.jsonp_) {
|
||||
requestJSONP(options.url, this.handleTileJSONResponse.bind(this),
|
||||
this.handleTileJSONError.bind(this));
|
||||
requestJSONP(
|
||||
options.url,
|
||||
this.handleTileJSONResponse.bind(this),
|
||||
this.handleTileJSONError.bind(this)
|
||||
);
|
||||
} else {
|
||||
const client = new XMLHttpRequest();
|
||||
client.addEventListener('load', this.onXHRLoad_.bind(this));
|
||||
@@ -329,10 +329,8 @@ class UTFGrid extends TileSource {
|
||||
} else {
|
||||
assert(false, 51); // Either `url` or `tileJSON` options must be provided
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event The load event.
|
||||
@@ -340,10 +338,12 @@ class UTFGrid extends TileSource {
|
||||
onXHRLoad_(event) {
|
||||
const client = /** @type {XMLHttpRequest} */ (event.target);
|
||||
// status will be 0 for file:// urls
|
||||
if (!client.status || client.status >= 200 && client.status < 300) {
|
||||
if (!client.status || (client.status >= 200 && client.status < 300)) {
|
||||
let response;
|
||||
try {
|
||||
response = /** @type {import("./TileJSON.js").Config} */(JSON.parse(client.responseText));
|
||||
response = /** @type {import("./TileJSON.js").Config} */ (JSON.parse(
|
||||
client.responseText
|
||||
));
|
||||
} catch (err) {
|
||||
this.handleTileJSONError();
|
||||
return;
|
||||
@@ -354,7 +354,6 @@ class UTFGrid extends TileSource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event The error event.
|
||||
@@ -363,7 +362,6 @@ class UTFGrid extends TileSource {
|
||||
this.handleTileJSONError();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the template from TileJSON.
|
||||
* @return {string|undefined} The template from TileJSON.
|
||||
@@ -373,7 +371,6 @@ class UTFGrid extends TileSource {
|
||||
return this.template_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls the callback (synchronously by default) with the available data
|
||||
* for given coordinate and resolution (or `null` if not yet loaded or
|
||||
@@ -386,16 +383,25 @@ class UTFGrid extends TileSource {
|
||||
* @api
|
||||
*/
|
||||
forDataAtCoordinateAndResolution(
|
||||
coordinate, resolution, callback, opt_request) {
|
||||
coordinate,
|
||||
resolution,
|
||||
callback,
|
||||
opt_request
|
||||
) {
|
||||
if (this.tileGrid) {
|
||||
const z = this.tileGrid.getZForResolution(resolution, this.zDirection);
|
||||
const tileCoord = this.tileGrid.getTileCoordForCoordAndZ(coordinate, z);
|
||||
const tile = /** @type {!CustomTile} */(this.getTile(
|
||||
tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
|
||||
const tile = /** @type {!CustomTile} */ (this.getTile(
|
||||
tileCoord[0],
|
||||
tileCoord[1],
|
||||
tileCoord[2],
|
||||
1,
|
||||
this.getProjection()
|
||||
));
|
||||
tile.forDataAtCoordinate(coordinate, callback, opt_request);
|
||||
} else {
|
||||
if (opt_request === true) {
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
callback(null);
|
||||
}, 0);
|
||||
} else {
|
||||
@@ -404,7 +410,6 @@ class UTFGrid extends TileSource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
@@ -412,21 +417,21 @@ class UTFGrid extends TileSource {
|
||||
this.setState(SourceState.ERROR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: very similar to ol/source/TileJSON#handleTileJSONResponse
|
||||
* @protected
|
||||
* @param {import("./TileJSON.js").Config} tileJSON Tile JSON.
|
||||
*/
|
||||
handleTileJSONResponse(tileJSON) {
|
||||
|
||||
const epsg4326Projection = getProjection('EPSG:4326');
|
||||
|
||||
const sourceProjection = this.getProjection();
|
||||
let extent;
|
||||
if (tileJSON['bounds'] !== undefined) {
|
||||
const transform = getTransformFromProjections(
|
||||
epsg4326Projection, sourceProjection);
|
||||
epsg4326Projection,
|
||||
sourceProjection
|
||||
);
|
||||
extent = applyTransform(tileJSON['bounds'], transform);
|
||||
}
|
||||
|
||||
@@ -435,7 +440,7 @@ class UTFGrid extends TileSource {
|
||||
const tileGrid = createXYZ({
|
||||
extent: extentFromProjection(sourceProjection),
|
||||
maxZoom: maxZoom,
|
||||
minZoom: minZoom
|
||||
minZoom: minZoom,
|
||||
});
|
||||
this.tileGrid = tileGrid;
|
||||
|
||||
@@ -450,10 +455,10 @@ class UTFGrid extends TileSource {
|
||||
this.tileUrlFunction_ = createFromTemplates(grids, tileGrid);
|
||||
|
||||
if (tileJSON['attribution'] !== undefined) {
|
||||
const attributionExtent = extent !== undefined ?
|
||||
extent : epsg4326Projection.getExtent();
|
||||
const attributionExtent =
|
||||
extent !== undefined ? extent : epsg4326Projection.getExtent();
|
||||
|
||||
this.setAttributions(function(frameState) {
|
||||
this.setAttributions(function (frameState) {
|
||||
if (intersects(attributionExtent, frameState.extent)) {
|
||||
return [tileJSON['attribution']];
|
||||
}
|
||||
@@ -462,10 +467,8 @@ class UTFGrid extends TileSource {
|
||||
}
|
||||
|
||||
this.setState(SourceState.READY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Tile coordinate z.
|
||||
* @param {number} x Tile coordinate x.
|
||||
@@ -480,22 +483,28 @@ class UTFGrid extends TileSource {
|
||||
return this.tileCache.get(tileCoordKey);
|
||||
} else {
|
||||
const tileCoord = [z, x, y];
|
||||
const urlTileCoord =
|
||||
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
||||
const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
||||
const urlTileCoord = this.getTileCoordForTileUrlFunction(
|
||||
tileCoord,
|
||||
projection
|
||||
);
|
||||
const tileUrl = this.tileUrlFunction_(
|
||||
urlTileCoord,
|
||||
pixelRatio,
|
||||
projection
|
||||
);
|
||||
const tile = new CustomTile(
|
||||
tileCoord,
|
||||
tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY,
|
||||
tileUrl !== undefined ? tileUrl : '',
|
||||
this.tileGrid.getTileCoordExtent(tileCoord),
|
||||
this.preemptive_,
|
||||
this.jsonp_);
|
||||
this.jsonp_
|
||||
);
|
||||
this.tileCache.set(tileCoordKey, tile);
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Marks a tile coord as being used, without triggering a load.
|
||||
* @param {number} z Tile coordinate z.
|
||||
@@ -510,5 +519,4 @@ class UTFGrid extends TileSource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default UTFGrid;
|
||||
|
||||
Reference in New Issue
Block a user