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:
+38
-25
@@ -1,14 +1,19 @@
|
||||
/**
|
||||
* @module ol/tilegrid
|
||||
*/
|
||||
import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from './tilegrid/common.js';
|
||||
import {toSize} from './size.js';
|
||||
import {containsCoordinate, createOrUpdate, getCorner, getHeight, getWidth} from './extent.js';
|
||||
import Corner from './extent/Corner.js';
|
||||
import {get as getProjection, METERS_PER_UNIT} from './proj.js';
|
||||
import Units from './proj/Units.js';
|
||||
import TileGrid from './tilegrid/TileGrid.js';
|
||||
|
||||
import Units from './proj/Units.js';
|
||||
import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from './tilegrid/common.js';
|
||||
import {METERS_PER_UNIT, get as getProjection} from './proj.js';
|
||||
import {
|
||||
containsCoordinate,
|
||||
createOrUpdate,
|
||||
getCorner,
|
||||
getHeight,
|
||||
getWidth,
|
||||
} from './extent.js';
|
||||
import {toSize} from './size.js';
|
||||
|
||||
/**
|
||||
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||
@@ -24,7 +29,6 @@ export function getForProjection(projection) {
|
||||
return tileGrid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {TileGrid} tileGrid Tile grid.
|
||||
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
||||
@@ -37,7 +41,9 @@ export function wrapX(tileGrid, tileCoord, projection) {
|
||||
const projectionExtent = extentFromProjection(projection);
|
||||
if (!containsCoordinate(projectionExtent, center)) {
|
||||
const worldWidth = getWidth(projectionExtent);
|
||||
const worldsAway = Math.ceil((projectionExtent[0] - center[0]) / worldWidth);
|
||||
const worldsAway = Math.ceil(
|
||||
(projectionExtent[0] - center[0]) / worldWidth
|
||||
);
|
||||
center[0] += worldWidth * worldsAway;
|
||||
return tileGrid.getTileCoordForCoordAndZ(center, z);
|
||||
} else {
|
||||
@@ -45,7 +51,6 @@ export function wrapX(tileGrid, tileCoord, projection) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number=} opt_maxZoom Maximum zoom level (default is
|
||||
@@ -64,11 +69,10 @@ export function createForExtent(extent, opt_maxZoom, opt_tileSize, opt_corner) {
|
||||
extent: extent,
|
||||
origin: getCorner(extent, corner),
|
||||
resolutions: resolutions,
|
||||
tileSize: opt_tileSize
|
||||
tileSize: opt_tileSize,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} XYZOptions
|
||||
* @property {import("./extent.js").Extent} [extent] Extent for the tile grid. The origin for an XYZ tile grid is the
|
||||
@@ -81,7 +85,6 @@ export function createForExtent(extent, opt_maxZoom, opt_tileSize, opt_corner) {
|
||||
* @property {number|import("./size.js").Size} [tileSize=[256, 256]] Tile size in pixels.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Creates a tile grid with a standard XYZ tiling scheme.
|
||||
* @param {XYZOptions=} opt_options Tile grid options.
|
||||
@@ -102,12 +105,11 @@ export function createXYZ(opt_options) {
|
||||
xyzOptions.maxZoom,
|
||||
xyzOptions.tileSize,
|
||||
xyzOptions.maxResolution
|
||||
)
|
||||
),
|
||||
};
|
||||
return new TileGrid(gridOptions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a resolutions array from an extent. A zoom factor of 2 is assumed.
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
@@ -118,17 +120,24 @@ export function createXYZ(opt_options) {
|
||||
* @param {number=} opt_maxResolution Resolution at level zero.
|
||||
* @return {!Array<number>} Resolutions array.
|
||||
*/
|
||||
function resolutionsFromExtent(extent, opt_maxZoom, opt_tileSize, opt_maxResolution) {
|
||||
const maxZoom = opt_maxZoom !== undefined ?
|
||||
opt_maxZoom : DEFAULT_MAX_ZOOM;
|
||||
function resolutionsFromExtent(
|
||||
extent,
|
||||
opt_maxZoom,
|
||||
opt_tileSize,
|
||||
opt_maxResolution
|
||||
) {
|
||||
const maxZoom = opt_maxZoom !== undefined ? opt_maxZoom : DEFAULT_MAX_ZOOM;
|
||||
|
||||
const height = getHeight(extent);
|
||||
const width = getWidth(extent);
|
||||
|
||||
const tileSize = toSize(opt_tileSize !== undefined ?
|
||||
opt_tileSize : DEFAULT_TILE_SIZE);
|
||||
const maxResolution = opt_maxResolution > 0 ? opt_maxResolution :
|
||||
Math.max(width / tileSize[0], height / tileSize[1]);
|
||||
const tileSize = toSize(
|
||||
opt_tileSize !== undefined ? opt_tileSize : DEFAULT_TILE_SIZE
|
||||
);
|
||||
const maxResolution =
|
||||
opt_maxResolution > 0
|
||||
? opt_maxResolution
|
||||
: Math.max(width / tileSize[0], height / tileSize[1]);
|
||||
|
||||
const length = maxZoom + 1;
|
||||
const resolutions = new Array(length);
|
||||
@@ -138,7 +147,6 @@ function resolutionsFromExtent(extent, opt_maxZoom, opt_tileSize, opt_maxResolut
|
||||
return resolutions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("./proj.js").ProjectionLike} projection Projection.
|
||||
* @param {number=} opt_maxZoom Maximum zoom level (default is
|
||||
@@ -148,12 +156,16 @@ function resolutionsFromExtent(extent, opt_maxZoom, opt_tileSize, opt_maxResolut
|
||||
* @param {Corner=} opt_corner Extent corner (default is `'top-left'`).
|
||||
* @return {!TileGrid} TileGrid instance.
|
||||
*/
|
||||
export function createForProjection(projection, opt_maxZoom, opt_tileSize, opt_corner) {
|
||||
export function createForProjection(
|
||||
projection,
|
||||
opt_maxZoom,
|
||||
opt_tileSize,
|
||||
opt_corner
|
||||
) {
|
||||
const extent = extentFromProjection(projection);
|
||||
return createForExtent(extent, opt_maxZoom, opt_tileSize, opt_corner);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a tile grid extent from a projection. If the projection has an
|
||||
* extent, it is used. If not, a global extent is assumed.
|
||||
@@ -164,7 +176,8 @@ export function extentFromProjection(projection) {
|
||||
projection = getProjection(projection);
|
||||
let extent = projection.getExtent();
|
||||
if (!extent) {
|
||||
const half = 180 * METERS_PER_UNIT[Units.DEGREES] / projection.getMetersPerUnit();
|
||||
const half =
|
||||
(180 * METERS_PER_UNIT[Units.DEGREES]) / projection.getMetersPerUnit();
|
||||
extent = createOrUpdate(-half, -half, half, half);
|
||||
}
|
||||
return extent;
|
||||
|
||||
Reference in New Issue
Block a user