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:
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* @module ol/resolutionconstraint
|
||||
*/
|
||||
import {linearFindNearest} from './array.js';
|
||||
import {getHeight, getWidth} from './extent.js';
|
||||
import {clamp} from './math.js';
|
||||
|
||||
import {getHeight, getWidth} from './extent.js';
|
||||
import {linearFindNearest} from './array.js';
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number, import("./size.js").Size, boolean=): (number|undefined)} Type
|
||||
@@ -19,7 +18,12 @@ import {clamp} from './math.js';
|
||||
* @param {boolean} showFullExtent Whether to show the full extent.
|
||||
* @return {number} Capped resolution.
|
||||
*/
|
||||
function getViewportClampedResolution(resolution, maxExtent, viewportSize, showFullExtent) {
|
||||
function getViewportClampedResolution(
|
||||
resolution,
|
||||
maxExtent,
|
||||
viewportSize,
|
||||
showFullExtent
|
||||
) {
|
||||
const xResolution = getWidth(maxExtent) / viewportSize[0];
|
||||
const yResolution = getHeight(maxExtent) / viewportSize[1];
|
||||
|
||||
@@ -45,10 +49,15 @@ function getSmoothClampedResolution(resolution, maxResolution, minResolution) {
|
||||
let result = Math.min(resolution, maxResolution);
|
||||
const ratio = 50;
|
||||
|
||||
result *= Math.log(1 + ratio * Math.max(0, resolution / maxResolution - 1)) / ratio + 1;
|
||||
result *=
|
||||
Math.log(1 + ratio * Math.max(0, resolution / maxResolution - 1)) / ratio +
|
||||
1;
|
||||
if (minResolution) {
|
||||
result = Math.max(result, minResolution);
|
||||
result /= Math.log(1 + ratio * Math.max(0, minResolution / resolution - 1)) / ratio + 1;
|
||||
result /=
|
||||
Math.log(1 + ratio * Math.max(0, minResolution / resolution - 1)) /
|
||||
ratio +
|
||||
1;
|
||||
}
|
||||
return clamp(result, minResolution / 2, maxResolution * 2);
|
||||
}
|
||||
@@ -60,7 +69,12 @@ function getSmoothClampedResolution(resolution, maxResolution, minResolution) {
|
||||
* @param {boolean=} opt_showFullExtent If true, allows us to show the full extent. Default: false.
|
||||
* @return {Type} Zoom function.
|
||||
*/
|
||||
export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent, opt_showFullExtent) {
|
||||
export function createSnapToResolutions(
|
||||
resolutions,
|
||||
opt_smooth,
|
||||
opt_maxExtent,
|
||||
opt_showFullExtent
|
||||
) {
|
||||
return (
|
||||
/**
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
@@ -69,13 +83,18 @@ export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent,
|
||||
* @param {boolean=} opt_isMoving True if an interaction or animation is in progress.
|
||||
* @return {number|undefined} Resolution.
|
||||
*/
|
||||
function(resolution, direction, size, opt_isMoving) {
|
||||
function (resolution, direction, size, opt_isMoving) {
|
||||
if (resolution !== undefined) {
|
||||
const maxResolution = resolutions[0];
|
||||
const minResolution = resolutions[resolutions.length - 1];
|
||||
const cappedMaxRes = opt_maxExtent ?
|
||||
getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_showFullExtent) :
|
||||
maxResolution;
|
||||
const cappedMaxRes = opt_maxExtent
|
||||
? getViewportClampedResolution(
|
||||
maxResolution,
|
||||
opt_maxExtent,
|
||||
size,
|
||||
opt_showFullExtent
|
||||
)
|
||||
: maxResolution;
|
||||
|
||||
// during interacting or animating, allow intermediary values
|
||||
if (opt_isMoving) {
|
||||
@@ -83,7 +102,11 @@ export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent,
|
||||
if (!smooth) {
|
||||
return clamp(resolution, minResolution, cappedMaxRes);
|
||||
}
|
||||
return getSmoothClampedResolution(resolution, cappedMaxRes, minResolution);
|
||||
return getSmoothClampedResolution(
|
||||
resolution,
|
||||
cappedMaxRes,
|
||||
minResolution
|
||||
);
|
||||
}
|
||||
|
||||
const capped = Math.min(cappedMaxRes, resolution);
|
||||
@@ -99,7 +122,6 @@ export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} power Power.
|
||||
* @param {number} maxResolution Maximum resolution.
|
||||
@@ -109,7 +131,14 @@ export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent,
|
||||
* @param {boolean=} opt_showFullExtent If true, allows us to show the full extent. Default: false.
|
||||
* @return {Type} Zoom function.
|
||||
*/
|
||||
export function createSnapToPower(power, maxResolution, opt_minResolution, opt_smooth, opt_maxExtent, opt_showFullExtent) {
|
||||
export function createSnapToPower(
|
||||
power,
|
||||
maxResolution,
|
||||
opt_minResolution,
|
||||
opt_smooth,
|
||||
opt_maxExtent,
|
||||
opt_showFullExtent
|
||||
) {
|
||||
return (
|
||||
/**
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
@@ -118,12 +147,18 @@ export function createSnapToPower(power, maxResolution, opt_minResolution, opt_s
|
||||
* @param {boolean=} opt_isMoving True if an interaction or animation is in progress.
|
||||
* @return {number|undefined} Resolution.
|
||||
*/
|
||||
function(resolution, direction, size, opt_isMoving) {
|
||||
function (resolution, direction, size, opt_isMoving) {
|
||||
if (resolution !== undefined) {
|
||||
const cappedMaxRes = opt_maxExtent ?
|
||||
getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_showFullExtent) :
|
||||
maxResolution;
|
||||
const minResolution = opt_minResolution !== undefined ? opt_minResolution : 0;
|
||||
const cappedMaxRes = opt_maxExtent
|
||||
? getViewportClampedResolution(
|
||||
maxResolution,
|
||||
opt_maxExtent,
|
||||
size,
|
||||
opt_showFullExtent
|
||||
)
|
||||
: maxResolution;
|
||||
const minResolution =
|
||||
opt_minResolution !== undefined ? opt_minResolution : 0;
|
||||
|
||||
// during interacting or animating, allow intermediary values
|
||||
if (opt_isMoving) {
|
||||
@@ -131,23 +166,30 @@ export function createSnapToPower(power, maxResolution, opt_minResolution, opt_s
|
||||
if (!smooth) {
|
||||
return clamp(resolution, minResolution, cappedMaxRes);
|
||||
}
|
||||
return getSmoothClampedResolution(resolution, cappedMaxRes, minResolution);
|
||||
return getSmoothClampedResolution(
|
||||
resolution,
|
||||
cappedMaxRes,
|
||||
minResolution
|
||||
);
|
||||
}
|
||||
|
||||
const tolerance = 1e-9;
|
||||
const minZoomLevel = Math.ceil(
|
||||
Math.log(maxResolution / cappedMaxRes) / Math.log(power) - tolerance);
|
||||
Math.log(maxResolution / cappedMaxRes) / Math.log(power) - tolerance
|
||||
);
|
||||
const offset = -direction * (0.5 - tolerance) + 0.5;
|
||||
const capped = Math.min(cappedMaxRes, resolution);
|
||||
const cappedZoomLevel = Math.floor(
|
||||
Math.log(maxResolution / capped) / Math.log(power) + offset);
|
||||
Math.log(maxResolution / capped) / Math.log(power) + offset
|
||||
);
|
||||
const zoomLevel = Math.max(minZoomLevel, cappedZoomLevel);
|
||||
const newResolution = maxResolution / Math.pow(power, zoomLevel);
|
||||
return clamp(newResolution, minResolution, cappedMaxRes);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +200,13 @@ export function createSnapToPower(power, maxResolution, opt_minResolution, opt_s
|
||||
* @param {boolean=} opt_showFullExtent If true, allows us to show the full extent. Default: false.
|
||||
* @return {Type} Zoom function.
|
||||
*/
|
||||
export function createMinMaxResolution(maxResolution, minResolution, opt_smooth, opt_maxExtent, opt_showFullExtent) {
|
||||
export function createMinMaxResolution(
|
||||
maxResolution,
|
||||
minResolution,
|
||||
opt_smooth,
|
||||
opt_maxExtent,
|
||||
opt_showFullExtent
|
||||
) {
|
||||
return (
|
||||
/**
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
@@ -167,17 +215,26 @@ export function createMinMaxResolution(maxResolution, minResolution, opt_smooth,
|
||||
* @param {boolean=} opt_isMoving True if an interaction or animation is in progress.
|
||||
* @return {number|undefined} Resolution.
|
||||
*/
|
||||
function(resolution, direction, size, opt_isMoving) {
|
||||
function (resolution, direction, size, opt_isMoving) {
|
||||
if (resolution !== undefined) {
|
||||
const cappedMaxRes = opt_maxExtent ?
|
||||
getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_showFullExtent) :
|
||||
maxResolution;
|
||||
const cappedMaxRes = opt_maxExtent
|
||||
? getViewportClampedResolution(
|
||||
maxResolution,
|
||||
opt_maxExtent,
|
||||
size,
|
||||
opt_showFullExtent
|
||||
)
|
||||
: maxResolution;
|
||||
const smooth = opt_smooth !== undefined ? opt_smooth : true;
|
||||
|
||||
if (!smooth || !opt_isMoving) {
|
||||
return clamp(resolution, minResolution, cappedMaxRes);
|
||||
}
|
||||
return getSmoothClampedResolution(resolution, cappedMaxRes, minResolution);
|
||||
return getSmoothClampedResolution(
|
||||
resolution,
|
||||
cappedMaxRes,
|
||||
minResolution
|
||||
);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user