Center should remain valid when resolution is not set

This commit is contained in:
Maximilian Krög
2021-10-03 19:36:16 +02:00
parent ab786cff73
commit 5a49410d82
+9 -7
View File
@@ -18,14 +18,19 @@ export function createExtent(extent, onlyCenter, smooth) {
return ( return (
/** /**
* @param {import("./coordinate.js").Coordinate|undefined} center Center. * @param {import("./coordinate.js").Coordinate|undefined} center Center.
* @param {number} resolution Resolution. * @param {number|undefined} resolution Resolution.
* @param {import("./size.js").Size} size Viewport size; unused if `onlyCenter` was specified. * @param {import("./size.js").Size} size Viewport size; unused if `onlyCenter` was specified.
* @param {boolean} [opt_isMoving] True if an interaction or animation is in progress. * @param {boolean} [opt_isMoving] True if an interaction or animation is in progress.
* @param {Array<number>} [opt_centerShift] Shift between map center and viewport center. * @param {Array<number>} [opt_centerShift] Shift between map center and viewport center.
* @return {import("./coordinate.js").Coordinate|undefined} Center. * @return {import("./coordinate.js").Coordinate|undefined} Center.
*/ */
function (center, resolution, size, opt_isMoving, opt_centerShift) { function (center, resolution, size, opt_isMoving, opt_centerShift) {
if (center) { if (!center) {
return undefined;
}
if (!resolution && !onlyCenter) {
return center;
}
const viewWidth = onlyCenter ? 0 : size[0] * resolution; const viewWidth = onlyCenter ? 0 : size[0] * resolution;
const viewHeight = onlyCenter ? 0 : size[1] * resolution; const viewHeight = onlyCenter ? 0 : size[1] * resolution;
const shiftX = opt_centerShift ? opt_centerShift[0] : 0; const shiftX = opt_centerShift ? opt_centerShift[0] : 0;
@@ -48,10 +53,10 @@ export function createExtent(extent, onlyCenter, smooth) {
let x = clamp(center[0], minX, maxX); let x = clamp(center[0], minX, maxX);
let y = clamp(center[1], minY, maxY); let y = clamp(center[1], minY, maxY);
const ratio = 30 * resolution;
// during an interaction, allow some overscroll // during an interaction, allow some overscroll
if (opt_isMoving && smooth) { if (opt_isMoving && smooth && resolution) {
const ratio = 30 * resolution;
x += x +=
-ratio * Math.log(1 + Math.max(0, minX - center[0]) / ratio) + -ratio * Math.log(1 + Math.max(0, minX - center[0]) / ratio) +
ratio * Math.log(1 + Math.max(0, center[0] - maxX) / ratio); ratio * Math.log(1 + Math.max(0, center[0] - maxX) / ratio);
@@ -61,9 +66,6 @@ export function createExtent(extent, onlyCenter, smooth) {
} }
return [x, y]; return [x, y];
} else {
return undefined;
}
} }
); );
} }