1- <script setup lang="js ">
1+ <script setup lang="ts ">
22import log from ' @swissgeo/log'
33import { getPointResolution } from ' ol/proj'
4- import { computed , onBeforeUnmount , onMounted , ref , watch } from ' vue'
4+ import { computed , onBeforeUnmount , onMounted , ref , watch , type ComputedRef } from ' vue'
55import { useI18n } from ' vue-i18n'
66import { useRoute } from ' vue-router'
7- import { useStore } from ' vuex'
87
98import { getGenerateQRCodeUrl } from ' @/api/qrcode.api'
109import { createShortLink } from ' @/api/shortlink.api'
10+
1111import {
1212 PRINT_DEFAULT_DPI ,
1313 PRINT_DIMENSIONS ,
1414 PRINT_MARGIN_IN_MILLIMETERS ,
1515} from ' @/config/print.config'
16+
1617import InfoboxModule from ' @/modules/infobox/InfoboxModule.vue'
1718import MapFooter from ' @/modules/map/components/footer/MapFooter.vue'
1819import OpenLayersPrintResolutionEnforcer from ' @/modules/map/components/openlayers/OpenLayersPrintResolutionEnforcer.vue'
1920import OpenLayersScale from ' @/modules/map/components/openlayers/OpenLayersScale.vue'
2021import MapModule from ' @/modules/map/MapModule.vue'
2122import ConfederationFullLogo from ' @/modules/menu/components/header/ConfederationFullLogo.vue'
2223import { stringifyQuery } from ' @/utils/url-router.js'
24+ import usePositionStore from ' @/store/modules/position.store'
25+ import { useI18nStore } from ' @/store/modules/i18n.store'
26+ import usePrintStore from ' @/store/modules/print.store'
27+ import useMapStore from ' @/store/modules/map.store'
2328
24- const dispatcher = { dispatcher : ' PrintView.vue' }
29+ const dispatcher = { name : ' PrintView.vue' }
2530
2631const route = useRoute ()
27- const store = useStore ()
2832const { t } = useI18n ()
2933
34+ const printStore = usePrintStore ()
35+ const positionStore = usePositionStore ()
36+ const i18nStore = useI18nStore ()
37+ const mapStore = useMapStore ()
38+
3039const inchToMillimeter = 25.4
3140
32- const shortLink = ref ( null )
33- const qrCodeUrl = computed (() => getGenerateQRCodeUrl (shortLink .value ))
41+ const shortLink = ref < string >( )
42+ const qrCodeUrl = computed (() => shortLink . value && getGenerateQRCodeUrl (shortLink .value ))
3443
3544const now = new Date ()
3645
37- const printLayout = computed (() => store .state .print .config .layout ?? ' A4_L' )
46+ const printLayout = computed (() => printStore .config .layout ?? ' A4_L' )
47+
3848const isLayerLandscape = computed (() => printLayout .value .endsWith (' _L' ))
39- const printDPI = computed (() => store .state .print .config .dpi ?? PRINT_DEFAULT_DPI )
40- const layoutIdentifier = computed (() => printLayout .value .replace (' _L' , ' ' ).replace (' _P' , ' ' ))
41- const layoutDimensions = computed (() => {
49+ const printDPI = computed (() => printStore .config .dpi ?? PRINT_DEFAULT_DPI )
50+
51+ const layoutIdentifier: ComputedRef <keyof typeof PRINT_DIMENSIONS > = computed (
52+ () => printLayout .value .replace (' _L' , ' ' ).replace (' _P' , ' ' ) as keyof typeof PRINT_DIMENSIONS
53+ )
54+
55+ const layoutDimensions: ComputedRef <typeof PRINT_DIMENSIONS .A0 | null > = computed (() => {
56+ if (! layoutIdentifier .value ) {
57+ return null
58+ }
4259 const dimensions = PRINT_DIMENSIONS [layoutIdentifier .value ]
60+
4361 if (! isLayerLandscape .value ) {
4462 return dimensions .toReversed ()
4563 }
4664 return dimensions
4765})
48- const mapResolution = computed (() => store .getters .resolution )
49- const mapRotation = computed (() => store .state .position .rotation )
50- const currentProjection = computed (() => store .state .position .projection )
51- const mapCenter = computed (() => store .state .position .center )
52- const currentLang = computed (() => store .state .i18n .lang )
66+
67+ const mapResolution = computed (() => positionStore .resolution )
68+ const mapRotation = computed (() => positionStore .rotation )
69+ const currentProjection = computed (() => positionStore .projection )
70+ const mapCenter = computed (() => positionStore .center )
71+ const currentLang = computed (() => i18nStore .lang )
5372const printContainerSize = computed (() => {
54- if (! layoutDimensions .value ) {
73+ if (! layoutDimensions .value || layoutDimensions . value . length == 0 ) {
5574 return null
5675 }
5776 return {
@@ -71,14 +90,14 @@ const printContainerStyle = computed(() => {
7190})
7291const mapScaleWidth = computed (() => {
7392 if (! printContainerSize .value ) {
74- return null
93+ return undefined
7594 }
7695 // max 10% of screen width or 200px
7796 return Math .min (printContainerSize .value .width * 0.1 , 200 )
7897})
7998const northArrowStyle = computed (() => {
8099 if (mapRotation .value === 0 ) {
81- return 0
100+ return {}
82101 }
83102 return {
84103 transform: ` rotate(${mapRotation .value }rad) ` ,
@@ -95,10 +114,12 @@ const matchingResolutionStepWithLabel = computed(() =>
95114 }
96115 // checking if map resolution is between the two steps
97116 const previousStep = otherResolution [index - 1 ]
98- return (
99- previousStep .resolution > mapResolution .value &&
100- mapResolution .value > res .resolution
101- )
117+ if (previousStep ) {
118+ return (
119+ previousStep .resolution > mapResolution .value &&
120+ mapResolution .value > res .resolution
121+ )
122+ }
102123 })
103124)
104125
@@ -114,13 +135,13 @@ const printResolution = computed(
114135
115136onMounted (() => {
116137 log .info (` Print map view mounted ` )
117- store . dispatch ( ' setPrintMode' , { mode : true , ... dispatcher } )
138+ mapStore . setPrintMode ( true , dispatcher )
118139
119- generateShareLink ()
140+ generateShareLink (). catch (( _ ) => {})
120141})
121142
122143onBeforeUnmount (() => {
123- store . dispatch ( ' setPrintMode' , { mode : false , ... dispatcher } )
144+ mapStore . setPrintMode ( false , dispatcher )
124145})
125146
126147watch (() => route .query , generateShareLink )
@@ -131,8 +152,7 @@ async function generateShareLink() {
131152 ` ${location .origin }/#/map?${stringifyQuery (route .query )} `
132153 )
133154 } catch (error ) {
134- log .error (` Failed to create shortlink` , error)
135- shortLink .value = null
155+ log .error ({ messages: ` Failed to create shortlink ` , error })
136156 }
137157}
138158 </script >
@@ -160,7 +180,7 @@ async function generateShareLink() {
160180 >
161181 <div class =" scale d-flex justify-content-center m-1 mb-3" >
162182 <OpenLayersScale
163- v- if = " mapScaleWidth > 0"
183+ v-if =" mapScaleWidth && mapScaleWidth > 0"
164184 scale-type =" bar"
165185 :min-width =" mapScaleWidth"
166186 with-relative-size
0 commit comments