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

@@ -53,16 +53,27 @@
* {@link module:ol/proj~addProjection}. See examples/wms-no-proj for an example of
* this.
*/
import {getDistance} from './sphere.js';
import {applyTransform} from './extent.js';
import {modulo} from './math.js';
import {toEPSG4326, fromEPSG4326, PROJECTIONS as EPSG3857_PROJECTIONS} from './proj/epsg3857.js';
import {PROJECTIONS as EPSG4326_PROJECTIONS} from './proj/epsg4326.js';
import Projection from './proj/Projection.js';
import Units, {METERS_PER_UNIT} from './proj/Units.js';
import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransformFunc} from './proj/transforms.js';
import {add as addProj, clear as clearProj, get as getProj} from './proj/projections.js';
import {
PROJECTIONS as EPSG3857_PROJECTIONS,
fromEPSG4326,
toEPSG4326,
} from './proj/epsg3857.js';
import {PROJECTIONS as EPSG4326_PROJECTIONS} from './proj/epsg4326.js';
import {
add as addProj,
clear as clearProj,
get as getProj,
} from './proj/projections.js';
import {
add as addTransformFunc,
clear as clearTransformFuncs,
get as getTransformFunc,
} from './proj/transforms.js';
import {applyTransform} from './extent.js';
import {getDistance} from './sphere.js';
import {modulo} from './math.js';
/**
* A projection as {@link module:ol/proj/Projection}, SRS identifier
@@ -71,7 +82,6 @@ import {add as addProj, clear as clearProj, get as getProj} from './proj/project
* @api
*/
/**
* A transform function accepts an array of input coordinate values, an optional
* output array, and an optional dimension (default should be 2). The function
@@ -82,7 +92,6 @@ import {add as addProj, clear as clearProj, get as getProj} from './proj/project
* @api
*/
export {METERS_PER_UNIT};
export {Projection};
@@ -107,7 +116,6 @@ export function cloneTransform(input, opt_output, opt_dimension) {
return output;
}
/**
* @param {Array<number>} input Input coordinate array.
* @param {Array<number>=} opt_output Output array of coordinate values.
@@ -124,7 +132,6 @@ export function identityTransform(input, opt_output, opt_dimension) {
return input;
}
/**
* Add a Projection object to the list of supported projections that can be
* looked up by their code.
@@ -137,7 +144,6 @@ export function addProjection(projection) {
addTransformFunc(projection, projection, cloneTransform);
}
/**
* @param {Array<Projection>} projections Projections.
*/
@@ -145,7 +151,6 @@ export function addProjections(projections) {
projections.forEach(addProjection);
}
/**
* Fetches a Projection object for the code specified.
*
@@ -156,12 +161,11 @@ export function addProjections(projections) {
* @api
*/
export function get(projectionLike) {
return typeof projectionLike === 'string' ?
getProj(/** @type {string} */ (projectionLike)) :
(/** @type {Projection} */ (projectionLike) || null);
return typeof projectionLike === 'string'
? getProj(/** @type {string} */ (projectionLike))
: /** @type {Projection} */ (projectionLike) || null;
}
/**
* Get the resolution of the point in degrees or distance units.
* For projections with degrees as the unit this will simply return the
@@ -191,31 +195,39 @@ export function getPointResolution(projection, resolution, point, opt_units) {
if (opt_units && opt_units !== projection.getUnits()) {
const metersPerUnit = projection.getMetersPerUnit();
if (metersPerUnit) {
pointResolution = pointResolution * metersPerUnit / METERS_PER_UNIT[opt_units];
pointResolution =
(pointResolution * metersPerUnit) / METERS_PER_UNIT[opt_units];
}
}
} else {
const units = projection.getUnits();
if (units == Units.DEGREES && !opt_units || opt_units == Units.DEGREES) {
if ((units == Units.DEGREES && !opt_units) || opt_units == Units.DEGREES) {
pointResolution = resolution;
} else {
// Estimate point resolution by transforming the center pixel to EPSG:4326,
// measuring its width and height on the normal sphere, and taking the
// average of the width and height.
const toEPSG4326 = getTransformFromProjections(projection, get('EPSG:4326'));
const toEPSG4326 = getTransformFromProjections(
projection,
get('EPSG:4326')
);
let vertices = [
point[0] - resolution / 2, point[1],
point[0] + resolution / 2, point[1],
point[0], point[1] - resolution / 2,
point[0], point[1] + resolution / 2
point[0] - resolution / 2,
point[1],
point[0] + resolution / 2,
point[1],
point[0],
point[1] - resolution / 2,
point[0],
point[1] + resolution / 2,
];
vertices = toEPSG4326(vertices, vertices, 2);
const width = getDistance(vertices.slice(0, 2), vertices.slice(2, 4));
const height = getDistance(vertices.slice(4, 6), vertices.slice(6, 8));
pointResolution = (width + height) / 2;
const metersPerUnit = opt_units ?
METERS_PER_UNIT[opt_units] :
projection.getMetersPerUnit();
const metersPerUnit = opt_units
? METERS_PER_UNIT[opt_units]
: projection.getMetersPerUnit();
if (metersPerUnit !== undefined) {
pointResolution /= metersPerUnit;
}
@@ -224,7 +236,6 @@ export function getPointResolution(projection, resolution, point, opt_units) {
return pointResolution;
}
/**
* Registers transformation functions that don't alter coordinates. Those allow
* to transform between projections with equal meaning.
@@ -234,8 +245,8 @@ export function getPointResolution(projection, resolution, point, opt_units) {
*/
export function addEquivalentProjections(projections) {
addProjections(projections);
projections.forEach(function(source) {
projections.forEach(function(destination) {
projections.forEach(function (source) {
projections.forEach(function (destination) {
if (source !== destination) {
addTransformFunc(source, destination, cloneTransform);
}
@@ -243,7 +254,6 @@ export function addEquivalentProjections(projections) {
});
}
/**
* Registers transformation functions to convert coordinates in any projection
* in projection1 to any projection in projection2.
@@ -257,16 +267,20 @@ export function addEquivalentProjections(projections) {
* @param {TransformFunction} inverseTransform Transform from any projection
* in projection2 to any projection in projection1..
*/
export function addEquivalentTransforms(projections1, projections2, forwardTransform, inverseTransform) {
projections1.forEach(function(projection1) {
projections2.forEach(function(projection2) {
export function addEquivalentTransforms(
projections1,
projections2,
forwardTransform,
inverseTransform
) {
projections1.forEach(function (projection1) {
projections2.forEach(function (projection2) {
addTransformFunc(projection1, projection2, forwardTransform);
addTransformFunc(projection2, projection1, inverseTransform);
});
});
}
/**
* Clear all cached projections and transforms.
*/
@@ -275,7 +289,6 @@ export function clearAllProjections() {
clearTransformFuncs();
}
/**
* @param {Projection|string|undefined} projection Projection.
* @param {string} defaultCode Default code.
@@ -287,13 +300,10 @@ export function createProjection(projection, defaultCode) {
} else if (typeof projection === 'string') {
return get(projection);
} else {
return (
/** @type {Projection} */ (projection)
);
return /** @type {Projection} */ (projection);
}
}
/**
* Creates a {@link module:ol/proj~TransformFunction} from a simple 2D coordinate transform
* function.
@@ -309,7 +319,7 @@ export function createTransformFromCoordinateTransform(coordTransform) {
* @param {number=} opt_dimension Dimension.
* @return {Array<number>} Output.
*/
function(input, opt_output, opt_dimension) {
function (input, opt_output, opt_dimension) {
const length = input.length;
const dimension = opt_dimension !== undefined ? opt_dimension : 2;
const output = opt_output !== undefined ? opt_output : new Array(length);
@@ -322,10 +332,10 @@ export function createTransformFromCoordinateTransform(coordTransform) {
}
}
return output;
});
}
);
}
/**
* Registers coordinate transform functions to convert coordinates between the
* source projection and the destination projection.
@@ -348,11 +358,18 @@ export function createTransformFromCoordinateTransform(coordTransform) {
export function addCoordinateTransforms(source, destination, forward, inverse) {
const sourceProj = get(source);
const destProj = get(destination);
addTransformFunc(sourceProj, destProj, createTransformFromCoordinateTransform(forward));
addTransformFunc(destProj, sourceProj, createTransformFromCoordinateTransform(inverse));
addTransformFunc(
sourceProj,
destProj,
createTransformFromCoordinateTransform(forward)
);
addTransformFunc(
destProj,
sourceProj,
createTransformFromCoordinateTransform(inverse)
);
}
/**
* Transforms a coordinate from longitude/latitude to a different projection.
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate as longitude and latitude, i.e.
@@ -363,11 +380,13 @@ export function addCoordinateTransforms(source, destination, forward, inverse) {
* @api
*/
export function fromLonLat(coordinate, opt_projection) {
return transform(coordinate, 'EPSG:4326',
opt_projection !== undefined ? opt_projection : 'EPSG:3857');
return transform(
coordinate,
'EPSG:4326',
opt_projection !== undefined ? opt_projection : 'EPSG:3857'
);
}
/**
* Transforms a coordinate to longitude/latitude.
* @param {import("./coordinate.js").Coordinate} coordinate Projected coordinate.
@@ -378,8 +397,11 @@ export function fromLonLat(coordinate, opt_projection) {
* @api
*/
export function toLonLat(coordinate, opt_projection) {
const lonLat = transform(coordinate,
opt_projection !== undefined ? opt_projection : 'EPSG:3857', 'EPSG:4326');
const lonLat = transform(
coordinate,
opt_projection !== undefined ? opt_projection : 'EPSG:3857',
'EPSG:4326'
);
const lon = lonLat[0];
if (lon < -180 || lon > 180) {
lonLat[0] = modulo(lon + 180, 360) - 180;
@@ -387,7 +409,6 @@ export function toLonLat(coordinate, opt_projection) {
return lonLat;
}
/**
* Checks if two projections are the same, that is every coordinate in one
* projection does represent the same geographic point as the same coordinate in
@@ -411,7 +432,6 @@ export function equivalent(projection1, projection2) {
}
}
/**
* Searches in the list of transform functions for the function for converting
* coordinates from the source projection to the destination projection.
@@ -421,7 +441,10 @@ export function equivalent(projection1, projection2) {
* object.
* @return {TransformFunction} Transform function.
*/
export function getTransformFromProjections(sourceProjection, destinationProjection) {
export function getTransformFromProjections(
sourceProjection,
destinationProjection
) {
const sourceCode = sourceProjection.getCode();
const destinationCode = destinationProjection.getCode();
let transformFunc = getTransformFunc(sourceCode, destinationCode);
@@ -431,7 +454,6 @@ export function getTransformFromProjections(sourceProjection, destinationProject
return transformFunc;
}
/**
* Given the projection-like objects, searches for a transformation
* function to convert a coordinates array from the source projection to the
@@ -448,7 +470,6 @@ export function getTransform(source, destination) {
return getTransformFromProjections(sourceProjection, destinationProjection);
}
/**
* Transforms a coordinate from source projection to destination projection.
* This returns a new coordinate (and does not modify the original).
@@ -468,7 +489,6 @@ export function transform(coordinate, source, destination) {
return transformFunc(coordinate, undefined, coordinate.length);
}
/**
* Transforms an extent from source projection to destination projection. This
* returns a new extent (and does not modify the original).
@@ -486,7 +506,6 @@ export function transformExtent(extent, source, destination, opt_stops) {
return applyTransform(extent, transformFunc, undefined, opt_stops);
}
/**
* Transforms the given point to the destination projection.
*
@@ -495,8 +514,15 @@ export function transformExtent(extent, source, destination, opt_stops) {
* @param {Projection} destinationProjection Destination projection.
* @return {import("./coordinate.js").Coordinate} Point.
*/
export function transformWithProjections(point, sourceProjection, destinationProjection) {
const transformFunc = getTransformFromProjections(sourceProjection, destinationProjection);
export function transformWithProjections(
point,
sourceProjection,
destinationProjection
) {
const transformFunc = getTransformFromProjections(
sourceProjection,
destinationProjection
);
return transformFunc(point);
}
@@ -611,7 +637,12 @@ export function addCommon() {
addEquivalentProjections(EPSG4326_PROJECTIONS);
// Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
// coordinates and back.
addEquivalentTransforms(EPSG4326_PROJECTIONS, EPSG3857_PROJECTIONS, fromEPSG4326, toEPSG4326);
addEquivalentTransforms(
EPSG4326_PROJECTIONS,
EPSG3857_PROJECTIONS,
fromEPSG4326,
toEPSG4326
);
}
addCommon();