Skip to content

Commit 14dcc55

Browse files
committed
BGDIINF_SB-2978: Updates according to comments
1 parent 518e4c7 commit 14dcc55

File tree

8 files changed

+46
-53
lines changed

8 files changed

+46
-53
lines changed

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import { CoordinateSystem, WEBMERCATOR } from '@/utils/coordinateSystems'
99
import { ImageryLayer, Rectangle, WebMapServiceImageryProvider } from 'cesium'
1010
import { TILEGRID_EXTENT_EPSG_4326 } from '@/config'
1111
import { mapState } from 'vuex'
12-
import { YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } from '@/api/layers/LayerTimeConfigEntry.class'
1312
import GeoAdminWMSLayer from '@/api/layers/GeoAdminWMSLayer.class'
1413
import addImageryLayerMixins from '@/modules/map/components/cesium/utils/addImageryLayer-mixins'
15-
import { getWMSTimestampFromConfig } from '@/utils/wmsLayerUtils'
1614
17-
// todo should we adapt LOD to resolution?
15+
import { getTimestampFromConfig } from '@/utils/layerUtils'
16+
1817
const MAXIMUM_LEVEL_OF_DETAILS = 18
1918
2019
export default {
@@ -57,7 +56,7 @@ export default {
5756
return this.wmsLayerConfig.getURL()
5857
},
5958
timestamp() {
60-
return getWMSTimestampFromConfig(this.wmsLayerConfig)
59+
return getTimestampFromConfig(this.wmsLayerConfig, this.previewYear)
6160
},
6261
/**
6362
* Definition of all relevant URL param for our WMS backends. Passes as parameters to

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { CoordinateSystem, WEBMERCATOR } from '@/utils/coordinateSystems'
1010
import { ImageryLayer, Rectangle, UrlTemplateImageryProvider } from 'cesium'
1111
import { TILEGRID_EXTENT_EPSG_4326 } from '@/config'
1212
import addImageryLayerMixins from './utils/addImageryLayer-mixins'
13-
import { getTimestampForPreviewLayer } from '@/utils/wmtsLayerUtils'
1413
15-
// todo should we adapt LOD to resolution?
14+
import { getTimestampFromConfig } from '@/utils/layerUtils'
15+
1616
const MAXIMUM_LEVEL_OF_DETAILS = 18
1717
1818
export default {
@@ -43,7 +43,7 @@ export default {
4343
return this.wmtsLayerConfig.opacity || 1.0
4444
},
4545
timestampForPreviewYear() {
46-
return getTimestampForPreviewLayer(this.previewYear, this.wmtsLayerConfig)
46+
return getTimestampFromConfig(this.wmtsLayerConfig, this.previewYear)
4747
},
4848
url() {
4949
return this.wmtsLayerConfig.getURL(

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

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
* `getViewer`). The mixin will manage this layer and will remove it from the viewer as soon as the
88
* component that has incorporated this mixin will be removed from the DOM.
99
*
10+
* `url` should be defined in the component and contains layer URL
11+
*
12+
* Component that will use this mixin should have `createImagery` method which takes layer URL as a
13+
* parameter
14+
*
1015
* It is also set/update zIndex of the layer, which places the layer accordingly in the stack of the
1116
* imagery layers in Cesium viewer.
1217
*/

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ 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'
21+
22+
import { getTimestampFromConfig } from '@/utils/layerUtils'
2223
2324
/** Renders a WMS layer on the map */
2425
export default {
@@ -64,7 +65,7 @@ export default {
6465
return this.wmsLayerConfig.getURL()
6566
},
6667
timestamp() {
67-
return getWMSTimestampFromConfig(this.wmsLayerConfig)
68+
return getTimestampFromConfig(this.wmsLayerConfig, this.previewYear)
6869
},
6970
/**
7071
* Definition of all relevant URL param for our WMS backends. This is because both

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ 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'
17+
18+
import { getTimestampFromConfig } from '@/utils/layerUtils'
1819
1920
/** Renders a WMTS layer on the map */
2021
export default {
@@ -45,7 +46,7 @@ export default {
4546
return this.wmtsLayerConfig.opacity || 1.0
4647
},
4748
timestampForPreviewYear() {
48-
return getTimestampForPreviewLayer(this.previewYear, this.wmtsLayerConfig)
49+
return getTimestampFromConfig(this.wmtsLayerConfig, this.previewYear)
4950
},
5051
url() {
5152
return this.wmtsLayerConfig.getURL(

src/utils/layerUtils.js

+29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } from '@/api/layers/LayerTimeConfigEntry.class'
2+
import GeoAdminWMTSLayer from '@/api/layers/GeoAdminWMTSLayer.class'
3+
14
export class ActiveLayerConfig {
25
/**
36
* @param {String} id The layer id
@@ -13,3 +16,29 @@ export class ActiveLayerConfig {
1316
this.customAttributes = customAttributes
1417
}
1518
}
19+
20+
/**
21+
* Returns timestamp for WMS or WMTS layer from config data
22+
*
23+
* @param {GeoAdminWMSLayer | GeoAdminWMTSLayer} config
24+
* @param {Number} previewYear
25+
* @returns {String | string | LayerTimeConfig.currentTimeEntry.timestamp}
26+
*/
27+
export function getTimestampFromConfig(config, previewYear) {
28+
const isWMTS = config instanceof GeoAdminWMTSLayer
29+
if (config.timeConfig) {
30+
// if there is a preview year set, we search for the matching timestamp
31+
if (previewYear && config.timeConfig.years.includes(previewYear) && isWMTS) {
32+
const matchingTimeEntry = config.timeConfig.getTimeEntryForYear(previewYear)
33+
if (matchingTimeEntry || isWMTS) {
34+
return matchingTimeEntry.timestamp
35+
}
36+
}
37+
// if a time entry is defined, and is different from 'all'
38+
// (no need to pass 'all' to our WMS, that's the default timestamp used under the hood)
39+
if (config.timeConfig.currentYear !== YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA && !isWMTS) {
40+
return config.timeConfig.currentTimestamp
41+
}
42+
}
43+
return isWMTS ? null : ''
44+
}

src/utils/wmsLayerUtils.js

-25
This file was deleted.

src/utils/wmtsLayerUtils.js

-17
This file was deleted.

0 commit comments

Comments
 (0)