Respect mutiWorld: false same as explicit extent
Fixes #9577 The multiWorld: false constraint is currently not taken into account when constrainResolution is set or when an explicit resolutions array is specified, while an explicit extent constraint is respected in the same situations. This pull request takes a global projection extent into consideration in that same situations that an explicit extent would be. Add multiWorld tests with resolution constraints includes fix for #9937
This commit is contained in:
+15
-14
@@ -198,7 +198,7 @@ const DEFAULT_MIN_ZOOM = 0;
|
|||||||
*
|
*
|
||||||
* ### The view states
|
* ### The view states
|
||||||
*
|
*
|
||||||
* An View is determined by three states: `center`, `resolution`,
|
* A View is determined by three states: `center`, `resolution`,
|
||||||
* and `rotation`. Each state has a corresponding getter and setter, e.g.
|
* and `rotation`. Each state has a corresponding getter and setter, e.g.
|
||||||
* `getCenter` and `setCenter` for the `center` state.
|
* `getCenter` and `setCenter` for the `center` state.
|
||||||
*
|
*
|
||||||
@@ -1452,6 +1452,15 @@ export function createResolutionConstraint(options) {
|
|||||||
const smooth =
|
const smooth =
|
||||||
options.smoothResolutionConstraint !== undefined ? options.smoothResolutionConstraint : true;
|
options.smoothResolutionConstraint !== undefined ? options.smoothResolutionConstraint : true;
|
||||||
|
|
||||||
|
const projection = createProjection(options.projection, 'EPSG:3857');
|
||||||
|
const projExtent = projection.getExtent();
|
||||||
|
let constrainOnlyCenter = options.constrainOnlyCenter;
|
||||||
|
let extent = options.extent;
|
||||||
|
if (!multiWorld && !extent && projection.isGlobal()) {
|
||||||
|
constrainOnlyCenter = false;
|
||||||
|
extent = projExtent;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.resolutions !== undefined) {
|
if (options.resolutions !== undefined) {
|
||||||
const resolutions = options.resolutions;
|
const resolutions = options.resolutions;
|
||||||
maxResolution = resolutions[minZoom];
|
maxResolution = resolutions[minZoom];
|
||||||
@@ -1460,20 +1469,18 @@ export function createResolutionConstraint(options) {
|
|||||||
|
|
||||||
if (options.constrainResolution) {
|
if (options.constrainResolution) {
|
||||||
resolutionConstraint = createSnapToResolutions(resolutions, smooth,
|
resolutionConstraint = createSnapToResolutions(resolutions, smooth,
|
||||||
!options.constrainOnlyCenter && options.extent);
|
!constrainOnlyCenter && extent);
|
||||||
} else {
|
} else {
|
||||||
resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth,
|
resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth,
|
||||||
!options.constrainOnlyCenter && options.extent);
|
!constrainOnlyCenter && extent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// calculate the default min and max resolution
|
// calculate the default min and max resolution
|
||||||
const projection = createProjection(options.projection, 'EPSG:3857');
|
const size = !projExtent ?
|
||||||
const extent = projection.getExtent();
|
|
||||||
const size = !extent ?
|
|
||||||
// use an extent that can fit the whole world if need be
|
// use an extent that can fit the whole world if need be
|
||||||
360 * METERS_PER_UNIT[Units.DEGREES] /
|
360 * METERS_PER_UNIT[Units.DEGREES] /
|
||||||
projection.getMetersPerUnit() :
|
projection.getMetersPerUnit() :
|
||||||
Math.max(getWidth(extent), getHeight(extent));
|
Math.max(getWidth(projExtent), getHeight(projExtent));
|
||||||
|
|
||||||
const defaultMaxResolution = size / DEFAULT_TILE_SIZE / Math.pow(
|
const defaultMaxResolution = size / DEFAULT_TILE_SIZE / Math.pow(
|
||||||
defaultZoomFactor, DEFAULT_MIN_ZOOM);
|
defaultZoomFactor, DEFAULT_MIN_ZOOM);
|
||||||
@@ -1511,14 +1518,8 @@ export function createResolutionConstraint(options) {
|
|||||||
if (options.constrainResolution) {
|
if (options.constrainResolution) {
|
||||||
resolutionConstraint = createSnapToPower(
|
resolutionConstraint = createSnapToPower(
|
||||||
zoomFactor, maxResolution, minResolution, smooth,
|
zoomFactor, maxResolution, minResolution, smooth,
|
||||||
!options.constrainOnlyCenter && options.extent);
|
!constrainOnlyCenter && extent);
|
||||||
} else {
|
} else {
|
||||||
let constrainOnlyCenter = options.constrainOnlyCenter;
|
|
||||||
let extent = options.extent;
|
|
||||||
if (!multiWorld && !extent && projection.isGlobal()) {
|
|
||||||
constrainOnlyCenter = false;
|
|
||||||
extent = projection.getExtent();
|
|
||||||
}
|
|
||||||
resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth,
|
resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth,
|
||||||
!constrainOnlyCenter && extent);
|
!constrainOnlyCenter && extent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ export function createSnapToResolutions(resolutions, opt_smooth, opt_maxExtent)
|
|||||||
|
|
||||||
const capped = Math.min(cappedMaxRes, resolution);
|
const capped = Math.min(cappedMaxRes, resolution);
|
||||||
const z = Math.floor(linearFindNearest(resolutions, capped, direction));
|
const z = Math.floor(linearFindNearest(resolutions, capped, direction));
|
||||||
|
if (resolutions[z] > cappedMaxRes && z < resolutions.length - 1) {
|
||||||
|
return resolutions[z + 1];
|
||||||
|
}
|
||||||
return resolutions[z];
|
return resolutions[z];
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@@ -430,6 +430,8 @@ describe('ol.View', function() {
|
|||||||
|
|
||||||
const defaultMaxRes = 156543.03392804097;
|
const defaultMaxRes = 156543.03392804097;
|
||||||
const size = [512, 512];
|
const size = [512, 512];
|
||||||
|
const maxResolution = 160000;
|
||||||
|
const resolutions = [160000, 80000, 40000, 20000, 10000, 5000];
|
||||||
function getConstraint(options) {
|
function getConstraint(options) {
|
||||||
return createResolutionConstraint(options).constraint;
|
return createResolutionConstraint(options).constraint;
|
||||||
}
|
}
|
||||||
@@ -439,12 +441,61 @@ describe('ol.View', function() {
|
|||||||
expect(fn(defaultMaxRes, 0, size)).to.be(defaultMaxRes / 2);
|
expect(fn(defaultMaxRes, 0, size)).to.be(defaultMaxRes / 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be enabled by setting multiWorld to truet', function() {
|
it('can be enabled by setting multiWorld to true', function() {
|
||||||
const fn = getConstraint({
|
const fn = getConstraint({
|
||||||
multiWorld: true
|
multiWorld: true
|
||||||
});
|
});
|
||||||
expect(fn(defaultMaxRes, 0, size)).to.be(defaultMaxRes);
|
expect(fn(defaultMaxRes, 0, size)).to.be(defaultMaxRes);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('disabled, with constrainResolution', function() {
|
||||||
|
const fn = getConstraint({
|
||||||
|
maxResolution: maxResolution,
|
||||||
|
constrainResolution: true
|
||||||
|
});
|
||||||
|
expect(fn(defaultMaxRes, 0, size)).to.be(defaultMaxRes / 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('enabled, with constrainResolution', function() {
|
||||||
|
const fn = getConstraint({
|
||||||
|
maxResolution: maxResolution,
|
||||||
|
constrainResolution: true,
|
||||||
|
multiWorld: true
|
||||||
|
});
|
||||||
|
expect(fn(defaultMaxRes, 0, size)).to.be(maxResolution);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('disabled, with resolutions array', function() {
|
||||||
|
const fn = getConstraint({
|
||||||
|
resolutions: resolutions
|
||||||
|
});
|
||||||
|
expect(fn(defaultMaxRes, 0, size)).to.be(defaultMaxRes / 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('enabled, with resolutions array', function() {
|
||||||
|
const fn = getConstraint({
|
||||||
|
resolutions: resolutions,
|
||||||
|
multiWorld: true
|
||||||
|
});
|
||||||
|
expect(fn(defaultMaxRes, 0, size)).to.be(defaultMaxRes);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('disabled, with resolutions array and constrainResolution', function() {
|
||||||
|
const fn = getConstraint({
|
||||||
|
resolutions: resolutions,
|
||||||
|
constrainResolution: true
|
||||||
|
});
|
||||||
|
expect(fn(defaultMaxRes, 0, size)).to.be(resolutions[2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('enabled, with resolutions array and constrainResolution', function() {
|
||||||
|
const fn = getConstraint({
|
||||||
|
resolutions: resolutions,
|
||||||
|
constrainResolution: true,
|
||||||
|
multiWorld: true
|
||||||
|
});
|
||||||
|
expect(fn(defaultMaxRes, 0, size)).to.be(resolutions[0]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user