Skip to content

Commit

Permalink
Make minZoom inclusive by zoom instead of resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Apr 28, 2024
1 parent a7530e5 commit 67114ed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
16 changes: 11 additions & 5 deletions src/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ export function applyStyle(
) {
layer.setMaxResolution(
getResolutionForZoom(
tileGrid.getMinZoom(),
tileGrid.getMinZoom() - 1e-12,
defaultResolutions,
) + 1e-15,
),
);
}
});
Expand Down Expand Up @@ -1237,9 +1237,12 @@ export function finalizeLayer(
if (minZoom > 0 || sourceMinZoom > 0) {
layer.setMaxResolution(
Math.min(
getResolutionForZoom(minZoom, defaultResolutions),
getResolutionForZoom(
Math.max(0, minZoom - 1e-12),
defaultResolutions,
),
tileGrid.getResolution(sourceMinZoom),
) + 1e-15,
),
);
}
if (maxZoom < 24) {
Expand All @@ -1251,7 +1254,10 @@ export function finalizeLayer(
} else {
if (minZoom > 0) {
layer.setMaxResolution(
getResolutionForZoom(minZoom, defaultResolutions) + 1e-15,
getResolutionForZoom(
Math.max(0, minZoom - 1e-12),
defaultResolutions,
),
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/MapboxVectorLayer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ describe('ol/layer/MapboxVector', () => {
source.on('change', function onchange() {
if (source.getState() === 'ready') {
source.un('change', onchange);
should(layer.getMaxResolution()).eql(
should(layer.getMaxResolution()).be.approximately(
source.getTileGrid().getResolution(6),
1e-8,
);
done();
}
Expand Down
17 changes: 11 additions & 6 deletions test/apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ describe('ol-mapbox-style', function () {
apply(target, context)
.then(function (map) {
should(map.getLayers().item(0).getMaxResolution()).eql(
defaultResolutions[9] + 1e-15,
defaultResolutions[9],
);
done();
})
Expand All @@ -714,8 +714,9 @@ describe('ol-mapbox-style', function () {
context.layers[0].maxzoom = 12;
apply(target, context)
.then(function (map) {
should(map.getLayers().item(0).getMaxResolution()).eql(
defaultResolutions[10] + 1e-15,
should(map.getLayers().item(0).getMaxResolution()).be.approximately(
defaultResolutions[10],
1e-8,
);
should(map.getLayers().item(0).getMinResolution()).eql(
defaultResolutions[12],
Expand Down Expand Up @@ -755,7 +756,10 @@ describe('ol-mapbox-style', function () {
apply(target, './fixtures/geojson-wfs.json')
.then(function (map) {
const layer = map.getAllLayers()[1];
should(layer.getMaxResolution()).eql(defaultResolutions[5] + 1e-15);
should(layer.getMaxResolution()).be.approximately(
defaultResolutions[5],
1e-8,
);
done();
})
.catch(function (err) {
Expand Down Expand Up @@ -913,8 +917,9 @@ describe('ol-mapbox-style', function () {
it('respects layer minzoom and maxzoom', function (done) {
apply(target, context)
.then(function (map) {
should(map.getLayers().item(0).getMaxResolution()).eql(
defaultResolutions[7] + 1e-15,
should(map.getLayers().item(0).getMaxResolution()).be.approximately(
defaultResolutions[7],
1e-8,
);
should(map.getLayers().item(0).getMinResolution()).eql(
defaultResolutions[23],
Expand Down
5 changes: 3 additions & 2 deletions test/applyStyle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ describe('maxResolution', function () {
const layer = new VectorTileLayer();
applyStyle(layer, glStyle)
.then(function () {
should(layer.getMaxResolution()).equal(
layer.getSource().getTileGrid().getResolution(6) - 1e-15,
should(layer.getMaxResolution()).be.approximately(
layer.getSource().getTileGrid().getResolution(6),
1e-8,
);
done();
})
Expand Down

0 comments on commit 67114ed

Please sign in to comment.