Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle fractional zooms for layer min/maxResolution properly #1032

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {bbox as bboxStrategy} from 'ol/loadingstrategy.js';
import {createXYZ} from 'ol/tilegrid.js';
import {
defaultResolutions,
defaultTileGrid,
fetchResource,
getFilterCache,
getFunctionCache,
Expand Down Expand Up @@ -1221,18 +1222,20 @@ export function finalizeLayer(
if (minZoom > 0 || sourceMinZoom > 0) {
layer.setMaxResolution(
Math.min(
defaultResolutions[minZoom],
defaultTileGrid.getResolution(minZoom),
tileGrid.getResolution(sourceMinZoom)
) + 1e-9
);
}
if (maxZoom < 24) {
layer.setMinResolution(defaultResolutions[maxZoom] + 1e-9);
layer.setMinResolution(
defaultTileGrid.getResolution(maxZoom) + 1e-9
);
}
}
} else {
if (minZoom > 0) {
layer.setMaxResolution(defaultResolutions[minZoom] + 1e-9);
layer.setMaxResolution(defaultTileGrid.getResolution(minZoom) + 1e-9);
}
}
if (
Expand Down
7 changes: 7 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import TileGrid from 'ol/tilegrid/TileGrid.js';
import TileState from 'ol/TileState.js';
import {VectorTile} from 'ol';
import {expandUrl} from 'ol/tileurlfunction.js';
import {get as getProjection} from 'ol/proj.js';
import {getUid} from 'ol/util.js';
import {normalizeSourceUrl, normalizeStyleUrl} from './mapbox.js';
import {toPromise} from 'ol/functions.js';
Expand Down Expand Up @@ -73,6 +75,11 @@ export const defaultResolutions = (function () {
return resolutions;
})();

export const defaultTileGrid = new TileGrid({
extent: getProjection('EPSG:3857').getExtent(),
resolutions: defaultResolutions,
});

/**
* @param {number} width Width of the canvas.
* @param {number} height Height of the canvas.
Expand Down