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
+91 -43
View File
@@ -1,15 +1,16 @@
/**
* @module ol/tilegrid/TileGrid
*/
import TileRange, {
createOrUpdate as createOrUpdateTileRange,
} from '../TileRange.js';
import {DEFAULT_TILE_SIZE} from './common.js';
import {assert} from '../asserts.js';
import TileRange, {createOrUpdate as createOrUpdateTileRange} from '../TileRange.js';
import {isSorted, linearFindNearest} from '../array.js';
import {createOrUpdate, getTopLeft} from '../extent.js';
import {clamp} from '../math.js';
import {toSize} from '../size.js';
import {createOrUpdate, getTopLeft} from '../extent.js';
import {createOrUpdate as createOrUpdateTileCoord} from '../tilecoord.js';
import {isSorted, linearFindNearest} from '../array.js';
import {toSize} from '../size.js';
/**
* @private
@@ -17,7 +18,6 @@ import {createOrUpdate as createOrUpdateTileCoord} from '../tilecoord.js';
*/
const tmpTileCoord = [0, 0, 0];
/**
* @typedef {Object} Options
* @property {import("../extent.js").Extent} [extent] Extent for the tile grid. No tiles outside this
@@ -49,7 +49,6 @@ const tmpTileCoord = [0, 0, 0];
* tile size.
*/
/**
* @classdesc
* Base class for setting the grid pattern for sources accessing tiled-image
@@ -61,7 +60,6 @@ class TileGrid {
* @param {Options} options Tile grid options.
*/
constructor(options) {
/**
* @protected
* @type {number}
@@ -73,10 +71,16 @@ class TileGrid {
* @type {!Array<number>}
*/
this.resolutions_ = options.resolutions;
assert(isSorted(this.resolutions_, function(a, b) {
return b - a;
}, true), 17); // `resolutions` must be sorted in descending order
assert(
isSorted(
this.resolutions_,
function (a, b) {
return b - a;
},
true
),
17
); // `resolutions` must be sorted in descending order
// check if we've got a consistent zoom factor and origin
let zoomFactor;
@@ -93,14 +97,12 @@ class TileGrid {
}
}
/**
* @private
* @type {number|undefined}
*/
this.zoomFactor_ = zoomFactor;
/**
* @protected
* @type {number}
@@ -120,20 +122,19 @@ class TileGrid {
this.origins_ = null;
if (options.origins !== undefined) {
this.origins_ = options.origins;
assert(this.origins_.length == this.resolutions_.length,
20); // Number of `origins` and `resolutions` must be equal
assert(this.origins_.length == this.resolutions_.length, 20); // Number of `origins` and `resolutions` must be equal
}
const extent = options.extent;
if (extent !== undefined &&
!this.origin_ && !this.origins_) {
if (extent !== undefined && !this.origin_ && !this.origins_) {
this.origin_ = getTopLeft(extent);
}
assert(
(!this.origin_ && this.origins_) || (this.origin_ && !this.origins_),
18); // Either `origin` or `origins` must be configured, never both
18
); // Either `origin` or `origins` must be configured, never both
/**
* @private
@@ -142,21 +143,24 @@ class TileGrid {
this.tileSizes_ = null;
if (options.tileSizes !== undefined) {
this.tileSizes_ = options.tileSizes;
assert(this.tileSizes_.length == this.resolutions_.length,
19); // Number of `tileSizes` and `resolutions` must be equal
assert(this.tileSizes_.length == this.resolutions_.length, 19); // Number of `tileSizes` and `resolutions` must be equal
}
/**
* @private
* @type {number|import("../size.js").Size}
*/
this.tileSize_ = options.tileSize !== undefined ?
options.tileSize :
!this.tileSizes_ ? DEFAULT_TILE_SIZE : null;
this.tileSize_ =
options.tileSize !== undefined
? options.tileSize
: !this.tileSizes_
? DEFAULT_TILE_SIZE
: null;
assert(
(!this.tileSize_ && this.tileSizes_) ||
(this.tileSize_ && !this.tileSizes_),
22); // Either `tileSize` or `tileSizes` must be configured, never both
22
); // Either `tileSize` or `tileSizes` must be configured, never both
/**
* @private
@@ -164,7 +168,6 @@ class TileGrid {
*/
this.extent_ = extent !== undefined ? extent : null;
/**
* @private
* @type {Array<import("../TileRange.js").default>}
@@ -178,16 +181,18 @@ class TileGrid {
this.tmpSize_ = [0, 0];
if (options.sizes !== undefined) {
this.fullTileRanges_ = options.sizes.map(function(size, z) {
this.fullTileRanges_ = options.sizes.map(function (size, z) {
const tileRange = new TileRange(
Math.min(0, size[0]), Math.max(size[0] - 1, -1),
Math.min(0, size[1]), Math.max(size[1] - 1, -1));
Math.min(0, size[0]),
Math.max(size[0] - 1, -1),
Math.min(0, size[1]),
Math.max(size[1] - 1, -1)
);
return tileRange;
}, this);
} else if (extent) {
this.calculateTileRanges_(extent);
}
}
/**
@@ -214,7 +219,12 @@ class TileGrid {
* @param {import("../extent.js").Extent=} opt_extent Temporary import("../extent.js").Extent object.
* @return {boolean} Callback succeeded.
*/
forEachTileCoordParentTileRange(tileCoord, callback, opt_tileRange, opt_extent) {
forEachTileCoordParentTileRange(
tileCoord,
callback,
opt_tileRange,
opt_extent
) {
let tileRange, x, y;
let tileCoordExtent = null;
let z = tileCoord[0] - 1;
@@ -230,7 +240,11 @@ class TileGrid {
y = Math.floor(y / 2);
tileRange = createOrUpdateTileRange(x, x, y, y, opt_tileRange);
} else {
tileRange = this.getTileRangeForExtentAndZ(tileCoordExtent, z, opt_tileRange);
tileRange = this.getTileRangeForExtentAndZ(
tileCoordExtent,
z,
opt_tileRange
);
}
if (callback(z, tileRange)) {
return true;
@@ -311,11 +325,20 @@ class TileGrid {
if (this.zoomFactor_ === 2) {
const minX = tileCoord[1] * 2;
const minY = tileCoord[2] * 2;
return createOrUpdateTileRange(minX, minX + 1, minY, minY + 1, opt_tileRange);
return createOrUpdateTileRange(
minX,
minX + 1,
minY,
minY + 1,
opt_tileRange
);
}
const tileCoordExtent = this.getTileCoordExtent(tileCoord, opt_extent);
return this.getTileRangeForExtentAndZ(
tileCoordExtent, tileCoord[0] + 1, opt_tileRange);
tileCoordExtent,
tileCoord[0] + 1,
opt_tileRange
);
}
return null;
}
@@ -351,7 +374,13 @@ class TileGrid {
const minX = tileCoord[1];
const minY = tileCoord[2];
this.getTileCoordForXYAndZ_(extent[2], extent[1], z, true, tileCoord);
return createOrUpdateTileRange(minX, tileCoord[1], minY, tileCoord[2], opt_tileRange);
return createOrUpdateTileRange(
minX,
tileCoord[1],
minY,
tileCoord[2],
opt_tileRange
);
}
/**
@@ -364,7 +393,7 @@ class TileGrid {
const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
return [
origin[0] + (tileCoord[1] + 0.5) * tileSize[0] * resolution,
origin[1] - (tileCoord[2] + 0.5) * tileSize[1] * resolution
origin[1] - (tileCoord[2] + 0.5) * tileSize[1] * resolution,
];
}
@@ -400,7 +429,12 @@ class TileGrid {
*/
getTileCoordForCoordAndResolution(coordinate, resolution, opt_tileCoord) {
return this.getTileCoordForXYAndResolution_(
coordinate[0], coordinate[1], resolution, false, opt_tileCoord);
coordinate[0],
coordinate[1],
resolution,
false,
opt_tileCoord
);
}
/**
@@ -416,7 +450,13 @@ class TileGrid {
* @return {import("../tilecoord.js").TileCoord} Tile coordinate.
* @private
*/
getTileCoordForXYAndResolution_(x, y, resolution, reverseIntersectionPolicy, opt_tileCoord) {
getTileCoordForXYAndResolution_(
x,
y,
resolution,
reverseIntersectionPolicy,
opt_tileCoord
) {
const z = this.getZForResolution(resolution);
const scale = resolution / this.getResolution(z);
const origin = this.getOrigin(z);
@@ -426,8 +466,8 @@ class TileGrid {
const adjustY = reverseIntersectionPolicy ? 0.5 : 0;
const xFromOrigin = Math.floor((x - origin[0]) / resolution + adjustX);
const yFromOrigin = Math.floor((origin[1] - y) / resolution + adjustY);
let tileCoordX = scale * xFromOrigin / tileSize[0];
let tileCoordY = scale * yFromOrigin / tileSize[1];
let tileCoordX = (scale * xFromOrigin) / tileSize[0];
let tileCoordY = (scale * yFromOrigin) / tileSize[1];
if (reverseIntersectionPolicy) {
tileCoordX = Math.ceil(tileCoordX) - 1;
@@ -488,7 +528,12 @@ class TileGrid {
*/
getTileCoordForCoordAndZ(coordinate, z, opt_tileCoord) {
return this.getTileCoordForXYAndZ_(
coordinate[0], coordinate[1], z, false, opt_tileCoord);
coordinate[0],
coordinate[1],
z,
false,
opt_tileCoord
);
}
/**
@@ -536,7 +581,11 @@ class TileGrid {
* @api
*/
getZForResolution(resolution, opt_direction) {
const z = linearFindNearest(this.resolutions_, resolution, opt_direction || 0);
const z = linearFindNearest(
this.resolutions_,
resolution,
opt_direction || 0
);
return clamp(z, this.minZoom, this.maxZoom);
}
@@ -554,5 +603,4 @@ class TileGrid {
}
}
export default TileGrid;
+28 -20
View File
@@ -2,10 +2,9 @@
* @module ol/tilegrid/WMTS
*/
import TileGrid from './TileGrid.js';
import {find} from '../array.js';
import {get as getProjection} from '../proj.js';
import TileGrid from './TileGrid.js';
/**
* @typedef {Object} Options
@@ -39,7 +38,6 @@ import TileGrid from './TileGrid.js';
* this array needs to match the length of the `resolutions` array.
*/
/**
* @classdesc
* Set the grid pattern for sources accessing WMTS tiled-image servers.
@@ -57,7 +55,7 @@ class WMTSTileGrid extends TileGrid {
resolutions: options.resolutions,
tileSize: options.tileSize,
tileSizes: options.tileSizes,
sizes: options.sizes
sizes: options.sizes,
});
/**
@@ -85,7 +83,6 @@ class WMTSTileGrid extends TileGrid {
}
}
export default WMTSTileGrid;
/**
@@ -100,8 +97,11 @@ export default WMTSTileGrid;
* @return {WMTSTileGrid} WMTS tileGrid instance.
* @api
*/
export function createFromCapabilitiesMatrixSet(matrixSet, opt_extent, opt_matrixLimits) {
export function createFromCapabilitiesMatrixSet(
matrixSet,
opt_extent,
opt_matrixLimits
) {
/** @type {!Array<number>} */
const resolutions = [];
/** @type {!Array<string>} */
@@ -124,30 +124,34 @@ export function createFromCapabilitiesMatrixSet(matrixSet, opt_extent, opt_matri
const tileHeightPropName = 'TileHeight';
const code = matrixSet[supportedCRSPropName];
const projection = getProjection(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
getProjection(code);
const projection =
getProjection(
code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')
) || getProjection(code);
const metersPerUnit = projection.getMetersPerUnit();
// swap origin x and y coordinates if axis orientation is lat/long
const switchOriginXY = projection.getAxisOrientation().substr(0, 2) == 'ne';
matrixSet[matrixIdsPropName].sort(function(a, b) {
matrixSet[matrixIdsPropName].sort(function (a, b) {
return b[scaleDenominatorPropName] - a[scaleDenominatorPropName];
});
matrixSet[matrixIdsPropName].forEach(function(elt) {
matrixSet[matrixIdsPropName].forEach(function (elt) {
let matrixAvailable;
// use of matrixLimits to filter TileMatrices from GetCapabilities
// TileMatrixSet from unavailable matrix levels.
if (matrixLimits.length > 0) {
matrixAvailable = find(matrixLimits, function(elt_ml) {
matrixAvailable = find(matrixLimits, function (elt_ml) {
if (elt[identifierPropName] == elt_ml[matrixIdsPropName]) {
return true;
}
// Fallback for tileMatrix identifiers that don't get prefixed
// by their tileMatrixSet identifiers.
if (elt[identifierPropName].indexOf(':') === -1) {
return matrixSet[identifierPropName] + ':' + elt[identifierPropName] === elt_ml[matrixIdsPropName];
return (
matrixSet[identifierPropName] + ':' + elt[identifierPropName] ===
elt_ml[matrixIdsPropName]
);
}
return false;
});
@@ -157,18 +161,22 @@ export function createFromCapabilitiesMatrixSet(matrixSet, opt_extent, opt_matri
if (matrixAvailable) {
matrixIds.push(elt[identifierPropName]);
const resolution = elt[scaleDenominatorPropName] * 0.28E-3 / metersPerUnit;
const resolution =
(elt[scaleDenominatorPropName] * 0.28e-3) / metersPerUnit;
const tileWidth = elt[tileWidthPropName];
const tileHeight = elt[tileHeightPropName];
if (switchOriginXY) {
origins.push([elt[topLeftCornerPropName][1],
elt[topLeftCornerPropName][0]]);
origins.push([
elt[topLeftCornerPropName][1],
elt[topLeftCornerPropName][0],
]);
} else {
origins.push(elt[topLeftCornerPropName]);
}
resolutions.push(resolution);
tileSizes.push(tileWidth == tileHeight ?
tileWidth : [tileWidth, tileHeight]);
tileSizes.push(
tileWidth == tileHeight ? tileWidth : [tileWidth, tileHeight]
);
sizes.push([elt['MatrixWidth'], elt['MatrixHeight']]);
}
});
@@ -179,6 +187,6 @@ export function createFromCapabilitiesMatrixSet(matrixSet, opt_extent, opt_matri
resolutions: resolutions,
matrixIds: matrixIds,
tileSizes: tileSizes,
sizes: sizes
sizes: sizes,
});
}