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:
@@ -7,16 +7,14 @@
|
||||
* See https://mapbox.com/developers/api/.
|
||||
*/
|
||||
|
||||
|
||||
import {createFromTemplates} from '../tileurlfunction.js';
|
||||
import {assert} from '../asserts.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 TileImage from './TileImage.js';
|
||||
import {applyTransform, intersects} from '../extent.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {createFromTemplates} from '../tileurlfunction.js';
|
||||
import {createXYZ, extentFromProjection} from '../tilegrid.js';
|
||||
|
||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||
import {jsonp as requestJSONP} from '../net.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Config
|
||||
@@ -35,7 +33,6 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
|
||||
* @property {Array<number>} [center] Optional center.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
|
||||
@@ -64,7 +61,6 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
|
||||
* To disable the opacity transition, pass `transition: 0`.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Layer source for tile data in TileJSON format.
|
||||
@@ -85,7 +81,7 @@ class TileJSON extends TileImage {
|
||||
state: SourceState.LOADING,
|
||||
tileLoadFunction: options.tileLoadFunction,
|
||||
wrapX: options.wrapX !== undefined ? options.wrapX : true,
|
||||
transition: options.transition
|
||||
transition: options.transition,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -100,11 +96,13 @@ class TileJSON extends TileImage {
|
||||
*/
|
||||
this.tileSize_ = options.tileSize;
|
||||
|
||||
|
||||
if (options.url) {
|
||||
if (options.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));
|
||||
@@ -117,7 +115,6 @@ class TileJSON extends TileImage {
|
||||
} else {
|
||||
assert(false, 51); // Either `url` or `tileJSON` options must be provided
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,10 +124,10 @@ class TileJSON extends TileImage {
|
||||
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 {TileJSON} */(JSON.parse(client.responseText));
|
||||
response = /** @type {TileJSON} */ (JSON.parse(client.responseText));
|
||||
} catch (err) {
|
||||
this.handleTileJSONError();
|
||||
return;
|
||||
@@ -162,14 +159,15 @@ class TileJSON extends TileImage {
|
||||
* @param {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);
|
||||
}
|
||||
|
||||
@@ -179,27 +177,25 @@ class TileJSON extends TileImage {
|
||||
extent: extentFromProjection(sourceProjection),
|
||||
maxZoom: maxZoom,
|
||||
minZoom: minZoom,
|
||||
tileSize: this.tileSize_
|
||||
tileSize: this.tileSize_,
|
||||
});
|
||||
this.tileGrid = tileGrid;
|
||||
|
||||
this.tileUrlFunction = createFromTemplates(tileJSON['tiles'], tileGrid);
|
||||
|
||||
if (tileJSON['attribution'] !== undefined && !this.getAttributions()) {
|
||||
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']];
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
}
|
||||
this.tileJSON_ = tileJSON;
|
||||
this.setState(SourceState.READY);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,5 +206,4 @@ class TileJSON extends TileImage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default TileJSON;
|
||||
|
||||
Reference in New Issue
Block a user