diff --git a/src/ol/View.js b/src/ol/View.js index b4e5605672..d2ab683f81 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -129,8 +129,9 @@ import {createMinMaxResolution} from './resolutionconstraint.js'; * @property {boolean} [smoothResolutionConstraint=true] If true, the resolution * min/max values will be applied smoothly, i. e. allow the view to exceed slightly * the given resolution or zoom bounds. - * @property {boolean} [largerResolutionConstraint=false] If true, the constrained - * resolution values will use the larger value to do so. + * @property {boolean} [constrainOneAxis=false] If true, the extent constraint can + * be exceeded along one but not both axes, allowing the whole extent to be visible + * on the map. * @property {import("./proj.js").ProjectionLike} [projection='EPSG:3857'] The * projection. The default is Spherical Mercator. * @property {number} [resolution] The initial resolution for the view. The @@ -1613,8 +1614,8 @@ export function createResolutionConstraint(options) { const smooth = options.smoothResolutionConstraint !== undefined ? options.smoothResolutionConstraint : true; - const larger = - options.largerResolutionConstraint !== undefined ? options.largerResolutionConstraint : false; + const oneAxis = + options.constrainOneAxis !== undefined ? options.constrainOneAxis : false; const projection = createProjection(options.projection, 'EPSG:3857'); const projExtent = projection.getExtent(); @@ -1633,10 +1634,10 @@ export function createResolutionConstraint(options) { if (options.constrainResolution) { resolutionConstraint = createSnapToResolutions(resolutions, smooth, - !constrainOnlyCenter && extent, larger); + !constrainOnlyCenter && extent, oneAxis); } else { resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth, - !constrainOnlyCenter && extent, larger); + !constrainOnlyCenter && extent, oneAxis); } } else { // calculate the default min and max resolution @@ -1682,10 +1683,10 @@ export function createResolutionConstraint(options) { if (options.constrainResolution) { resolutionConstraint = createSnapToPower( zoomFactor, maxResolution, minResolution, smooth, - !constrainOnlyCenter && extent, larger); + !constrainOnlyCenter && extent, oneAxis); } else { resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth, - !constrainOnlyCenter && extent, larger); + !constrainOnlyCenter && extent, oneAxis); } } return {constraint: resolutionConstraint, maxResolution: maxResolution, diff --git a/src/ol/resolutionconstraint.js b/src/ol/resolutionconstraint.js index 3d14209ec9..73dec32ace 100644 --- a/src/ol/resolutionconstraint.js +++ b/src/ol/resolutionconstraint.js @@ -16,14 +16,14 @@ import {clamp} from './math.js'; * @param {number} resolution Resolution * @param {import("./extent.js").Extent=} maxExtent Maximum allowed extent. * @param {import("./size.js").Size} viewportSize Viewport size. - * @param {boolean} larger Whether to use the larger resolution size. + * @param {boolean} oneAxis Whether we can exceed extent constraint along one axis but not both. * @return {number} Capped resolution. */ -function getViewportClampedResolution(resolution, maxExtent, viewportSize, larger) { +function getViewportClampedResolution(resolution, maxExtent, viewportSize, oneAxis) { const xResolution = getWidth(maxExtent) / viewportSize[0]; const yResolution = getHeight(maxExtent) / viewportSize[1]; - if (larger) { + if (oneAxis) { return Math.min(resolution, Math.max(xResolution, yResolution)); } return Math.min(resolution, Math.min(xResolution, yResolution)); @@ -57,10 +57,10 @@ function getSmoothClampedResolution(resolution, maxResolution, minResolution) { * @param {Array} resolutions Resolutions. * @param {boolean=} opt_smooth If true, the view will be able to slightly exceed resolution limits. Default: true. * @param {import("./extent.js").Extent=} opt_maxExtent Maximum allowed extent. - * @param {boolean=} opt_larger If true, the view will constrain the larger resolution value. Default: false. + * @param {boolean=} opt_oneAxis If true, can exceed extent constraint along one axis but not both. Default: false. * @return {Type} Zoom function. */ -export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent, opt_larger) { +export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent, opt_oneAxis) { return ( /** * @param {number|undefined} resolution Resolution. @@ -74,7 +74,7 @@ export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent, const maxResolution = resolutions[0]; const minResolution = resolutions[resolutions.length - 1]; const cappedMaxRes = opt_maxExtent ? - getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_larger) : + getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_oneAxis) : maxResolution; // during interacting or animating, allow intermediary values @@ -106,10 +106,10 @@ export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent, * @param {number=} opt_minResolution Minimum resolution. * @param {boolean=} opt_smooth If true, the view will be able to slightly exceed resolution limits. Default: true. * @param {import("./extent.js").Extent=} opt_maxExtent Maximum allowed extent. - * @param {boolean=} opt_larger If true, the view will constrain the larger resolution value. Default: false. + * @param {boolean=} opt_oneAxis If true, can exceed extent constraint along one axis but not both. Default: false. * @return {Type} Zoom function. */ -export function createSnapToPower(power, maxResolution, opt_minResolution, opt_smooth, opt_maxExtent, opt_larger) { +export function createSnapToPower(power, maxResolution, opt_minResolution, opt_smooth, opt_maxExtent, opt_oneAxis) { return ( /** * @param {number|undefined} resolution Resolution. @@ -121,7 +121,7 @@ export function createSnapToPower(power, maxResolution, opt_minResolution, opt_s function(resolution, direction, size, opt_isMoving) { if (resolution !== undefined) { const cappedMaxRes = opt_maxExtent ? - getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_larger) : + getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_oneAxis) : maxResolution; const minResolution = opt_minResolution !== undefined ? opt_minResolution : 0; @@ -155,10 +155,10 @@ export function createSnapToPower(power, maxResolution, opt_minResolution, opt_s * @param {number} minResolution Min resolution. * @param {boolean=} opt_smooth If true, the view will be able to slightly exceed resolution limits. Default: true. * @param {import("./extent.js").Extent=} opt_maxExtent Maximum allowed extent. - * @param {boolean=} opt_larger If true, the view will constrain the larger resolution value. Default: false. + * @param {boolean=} opt_oneAxis If true, can exceed extent constraint along one axis but not both. Default: false. * @return {Type} Zoom function. */ -export function createMinMaxResolution(maxResolution, minResolution, opt_smooth, opt_maxExtent, opt_larger) { +export function createMinMaxResolution(maxResolution, minResolution, opt_smooth, opt_maxExtent, opt_oneAxis) { return ( /** * @param {number|undefined} resolution Resolution. @@ -170,7 +170,7 @@ export function createMinMaxResolution(maxResolution, minResolution, opt_smooth, function(resolution, direction, size, opt_isMoving) { if (resolution !== undefined) { const cappedMaxRes = opt_maxExtent ? - getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_larger) : + getViewportClampedResolution(maxResolution, opt_maxExtent, size, opt_oneAxis) : maxResolution; const smooth = opt_smooth !== undefined ? opt_smooth : true;