Skip to content

Commit 6fed90a

Browse files
committed
BGDIINF_SB-2978: Updates according to comments
1 parent d418f5c commit 6fed90a

11 files changed

+93
-92
lines changed

src/config.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ export const TILEGRID_RESOLUTIONS = [
188188
]
189189

190190
/**
191-
* Map view's mininal resolution
192-
* Currently set so that OL scalebar displays 10 meters
193-
* Scalebar about 1" on screen, hence about 100px. So, 10 meters/100px = 0.1
194-
* Caveat: setting resolution (mininum and maximum) has the precedence over zoom (minimum/maximum)
191+
* Map view's mininal resolution Currently set so that OL scalebar displays 10 meters Scalebar about
192+
* 1" on screen, hence about 100px. So, 10 meters/100px = 0.1 Caveat: setting resolution (mininum
193+
* and maximum) has the precedence over zoom (minimum/maximum)
195194
*/
196195

197196
export const VIEW_MIN_RESOLUTION = 0.1 // meters/pixel
@@ -216,14 +215,14 @@ export const TILEGRID_EXTENT = [2420000, 1030000, 2900000, 1350000]
216215
*
217216
* @type {Number[]}
218217
*/
219-
export const LV95_EXTENT = [572215.44, 5684416.96, 1277662.37, 6145307.4]
218+
export const TILEGRID_EXTENT_EPSG_3857 = [572215.44, 5684416.96, 1277662.37, 6145307.4]
220219

221220
/**
222221
* TILEGRID_EXTENT (defined above) reprojected in EPSG:4326 through epsg.io website.
223222
*
224223
* @type {Number[]}
225224
*/
226-
export const WGS84_EXTENT = [5.1402988, 45.3981222, 11.4774363, 48.230617]
225+
export const TILEGRID_EXTENT_EPSG_4326 = [5.1402988, 45.3981222, 11.4774363, 48.230617]
227226

