Skip to content

Commit dd4d3e5

Browse files
authored
Merge pull request #658 from geoadmin/feat-PB-111-send-print-request
PB-111: Send print request
2 parents c7f62c6 + d02e2d5 commit dd4d3e5

File tree

9 files changed

+391
-29
lines changed

9 files changed

+391
-29
lines changed

package-lock.json

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@fortawesome/free-solid-svg-icons": "^6.5.1",
3939
"@fortawesome/vue-fontawesome": "^3.0.6",
4040
"@geoblocks/cesium-compass": "^0.5.0",
41+
"@geoblocks/mapfishprint": "^0.2.7",
4142
"@geoblocks/ol-maplibre-layer": "^0.1.3",
4243
"@ivanv/vue-collapse-transition": "^1.0.2",
4344
"@mapbox/togeojson": "^0.16.2",

src/api/qrcode.api.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ import axios from 'axios'
33
import { API_SERVICES_BASE_URL } from '@/config'
44
import log from '@/utils/logging'
55

6+
/**
7+
* Generates a URL to generate a QR Code for a URL
8+
*
9+
* @param {String} url The URL we want to QR-Codify
10+
* @returns {String} The URL to generate the QR Code
11+
*/
12+
export function getGenerateQRCodeUrl(url) {
13+
const encodedUrl = encodeURIComponent(url)
14+
return `${API_SERVICES_BASE_URL}qrcode/generate?url=${encodedUrl}`
15+
}
16+
617
/**
718
* Generates a QR Code that, when scanned by mobile devices, open the URL given in parameters
819
*
@@ -20,10 +31,7 @@ export const generateQrCode = (url) => {
2031
reject(errorMessage)
2132
}
2233
axios
23-
.get(`${API_SERVICES_BASE_URL}qrcode/generate`, {
24-
params: {
25-
url: url,
26-
},
34+
.get(getGenerateQRCodeUrl(url), {
2735
responseType: 'arraybuffer',
2836
})
2937
.then((image) => {

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

+62-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<script setup>
22
import { Tile as TileLayer } from 'ol/layer'
3-
import { XYZ as XYZSource } from 'ol/source'
4-
import TileGrid from 'ol/tilegrid/TileGrid'
3+
import { WMTS as WMTSSource } from 'ol/source'
4+
import WMTSTileGrid from 'ol/tilegrid/WMTS'
55
import { computed, inject, toRefs, watch } from 'vue'
66
import { useStore } from 'vuex'
77
88
import GeoAdminWMTSLayer from '@/api/layers/GeoAdminWMTSLayer.class'
99
import useAddLayerToMap from '@/modules/map/components/openlayers/utils/add-layers-to-map.composable'
10-
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
1110
import { getTimestampFromConfig } from '@/utils/layerUtils'
1211
1312
const props = defineProps({
@@ -44,43 +43,88 @@ const url = computed(() => {
4443
const layer = new TileLayer({
4544
id: layerId.value,
4645
opacity: opacity.value,
47-
source: createXYZSourceForProjection(),
46+
source: createWMTSSourceForProjection(),
4847
})
4948
5049
// grabbing the map from the main OpenLayersMap component and use the composable that adds this layer to the map
5150
const olMap = inject('olMap', null)
5251
useAddLayerToMap(layer, olMap, zIndex)
5352
5453
// reacting to changes accordingly
55-
watch(url, (newUrl) => layer.getSource().setUrl(newUrl))
54+
watch(url, (newUrl) => {
55+
layer.getSource().setUrl(getWMTSUrl(newUrl))
56+
})
5657
watch(opacity, (newOpacity) => layer.setOpacity(newOpacity))
57-
watch(projection, () => layer.setSource(createXYZSourceForProjection()))
58+
watch(projection, () => layer.setSource(createWMTSSourceForProjection()))
59+
60+
function getWMTSUrl(xyzUrl) {
61+
return xyzUrl
62+
.replace('{z}', '{TileMatrix}')
63+
.replace('{x}', '{TileCol}')
64+
.replace('{y}', '{TileRow}')
65+
}
5866
5967
/**
60-
* Returns an OpenLayers XYZ source, with some customization depending on the projection being used.
68+
* Returns an OpenLayers WMTS source, with some customization depending on the projection being
69+
* used.
6170
*
6271
* If the projection is a CustomCoordinateSystem, it will set the extent of this projection to a
6372
* dedicated TileGrid object, meaning that tiles outside the extent won't be requested.
6473
*
6574
* If the projection is not a CustomCoordinateSystem, it will default to a worldwide coverage,
6675
* meaning no limit where tiles shouldn't be requested.
6776
*
68-
* @returns {XYZ}
77+
* @returns {WMTSSource}
6978
*/
70-
function createXYZSourceForProjection() {
71-
let tileGrid = null
72-
if (projection.value instanceof CustomCoordinateSystem) {
73-
tileGrid = new TileGrid({
74-
resolutions: projection.value.getResolutions(),
75-
extent: projection.value.bounds.flatten,
76-
origin: projection.value.getTileOrigin(),
77-
})
79+
function createWMTSSourceForProjection() {
80+
const resolutions = projection.value.getResolutions()
81+
const origin = projection.value.getTileOrigin()
82+
const extent = projection.value.bounds.flatten
83+
const matrixIds = projection.value.getMatrixIds()
84+
85+
const tileGrid = new WMTSTileGrid({
86+
resolutions: resolutions,
87+
origin: origin,
88+
matrixIds: matrixIds,
89+
extent: extent,
90+
})
91+
let timestamp = getTimestampFromConfig(wmtsLayerConfig.value, previewYear.value)
92+
// Use "current" as the default timestamp if not defined in the layer config or
93+
timestamp = timestamp || wmtsLayerConfig.value.timeConfig.currentTimestamp || 'current'
94+
95+
// NOTE(IS): The following code is taken from the old geoadmin
96+
// For some obscure reasons, on iOS, displaying a base 64 image
97+
// in a tile with an existing crossOrigin attribute generates
98+
// CORS errors.
99+
// Currently crossOrigin definition is only used for mouse cursor
100+
// detection on desktop in TooltipDirective.
101+
let crossOrigin = 'anonymous'
102+
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
103+
crossOrigin = undefined
78104
}
79-
return new XYZSource({
105+
const wmtsSource = new WMTSSource({
106+
dimensions: {
107+
Time: timestamp,
108+
},
109+
110+
// Workaround: Set a cache size of zero when layer is
111+
// timeEnabled see:
112+
// https://github.com/geoadmin/mf-geoadmin3/issues/3491
113+
cacheSize: wmtsLayerConfig.value.timeEnabled ? 0 : 2048,
114+
layer: layerId.value,
115+
format: wmtsLayerConfig.value.format,
80116
projection: projection.value.epsg,
81-
url: url.value,
117+
requestEncoding: 'REST',
82118
tileGrid,
119+
// tileLoadFunction: tileLoadFunction,
120+
url: getWMTSUrl(url.value),
121+
crossOrigin: crossOrigin,
122+
transition: 0,
123+
style: 'default',
124+
matrixSet: projection.value.epsg,
125+
attributions: wmtsLayerConfig.value.attribution,
83126
})
127+
return wmtsSource
84128
}
85129
</script>
86130

0 commit comments

Comments
 (0)