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

Make minZoom inclusive by zoom instead of resolution #1141

Merged
merged 1 commit into from
Apr 28, 2024
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
23 changes: 16 additions & 7 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(),
defaultResolutions,
) + 1e-15,
Math.max(0, tileGrid.getMinZoom() - 1e-12),
tileGrid.getResolutions(),
),
);
}
});
Expand Down Expand Up @@ -1237,9 +1237,15 @@ export function finalizeLayer(
if (minZoom > 0 || sourceMinZoom > 0) {
layer.setMaxResolution(
Math.min(
getResolutionForZoom(minZoom, defaultResolutions),
tileGrid.getResolution(sourceMinZoom),
) + 1e-15,
getResolutionForZoom(
Math.max(0, minZoom - 1e-12),
defaultResolutions,
),
getResolutionForZoom(
Math.max(0, sourceMinZoom - 1e-12),
tileGrid.getResolutions(),
),
),
);
}
if (maxZoom < 24) {
Expand All @@ -1251,7 +1257,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
9 changes: 6 additions & 3 deletions test/MapboxVectorLayer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Map from 'ol/Map.js';
import MapboxVectorLayer from '../src/MapboxVectorLayer.js';
import View from 'ol/View.js';
import should from 'should';
import {defaultResolutions, getZoomForResolution} from '../src/util.js';
import {unByKey} from 'ol/Observable.js';

describe('ol/layer/MapboxVector', () => {
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('ol/layer/MapboxVector', () => {
'foo': {
tiles: ['/spec/ol/data/{z}-{x}-{y}.vector.pbf'],
type: 'vector',
tileSize: 256,
minzoom: 6,
},
},
Expand Down Expand Up @@ -82,9 +84,10 @@ describe('ol/layer/MapboxVector', () => {
source.on('change', function onchange() {
if (source.getState() === 'ready') {
source.un('change', onchange);
should(layer.getMaxResolution()).eql(
source.getTileGrid().getResolution(6),
);
should(
getZoomForResolution(layer.getMaxResolution(), defaultResolutions) +
1e-12,
).eql(5);
done();
}
});
Expand Down
54 changes: 37 additions & 17 deletions test/apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
setFeatureState,
} from '../src/index.js';
import {containsExtent} from 'ol/extent.js';
import {defaultResolutions} from '../src/util.js';
import {defaultResolutions, getZoomForResolution} from '../src/util.js';
delete brightV9.sprite;

describe('ol-mapbox-style', function () {
Expand Down Expand Up @@ -699,9 +699,12 @@ describe('ol-mapbox-style', function () {
context.sources.states.minzoom = 10;
apply(target, context)
.then(function (map) {
should(map.getLayers().item(0).getMaxResolution()).eql(
defaultResolutions[9] + 1e-15,
);
should(
getZoomForResolution(
map.getLayers().item(0).getMaxResolution(),
defaultResolutions,
) + 1e-12,
).eql(9);
done();
})
.catch(function (err) {
Expand All @@ -714,9 +717,12 @@ 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(
getZoomForResolution(
map.getLayers().item(0).getMaxResolution(),
defaultResolutions,
) + 1e-12,
).eql(10);
should(map.getLayers().item(0).getMinResolution()).eql(
defaultResolutions[12],
);
Expand Down Expand Up @@ -755,7 +761,12 @@ 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(
getZoomForResolution(
layer.getMaxResolution(),
defaultResolutions,
) + 1e-12,
).eql(5);
done();
})
.catch(function (err) {
Expand Down Expand Up @@ -881,9 +892,12 @@ describe('ol-mapbox-style', function () {
context.sources.osm.minzoom = 8;
apply(target, context)
.then(function (map) {
should(map.getLayers().item(0).getMaxResolution()).eql(
defaultResolutions[8] + 1e-15,
);
should(
getZoomForResolution(
map.getLayers().item(0).getMaxResolution(),
defaultResolutions,
) + 1e-12,
).eql(8);
done();
})
.catch(function (err) {
Expand All @@ -900,9 +914,12 @@ describe('ol-mapbox-style', function () {
};
apply(target, context)
.then(function (map) {
should(map.getLayers().item(0).getMaxResolution()).eql(
defaultResolutions[8] + 1e-15,
);
should(
getZoomForResolution(
map.getLayers().item(0).getMaxResolution(),
defaultResolutions,
) + 1e-12,
).eql(8);
done();
})
.catch(function (err) {
Expand All @@ -913,9 +930,12 @@ 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(
getZoomForResolution(
map.getLayers().item(0).getMaxResolution(),
defaultResolutions,
) + 1e-12,
).eql(7);
should(map.getLayers().item(0).getMinResolution()).eql(
defaultResolutions[23],
);
Expand Down
8 changes: 5 additions & 3 deletions test/applyStyle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import styleMissingSprite from './fixtures/style-missing-sprite.json';

import VectorSource from 'ol/source/Vector.js';
import {apply, applyStyle} from '../src/apply.js';
import {defaultResolutions, getZoomForResolution} from '../src/util.js';
import {get} from 'ol/proj.js';

describe('applyStyle with source creation', function () {
Expand Down Expand Up @@ -353,9 +354,10 @@ describe('maxResolution', function () {
const layer = new VectorTileLayer();
applyStyle(layer, glStyle)
.then(function () {
should(layer.getMaxResolution()).equal(
layer.getSource().getTileGrid().getResolution(6) - 1e-15,
);
should(
getZoomForResolution(layer.getMaxResolution(), defaultResolutions) +
1e-12,
).eql(6);
done();
})
.catch(function (e) {
Expand Down