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:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -2,15 +2,14 @@
* @module ol/source/BingMaps
*/
import {createFromTileUrlFunctions} from '../tileurlfunction.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 {createFromTileUrlFunctions} from '../tileurlfunction.js';
import {createOrUpdate} from '../tilecoord.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
import {get as getProjection, getTransformFromProjections} from '../proj.js';
import {jsonp as requestJSONP} from '../net.js';
/**
* @param {import('../tilecoord.js').TileCoord} tileCoord Tile coord.
@@ -36,17 +35,16 @@ export function quadKey(tileCoord) {
return digits.join('');
}
/**
* The attribution containing a link to the Microsoft® Bing™ Maps Platform APIs
* Terms Of Use.
* @const
* @type {string}
*/
const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
'href="https://www.microsoft.com/maps/product/terms.html" target="_blank">' +
'Terms of Use</a>';
const TOS_ATTRIBUTION =
'<a class="ol-attribution-bing-tos" ' +
'href="https://www.microsoft.com/maps/product/terms.html" target="_blank">' +
'Terms of Use</a>';
/**
* @typedef {Object} Options
@@ -70,7 +68,6 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
* To disable the opacity transition, pass `transition: 0`.
*/
/**
* @typedef {Object} BingMapsImageryMetadataResponse
* @property {number} statusCode The response status code
@@ -79,13 +76,11 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
* @property {Array<ResourceSet>} resourceSets The array of resource sets
*/
/**
* @typedef {Object} ResourceSet
* @property {Array<Resource>} resources
*/
/**
* @typedef {Object} Resource
* @property {number} imageHeight The image height
@@ -97,14 +92,12 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
* @property {Array<ImageryProvider>} [imageryProviders] The array of ImageryProviders
*/
/**
* @typedef {Object} ImageryProvider
* @property {Array<CoverageArea>} coverageAreas The coverage areas
* @property {string} [attribution] The attribution
*/
/**
* @typedef {Object} CoverageArea
* @property {number} zoomMin The minimum zoom
@@ -112,7 +105,6 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
* @property {Array<number>} bbox The coverage bounding box
*/
/**
* @classdesc
* Layer source for Bing Maps tile data.
@@ -123,7 +115,6 @@ class BingMaps extends TileImage {
* @param {Options} options Bing Maps options.
*/
constructor(options) {
const hidpi = options.hidpi !== undefined ? options.hidpi : false;
super({
@@ -137,7 +128,7 @@ class BingMaps extends TileImage {
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: hidpi ? 2 : 1,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
transition: options.transition
transition: options.transition,
});
/**
@@ -146,7 +137,6 @@ class BingMaps extends TileImage {
*/
this.hidpi_ = hidpi;
/**
* @private
* @type {string}
@@ -171,14 +161,20 @@ class BingMaps extends TileImage {
*/
this.imagerySet_ = options.imagerySet;
const url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/' +
this.imagerySet_ +
'?uriScheme=https&include=ImageryProviders&key=' + this.apiKey_ +
'&c=' + this.culture_;
requestJSONP(url, this.handleImageryMetadataResponse.bind(this), undefined,
'jsonp');
const url =
'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/' +
this.imagerySet_ +
'?uriScheme=https&include=ImageryProviders&key=' +
this.apiKey_ +
'&c=' +
this.culture_;
requestJSONP(
url,
this.handleImageryMetadataResponse.bind(this),
undefined,
'jsonp'
);
}
/**
@@ -205,11 +201,13 @@ class BingMaps extends TileImage {
* @param {BingMapsImageryMetadataResponse} response Response.
*/
handleImageryMetadataResponse(response) {
if (response.statusCode != 200 ||
response.statusDescription != 'OK' ||
response.authenticationResultCode != 'ValidCredentials' ||
response.resourceSets.length != 1 ||
response.resourceSets[0].resources.length != 1) {
if (
response.statusCode != 200 ||
response.statusDescription != 'OK' ||
response.authenticationResultCode != 'ValidCredentials' ||
response.resourceSets.length != 1 ||
response.resourceSets[0].resources.length != 1
) {
this.setState(SourceState.ERROR);
return;
}
@@ -220,22 +218,23 @@ class BingMaps extends TileImage {
const sourceProjection = this.getProjection();
const extent = extentFromProjection(sourceProjection);
const scale = this.hidpi_ ? 2 : 1;
const tileSize = resource.imageWidth == resource.imageHeight ?
resource.imageWidth / scale :
[resource.imageWidth / scale, resource.imageHeight / scale];
const tileSize =
resource.imageWidth == resource.imageHeight
? resource.imageWidth / scale
: [resource.imageWidth / scale, resource.imageHeight / scale];
const tileGrid = createXYZ({
extent: extent,
minZoom: resource.zoomMin,
maxZoom: maxZoom,
tileSize: tileSize
tileSize: tileSize,
});
this.tileGrid = tileGrid;
const culture = this.culture_;
const hidpi = this.hidpi_;
this.tileUrlFunction = createFromTileUrlFunctions(
resource.imageUrlSubdomains.map(function(subdomain) {
resource.imageUrlSubdomains.map(function (subdomain) {
/** @type {import('../tilecoord.js').TileCoord} */
const quadKeyTileCoord = [0, 0, 0];
const imageUrl = resource.imageUrl
@@ -248,11 +247,16 @@ class BingMaps extends TileImage {
* @param {import("../proj/Projection.js").default} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
function (tileCoord, pixelRatio, projection) {
if (!tileCoord) {
return undefined;
} else {
createOrUpdate(tileCoord[0], tileCoord[1], tileCoord[2], quadKeyTileCoord);
createOrUpdate(
tileCoord[0],
tileCoord[1],
tileCoord[2],
quadKeyTileCoord
);
let url = imageUrl;
if (hidpi) {
url += '&dpi=d1&device=mobile';
@@ -261,42 +265,56 @@ class BingMaps extends TileImage {
}
}
);
}));
})
);
if (resource.imageryProviders) {
const transform = getTransformFromProjections(
getProjection('EPSG:4326'), this.getProjection());
getProjection('EPSG:4326'),
this.getProjection()
);
this.setAttributions(function(frameState) {
const attributions = [];
const viewState = frameState.viewState;
const tileGrid = this.getTileGrid();
const z = tileGrid.getZForResolution(viewState.resolution, this.zDirection);
const tileCoord = tileGrid.getTileCoordForCoordAndZ(viewState.center, z);
const zoom = tileCoord[0];
resource.imageryProviders.map(function(imageryProvider) {
let intersecting = false;
const coverageAreas = imageryProvider.coverageAreas;
for (let i = 0, ii = coverageAreas.length; i < ii; ++i) {
const coverageArea = coverageAreas[i];
if (zoom >= coverageArea.zoomMin && zoom <= coverageArea.zoomMax) {
const bbox = coverageArea.bbox;
const epsg4326Extent = [bbox[1], bbox[0], bbox[3], bbox[2]];
const extent = applyTransform(epsg4326Extent, transform);
if (intersects(extent, frameState.extent)) {
intersecting = true;
break;
this.setAttributions(
function (frameState) {
const attributions = [];
const viewState = frameState.viewState;
const tileGrid = this.getTileGrid();
const z = tileGrid.getZForResolution(
viewState.resolution,
this.zDirection
);
const tileCoord = tileGrid.getTileCoordForCoordAndZ(
viewState.center,
z
);
const zoom = tileCoord[0];
resource.imageryProviders.map(function (imageryProvider) {
let intersecting = false;
const coverageAreas = imageryProvider.coverageAreas;
for (let i = 0, ii = coverageAreas.length; i < ii; ++i) {
const coverageArea = coverageAreas[i];
if (
zoom >= coverageArea.zoomMin &&
zoom <= coverageArea.zoomMax
) {
const bbox = coverageArea.bbox;
const epsg4326Extent = [bbox[1], bbox[0], bbox[3], bbox[2]];
const extent = applyTransform(epsg4326Extent, transform);
if (intersects(extent, frameState.extent)) {
intersecting = true;
break;
}
}
}
}
if (intersecting) {
attributions.push(imageryProvider.attribution);
}
});
if (intersecting) {
attributions.push(imageryProvider.attribution);
}
});
attributions.push(TOS_ATTRIBUTION);
return attributions;
}.bind(this));
attributions.push(TOS_ATTRIBUTION);
return attributions;
}.bind(this)
);
}
this.setState(SourceState.READY);