Skip to content

Commit

Permalink
#9346 ensure the zoom is always round before using it as index (#9357) (
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Sep 14, 2023
1 parent c3bb9d5 commit 71ba634
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion web/client/components/map/cesium/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class CesiumMap extends React.Component {
roll: this.map.camera.roll
}
},
getResolutions()[zoom]
getResolutions()[Math.round(zoom)]
);
};

Expand Down
5 changes: 3 additions & 2 deletions web/client/components/map/leaflet/Layer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ class LeafletLayer extends React.Component {
maxResolution = Infinity,
disableResolutionLimits
} = options || {};
if (!disableResolutionLimits && !isNil(resolutions[zoom])) {
const resolution = resolutions[zoom];
const zoomRound = Math.round(zoom);
if (!disableResolutionLimits && !isNil(resolutions[zoomRound])) {
const resolution = resolutions[zoomRound];
// use similar approach of ol
// maxResolution is exclusive
// minResolution is inclusive
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/map/leaflet/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class LeafletMap extends React.Component {
this.props.id,
this.props.projection,
viewerOptions, // viewerOptions
this.getResolutions()[zoom] // resolution
this.getResolutions()[Math.round(zoom)] // resolution
);
};

Expand Down
2 changes: 1 addition & 1 deletion web/client/utils/MapUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ export function calculateExtent(center = {x: 0, y: 0, crs: "EPSG:3857"}, resolut

export const reprojectZoom = (zoom, mapProjection, printProjection) => {
const multiplier = METERS_PER_UNIT[getUnits(mapProjection)] / METERS_PER_UNIT[getUnits(printProjection)];
const mapResolution = getResolutions(mapProjection)[zoom] * multiplier;
const mapResolution = getResolutions(mapProjection)[Math.round(zoom)] * multiplier;
const printResolutions = getResolutions(printProjection);

const printResolution = printResolutions.reduce((nearest, current) => {
Expand Down
7 changes: 6 additions & 1 deletion web/client/utils/__tests__/MapUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
addRootParentGroup,
mapUpdated,
getZoomFromResolution,
getResolutionObject
getResolutionObject,
reprojectZoom
} from '../MapUtils';
import { VisualizationModes } from '../MapTypeUtils';

Expand Down Expand Up @@ -2132,6 +2133,10 @@ describe('Test the MapUtils', () => {
const resolution = 1000; // ~zoom 7 in Web Mercator
expect(getZoomFromResolution(resolution)).toBe(7);
});
it('reprojectZoom', () => {
expect(reprojectZoom(5, 'EPSG:3857', 'EPSG:4326')).toBe(4);
expect(reprojectZoom(5.2, 'EPSG:3857', 'EPSG:4326')).toBe(4);
});
describe("getResolutionObject tests", () => {
const resolutions = [156543, 78271, 39135, 19567, 9783, 4891, 2445, 1222];
it('getResolutionObject for visibility limit type scale', ()=> {
Expand Down
2 changes: 1 addition & 1 deletion web/client/utils/grids/MapGridsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export function getGridGeoJson({
pixelRatio = devicePixelRatio,
frameSize = 0.0
}) {
const resolution = (resolutions ?? getResolutions(mapProjection))[zoom];
const resolution = (resolutions ?? getResolutions(mapProjection))[Math.round(zoom)];
const mapToGrid = proj4(mapProjection, gridProjection).forward;
const gridToMap = proj4(gridProjection, mapProjection).forward;
const projectionCenter = mapToGrid(getCenter(getProjection(gridProjection).extent));
Expand Down
4 changes: 2 additions & 2 deletions web/client/utils/grids/__tests__/MapGridsUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ describe("getGridGeoJson", () => {
expect(geoJson.features[5].geometry.coordinates).toEqual([[-180, -90], [180, -90]]);
expect(geoJson.features[7].geometry.coordinates).toEqual([[-180, 90], [180, 90]]);
});
it("map and grid in EPSG:4326 and zoom 5, no labels", () => {
it("map and grid in EPSG:4326 and zoom 5.2, no labels", () => {
const geoJson = getGridGeoJson({
mapProjection: "EPSG:4326",
gridProjection: "EPSG:4326",
extent: [5, 40, 10, 44],
zoom: 5
zoom: 5.2
});
expect(geoJson.type).toBe("FeatureCollection");
expect(geoJson.features.length).toBe(7);
Expand Down

0 comments on commit 71ba634

Please sign in to comment.