228227
/**
229228
* Map center default value is the center of switzerland LV:95 projection's extent (from

src/modules/map/components/cesium/CesiumWMSLayer.vue

+8-28
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
<script>
88
import { CoordinateSystem, WEBMERCATOR } from '@/utils/coordinateSystems'
99
import { ImageryLayer, Rectangle, WebMapServiceImageryProvider } from 'cesium'
10-
import { WGS84_EXTENT } from '@/config'
10+
import { TILEGRID_EXTENT_EPSG_4326 } from '@/config'
1111
import { mapState } from 'vuex'
1212
import { YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } from '@/api/layers/LayerTimeConfigEntry.class'
1313
import GeoAdminWMSLayer from '@/api/layers/GeoAdminWMSLayer.class'
1414
import addImageryLayerMixins from '@/modules/map/components/cesium/utils/addImageryLayer-mixins'
15+
import { getWMSTimestampFromConfig } from '@/utils/wmsLayerUtils'
1516
1617
// todo should we adapt LOD to resolution?
1718
const MAXIMUM_LEVEL_OF_DETAILS = 18
@@ -20,7 +21,7 @@ export default {
2021
mixins: [addImageryLayerMixins],
2122
props: {
2223
wmsLayerConfig: {
23-
type: [GeoAdminWMSLayer],
24+
type: GeoAdminWMSLayer,
2425
required: true,
2526
},
2627
previewYear: {
@@ -53,35 +54,14 @@ export default {
5354
return this.wmsLayerConfig.format || 'png'
5455
},
5556
url() {
56-
return this.wmsLayerConfig.getURL(this.previewYear, this.projection.epsgNumber)
57+
return this.wmsLayerConfig.getURL()
5758
},
5859
timestamp() {
59-
if (this.wmsLayerConfig.timeConfig) {
60-
// if there is a preview year set, we search for the matching timestamp
61-
if (this.previewYear) {
62-
const matchingTimeEntry = this.wmsLayerConfig.getTimeEntryForYear(
63-
this.previewYear
64-
)
65-
if (matchingTimeEntry) {
66-
return matchingTimeEntry.timestamp
67-
}
68-
}
69-
// if a time entry is defined, and is different from 'all'
70-
// (no need to pass 'all' to our WMS, that's the default timestamp used under the hood)
71-
if (
72-
this.wmsLayerConfig.timeConfig.currentYear !==
73-
YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA
74-
) {
75-
return this.wmsLayerConfig.timeConfig.currentTimestamp
76-
}
77-
}
78-
return ''
60+
return getWMSTimestampFromConfig(this.wmsLayerConfig)
7961
},
8062
/**
81-
* Definition of all relevant URL param for our WMS backends. This is because both
82-
* https://openlayers.org/en/latest/apidoc/module-ol_source_TileWMS-TileWMS.html and
83-
* https://openlayers.org/en/latest/apidoc/module-ol_source_ImageWMS-ImageWMS.html have this
84-
* option.
63+
* Definition of all relevant URL param for our WMS backends. Passes as parameters to
64+
* https://cesium.com/learn/cesiumjs/ref-doc/WebMapServiceImageryProvider.html#.ConstructorOptions
8565
*
8666
* If we let the URL have all the param beforehand (sending all URL param through the url
8767
* option), most of our wanted params will be doubled, resulting in longer and more
@@ -111,7 +91,7 @@ export default {
11191
subdomains: '0123',
11292
layers: this.wmsLayerConfig.geoAdminID,
11393
maximumLevel: MAXIMUM_LEVEL_OF_DETAILS,
114-
rectangle: Rectangle.fromDegrees(...WGS84_EXTENT),
94+
rectangle: Rectangle.fromDegrees(...TILEGRID_EXTENT_EPSG_4326),
11595
}),
11696
{
11797
show: this.wmsLayerConfig.visible,

src/modules/map/components/cesium/CesiumWMTSLayer.vue

+4-11
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import GeoAdminWMTSLayer from '@/api/layers/GeoAdminWMTSLayer.class'
99
import { CoordinateSystem, WEBMERCATOR } from '@/utils/coordinateSystems'
1010
import { ImageryLayer, Rectangle, UrlTemplateImageryProvider } from 'cesium'
11-
import { WGS84_EXTENT } from '@/config'
11+
import { TILEGRID_EXTENT_EPSG_4326 } from '@/config'
1212
import addImageryLayerMixins from './utils/addImageryLayer-mixins'
13+
import { getTimestampForPreviewLayer } from '@/utils/wmtsLayerUtils'
1314
1415
// todo should we adapt LOD to resolution?
1516
const MAXIMUM_LEVEL_OF_DETAILS = 18
@@ -42,15 +43,7 @@ export default {
4243
return this.wmtsLayerConfig.opacity || 1.0
4344
},
4445
timestampForPreviewYear() {
45-
if (
46-
this.previewYear &&
47-
this.wmtsLayerConfig.timeConfig &&
48-
this.wmtsLayerConfig.timeConfig.years.includes(this.previewYear)
49-
) {
50-
return this.wmtsLayerConfig.timeConfig.getTimeEntryForYear(this.previewYear)
51-
.timestamp
52-
}
53-
return null
46+
return getTimestampForPreviewLayer(this.previewYear, this.wmtsLayerConfig)
5447
},
5548
url() {
5649
return this.wmtsLayerConfig.getURL(
@@ -63,7 +56,7 @@ export default {
6356
createImagery(url) {
6457
return new ImageryLayer(
6558
new UrlTemplateImageryProvider({
66-
rectangle: Rectangle.fromDegrees(...WGS84_EXTENT),
59+
rectangle: Rectangle.fromDegrees(...TILEGRID_EXTENT_EPSG_4326),
6760
maximumLevel: MAXIMUM_LEVEL_OF_DETAILS,
6861
url: url,
6962
}),

src/modules/map/components/cesium/utils/addImageryLayer-mixins.js

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Vue mixin that will handle the addition or removal of a Cesium Imagery layer. This is a
3+
* centralized way of describing this logic.
4+
*
5+
* Each component that uses this mixin must create a layer (`this.layer`) in their `created(){}`
6+
* method. This layer will then be added to the viewer (through dependency injection with
7+
* `getViewer`). The mixin will manage this layer and will remove it from the viewer as soon as the
8+
* component that has incorporated this mixin will be removed from the DOM.
9+
*
10+
* It is also set/update zIndex of the layer, which places the layer accordingly in the stack of the
11+
* imagery layers in Cesium viewer.
12+
*/
113
const addImageryLayerMixins = {
214
inject: ['getViewer'],
315
data() {

src/modules/map/components/openlayers/OpenLayersWMSLayer.vue

+3-21
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import TileGrid from 'ol/tilegrid/TileGrid'
1818
import proj4 from 'proj4'
1919
import { mapState } from 'vuex'
2020
import addLayerToMapMixin from './utils/addLayerToMap-mixins'
21+
import { getWMSTimestampFromConfig } from '@/utils/wmsLayerUtils'
2122
2223
/** Renders a WMS layer on the map */
2324
export default {
@@ -60,29 +61,10 @@ export default {
6061
return this.wmsLayerConfig.gutter || -1
6162
},
6263
url() {
63-
return this.wmsLayerConfig.getURL(this.previewYear, this.projection.epsgNumber)
64+
return this.wmsLayerConfig.getURL()
6465
},
6566
timestamp() {
66-
if (this.wmsLayerConfig.timeConfig) {
67-
// if there is a preview year set, we search for the matching timestamp
68-
if (this.previewYear) {
69-
const matchingTimeEntry = this.wmsLayerConfig.getTimeEntryForYear(
70-
this.previewYear
71-
)
72-
if (matchingTimeEntry) {
73-
return matchingTimeEntry.timestamp
74-
}
75-
}
76-
// if a time entry is defined, and is different from 'all'
77-
// (no need to pass 'all' to our WMS, that's the default timestamp used under the hood)
78-
if (
79-
this.wmsLayerConfig.timeConfig.currentYear !==
80-
YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA
81-
) {
82-
return this.wmsLayerConfig.timeConfig.currentTimestamp
83-
}
84-
}
85-
return ''
67+
return getWMSTimestampFromConfig(this.wmsLayerConfig)
8668
},
8769
/**
8870
* Definition of all relevant URL param for our WMS backends. This is because both

src/modules/map/components/openlayers/OpenLayersWMTSLayer.vue

+2-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { XYZ as XYZSource } from 'ol/source'
1414
import TileGrid from 'ol/tilegrid/TileGrid'
1515
import proj4 from 'proj4'
1616
import addLayerToMapMixin from './utils/addLayerToMap-mixins'
17+
import { getTimestampForPreviewLayer } from '@/utils/wmtsLayerUtils'
1718
1819
/** Renders a WMTS layer on the map */
1920
export default {
@@ -44,15 +45,7 @@ export default {
4445
return this.wmtsLayerConfig.opacity || 1.0
4546
},
4647
timestampForPreviewYear() {
47-
if (
48-
this.previewYear &&
49-
this.wmtsLayerConfig.timeConfig &&
50-
this.wmtsLayerConfig.timeConfig.years.includes(this.previewYear)
51-
) {
52-
return this.wmtsLayerConfig.timeConfig.getTimeEntryForYear(this.previewYear)
53-
.timestamp
54-
}
55-
return null
48+
return getTimestampForPreviewLayer(this.previewYear, this.wmtsLayerConfig)
5649
},
5750
url() {
5851
return this.wmtsLayerConfig.getURL(

src/store/modules/position.store.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LV95_EXTENT, MAP_CENTER } from '@/config'
1+
import { TILEGRID_EXTENT_EPSG_3857, MAP_CENTER } from '@/config'
22
import { WEBMERCATOR, WGS84 } from '@/utils/coordinateSystems'
33
import log from '@/utils/logging'
44
import { round } from '@/utils/numberUtils'
@@ -174,10 +174,10 @@ const getters = {
174174
isExtentOnlyWithinLV95Bounds(state, getters) {
175175
const [currentExtentBottomLeft, currentExtentTopRight] = getters.extent
176176
return (
177-
currentExtentBottomLeft[0] >= LV95_EXTENT[0] &&
178-
currentExtentBottomLeft[1] >= LV95_EXTENT[1] &&
179-
currentExtentTopRight[0] <= LV95_EXTENT[2] &&
180-
currentExtentTopRight[1] <= LV95_EXTENT[3]
177+
currentExtentBottomLeft[0] >= TILEGRID_EXTENT_EPSG_3857[0] &&
178+
currentExtentBottomLeft[1] >= TILEGRID_EXTENT_EPSG_3857[1] &&
179+
currentExtentTopRight[0] <= TILEGRID_EXTENT_EPSG_3857[2] &&
180+
currentExtentTopRight[1] <= TILEGRID_EXTENT_EPSG_3857[3]
181181
)
182182
},
183183
}

src/utils/__tests__/coordinateUtils.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LV95_EXTENT } from '@/config'
1+
import { TILEGRID_EXTENT_EPSG_3857 } from '@/config'
22
import {
33
coordinateFromString,
44
reprojectUnknownSrsCoordsToWebMercator,
@@ -504,14 +504,14 @@ describe('Unit test functions from coordinateUtils.js', () => {
504504
// checking that the split happened on the LV95 bounds
505505
const intersectingCoordinate = outOfBoundChunk.coordinates[1]
506506
expect(intersectingCoordinate).to.be.an('Array').of.length(2)
507-
expect(intersectingCoordinate).to.eql([LV95_EXTENT[0], yValue])
507+
expect(intersectingCoordinate).to.eql([TILEGRID_EXTENT_EPSG_3857[0], yValue])
508508
// next chunk must start by the intersecting coordinate
509509
expect(inBoundChunk).to.haveOwnProperty('isWithinLV95Bounds')
510510
expect(inBoundChunk.isWithinLV95Bounds).to.be.true
511511
expect(inBoundChunk.coordinates).to.be.an('Array').of.length(6)
512512
const [firstInBoundCoordinate] = inBoundChunk.coordinates
513513
expect(firstInBoundCoordinate).to.be.an('Array').of.length(2)
514-
expect(firstInBoundCoordinate).to.eql([LV95_EXTENT[0], yValue])
514+
expect(firstInBoundCoordinate).to.eql([TILEGRID_EXTENT_EPSG_3857[0], yValue])
515515
// checking that further coordinates have been correctly copied
516516
coordinatesOverlappingSwissBounds.slice(1).forEach((coordinate, index) => {
517517
expect(inBoundChunk.coordinates[index + 1][0]).to.eq(coordinate[0])
@@ -527,9 +527,9 @@ describe('Unit test functions from coordinateUtils.js', () => {
527527
[700000, 6000000], // inside
528528
[1000000, 6000000], // inside
529529
]
530-
const expectedFirstIntersection = [LV95_EXTENT[0], 6000000]
531-
const expectedSecondIntersection = [800000, LV95_EXTENT[1]]
532-
const expectedThirdIntersection = [700000, LV95_EXTENT[1]]
530+
const expectedFirstIntersection = [TILEGRID_EXTENT_EPSG_3857[0], 6000000]
531+
const expectedSecondIntersection = [800000, TILEGRID_EXTENT_EPSG_3857[1]]
532+
const expectedThirdIntersection = [700000, TILEGRID_EXTENT_EPSG_3857[1]]
533533

534534
const result = splitIfOutOfLV95Bounds(coordinatesGoingBackAndForth)
535535
expect(result).to.be.an('Array').of.length(4)

src/utils/coordinateUtils.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LV95_EXTENT } from '@/config'
1+
import { TILEGRID_EXTENT_EPSG_3857 } from '@/config'
22
import clip from 'liang-barsky'
33
import proj4 from 'proj4'
44
import { LV03, LV95, WEBMERCATOR, WGS84 } from './coordinateSystems'
@@ -77,12 +77,12 @@ const LV95_BOUNDS = {
7777
*/
7878
const LV95_IN_MERCATOR_BOUNDS = {
7979
x: {
80-
lower: LV95_EXTENT[0],
81-
upper: LV95_EXTENT[2],
80+
lower: TILEGRID_EXTENT_EPSG_3857[0],
81+
upper: TILEGRID_EXTENT_EPSG_3857[2],
8282
},
8383
y: {
84-
lower: LV95_EXTENT[1],
85-
upper: LV95_EXTENT[3],
84+
lower: TILEGRID_EXTENT_EPSG_3857[1],
85+
upper: TILEGRID_EXTENT_EPSG_3857[3],
8686
},
8787
}
8888
/**
@@ -468,7 +468,7 @@ function splitIfOutOfLV95BoundsRecurse(coordinates, previousChunks = [], isFirst
468468
clip(
469469
lastCoordinateWithSameBounds,
470470
nextCoordinateWithoutSameBounds,
471-
LV95_EXTENT,
471+
TILEGRID_EXTENT_EPSG_3857,
472472
crossing1,
473473
crossing2
474474
)

src/utils/wmsLayerUtils.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } from '@/api/layers/LayerTimeConfigEntry.class'
2+
3+
/**
4+
* Returns timestamp for WMS layer from config data
5+
*
6+
* @param {GeoAdminWMSLayer} wmsLayerConfig
7+
* @returns {String | string | LayerTimeConfig.currentTimeEntry.timestamp}
8+
*/
9+
export function getWMSTimestampFromConfig(wmsLayerConfig) {
10+
if (wmsLayerConfig.timeConfig) {
11+
// if there is a preview year set, we search for the matching timestamp
12+
if (this.previewYear) {
13+
const matchingTimeEntry = wmsLayerConfig.getTimeEntryForYear(this.previewYear)
14+
if (matchingTimeEntry) {
15+
return matchingTimeEntry.timestamp
16+
}
17+
}
18+
// if a time entry is defined, and is different from 'all'
19+
// (no need to pass 'all' to our WMS, that's the default timestamp used under the hood)
20+
if (wmsLayerConfig.timeConfig.currentYear !== YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA) {
21+
return wmsLayerConfig.timeConfig.currentTimestamp
22+
}
23+
}
24+
return ''
25+
}

src/utils/wmtsLayerUtils.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Returns timestamp of preview year for WMTS layer from config data
3+
*
4+
* @param {Number} previewYear
5+
* @param {GeoAdminWMTSLayer} wmtsLayerConfig
6+
* @returns {String | null}
7+
*/
8+
export function getTimestampForPreviewLayer(previewYear, wmtsLayerConfig) {
9+
if (
10+
previewYear &&
11+
wmtsLayerConfig.timeConfig &&
12+
wmtsLayerConfig.timeConfig.years.includes(previewYear)
13+
) {
14+
return wmtsLayerConfig.timeConfig.getTimeEntryForYear(previewYear).timestamp
15+
}
16+
return null
17+
}

0 commit comments

Comments
 (0)