Skip to content

Commit

Permalink
Merge pull request #937 from geoadmin/bugfix-PB-645-zoom-to-extent-on…
Browse files Browse the repository at this point in the history
…-feature-preselection

PB-645: zoom to extent on feature preselection
  • Loading branch information
ltkum authored Jun 21, 2024
2 parents e8aa05a + 28f7b3d commit 30f838e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/router/storeSync/LayerParamConfig.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async function getAndDispatchFeatures(to, featuresPromise, store) {
if (!query.z) {
await store.dispatch('zoomToExtent', {
extent: extent,
maxZoom: 8,
maxZoom: store.state.position.projection.get1_25000ZoomLevel(),
dispatcher: STORE_DISPATCHER_ROUTER_PLUGIN,
})
} else {
Expand Down
9 changes: 3 additions & 6 deletions src/store/modules/position.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import CoordinateSystem from '@/utils/coordinates/CoordinateSystem.class'
import allCoordinateSystems, { LV95, WGS84 } from '@/utils/coordinates/coordinateSystems'
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
import StandardCoordinateSystem from '@/utils/coordinates/StandardCoordinateSystem.class'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/SwissCoordinateSystem.class.js'
import log from '@/utils/logging'
import { wrapDegrees } from '@/utils/numberUtils.js'

Expand Down Expand Up @@ -266,11 +265,9 @@ const actions = {
targetResolution,
centerOfExtent
)
let computedMaxZoom = maxZoom ?? STANDARD_ZOOM_LEVEL_1_25000_MAP
if (state.projection instanceof CustomCoordinateSystem) {
computedMaxZoom =
state.projection.transformStandardZoomLevelToCustom(computedMaxZoom)
}
// if maxZoom is not set, we set it to the current projection value to
// have a 1:25000 ratio.
const computedMaxZoom = maxZoom ?? state.projection.get1_25000ZoomLevel()
// Zoom levels are fixed value with LV95, the one calculated is the fixed zoom the closest to the floating
// zoom level required to show the full extent on the map (scale to fill).
// So the view will be too zoomed-in to have an overview of the extent.
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/search.store.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import search, { SearchResultTypes } from '@/api/search.api'
import { isWhat3WordsString, retrieveWhat3WordsLocation } from '@/api/what3words.api'
import coordinateFromString from '@/utils/coordinates/coordinateExtractors'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/CoordinateSystem.class'
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/SwissCoordinateSystem.class'
import log from '@/utils/logging'

const state = {
Expand Down
2 changes: 1 addition & 1 deletion src/store/plugins/geolocation-management.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import proj4 from 'proj4'

import { IS_TESTING_WITH_CYPRESS } from '@/config'
import i18n from '@/modules/i18n'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/CoordinateSystem.class'
import { WGS84 } from '@/utils/coordinates/coordinateSystems'
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class.js'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/SwissCoordinateSystem.class.js'
import log from '@/utils/logging'

const dispatcher = { dispatcher: 'geolocation-management.plugin' }
Expand Down
22 changes: 21 additions & 1 deletion src/utils/coordinates/CoordinateSystem.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import proj4 from 'proj4'
import CoordinateSystemBounds from '@/utils/coordinates/CoordinateSystemBounds.class'
import { round } from '@/utils/numberUtils'

/**
* These are the zoom levels, for each projection, which give us a 1:25'000 ratio map.
*
* These variables are declared here, as the config.js import the LV95 coordinate system, and it
* could lead to initialization errors (even when initializing the constants before importing the
* class). Thus we declare them here, at the root class of the coordinates systems.
*
* @type {Number}
*/

export const STANDARD_ZOOM_LEVEL_1_25000_MAP = 15.5
export const SWISS_ZOOM_LEVEL_1_25000_MAP = 8

/**
* Representation of a coordinate system (or also called projection system) in the context of this
* application.
Expand Down Expand Up @@ -90,6 +103,14 @@ export default class CoordinateSystem {
return !!this.bounds?.isInBounds(x, y)
}

/**
* @abstract The Index in the resolution list where the 1:25000 zoom level is
* @returns {Number}
*/
get1_25000ZoomLevel() {
throw new Error('Not yet implemented')
}

/**
* @abstract
* @returns {Number} The default zoom to use when starting the map in this coordinate system (if
Expand Down Expand Up @@ -155,7 +176,6 @@ export default class CoordinateSystem {
roundCoordinateValue(_value) {
throw Error('Not yet implemented')
}

/**
* A (descending) list of all the available resolutions for this coordinate system. If this is
* not the behavior you want, you have to override this function.
Expand Down
11 changes: 10 additions & 1 deletion src/utils/coordinates/StandardCoordinateSystem.class.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CoordinateSystem from '@/utils/coordinates/CoordinateSystem.class'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/SwissCoordinateSystem.class'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/CoordinateSystem.class'

/**
* Equatorial radius of the Earth, in meters
Expand Down Expand Up @@ -39,6 +39,15 @@ export const PIXEL_LENGTH_IN_KM_AT_ZOOM_ZERO_WITH_256PX_TILES = WGS84_EQUATOR_LE
* @see https://wiki.openstreetmap.org/wiki/Zoom_levels
*/
export default class StandardCoordinateSystem extends CoordinateSystem {
/**
* The index in the resolution list where the 1:25000 zoom level is
*
* @returns {Number}
*/
get1_25000ZoomLevel() {
return STANDARD_ZOOM_LEVEL_1_25000_MAP
}

getDefaultZoom() {
return STANDARD_ZOOM_LEVEL_1_25000_MAP
}
Expand Down
23 changes: 14 additions & 9 deletions src/utils/coordinates/SwissCoordinateSystem.class.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {
STANDARD_ZOOM_LEVEL_1_25000_MAP,
SWISS_ZOOM_LEVEL_1_25000_MAP,
} from '@/utils/coordinates/CoordinateSystem.class'
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
import { closest, round } from '@/utils/numberUtils'

/**
* WebMercator zoom level corresponding to the resolution of the 1:25'000 map we provide
*
* @type {Number}
*/
export const STANDARD_ZOOM_LEVEL_1_25000_MAP = 15.5

/**
* Resolutions for each LV95 zoom level, from 0 to 14
*
Expand Down Expand Up @@ -97,6 +93,15 @@ export default class SwissCoordinateSystem extends CustomCoordinateSystem {
return TILEGRID_RESOLUTIONS
}

/**
* The index in the resolution list where the 1:25000 zoom level is
*
* @returns {Number}
*/
get1_25000ZoomLevel() {
return SWISS_ZOOM_LEVEL_1_25000_MAP
}

getDefaultZoom() {
return 1
}
Expand All @@ -117,7 +122,7 @@ export default class SwissCoordinateSystem extends CustomCoordinateSystem {
return 14
}
// if no matching zoom level was found, we return the one for the 1:25'000 map
return 8
return this.get1_25000ZoomLevel()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/tests-e2e/search/coordinates-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import proj4 from 'proj4'

import { DEFAULT_PROJECTION } from '@/config'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/CoordinateSystem.class'
import { LV03, LV95, WEBMERCATOR, WGS84 } from '@/utils/coordinates/coordinateSystems'
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/SwissCoordinateSystem.class'
import { latLonToMGRS } from '@/utils/militaryGridProjection'

const searchbarSelector = '[data-cy="searchbar"]'
Expand Down

0 comments on commit 30f838e

Please sign in to comment.