@@ -43,99 +43,124 @@ const handleLegacyKmlAdminIdParam = async (legacyParams, newQuery) => {
43
43
return newQuery
44
44
}
45
45
46
+ const handleLegacyParam = (
47
+ param ,
48
+ legacyValue ,
49
+ store ,
50
+ newQuery ,
51
+ latlongCoordinates ,
52
+ legacyCoordinates
53
+ ) => {
54
+ const { projection } = store . state . position
55
+ let newValue
56
+
57
+ let key = param
58
+ switch ( param ) {
59
+ case 'zoom' :
60
+ // the legacy viewer always expresses its zoom level in the LV95 context (so in SwissCoordinateSystem)
61
+ if ( ! ( projection instanceof SwissCoordinateSystem ) ) {
62
+ newValue = LV95 . transformCustomZoomLevelToStandard ( legacyValue )
63
+ if ( projection instanceof CustomCoordinateSystem ) {
64
+ newValue = projection . transformStandardZoomLevelToCustom ( newValue )
65
+ }
66
+ } else {
67
+ newValue = legacyValue
68
+ }
69
+ key = 'z'
70
+ break
71
+
72
+ // storing coordinate parts for later conversion
73
+ case 'E' :
74
+ case 'X' :
75
+ legacyCoordinates [ 0 ] = Number ( legacyValue )
76
+ break
77
+ case 'N' :
78
+ case 'Y' :
79
+ legacyCoordinates [ 1 ] = Number ( legacyValue )
80
+ break
81
+
82
+ case 'lon' :
83
+ latlongCoordinates [ 0 ] = Number ( legacyValue )
84
+ break
85
+ case 'lat' :
86
+ latlongCoordinates [ 1 ] = Number ( legacyValue )
87
+ break
88
+
89
+ // taking all layers related param aside so that they can be processed later (see below)
90
+ // this only occurs if the syntax is recognized as a mf-geoadmin3 syntax (or legacy)
91
+ case 'layers' :
92
+ if ( isLayersUrlParamLegacy ( legacyValue ) ) {
93
+ // for legacy layers param, we need to give the whole search query
94
+ // as it needs to look for layers, layers_visibility, layers_opacity and
95
+ // layers_timestamp param altogether
96
+ const layers = getLayersFromLegacyUrlParams (
97
+ store . state . layers . config ,
98
+ window . location . search
99
+ )
100
+ newValue = layers . map ( ( layer ) => transformLayerIntoUrlString ( layer ) ) . join ( ';' )
101
+ log . debug ( 'Importing legacy layers as' , newValue )
102
+ } else {
103
+ // if not legacy, we let it go as it is
104
+ newValue = legacyValue
105
+ }
106
+ break
107
+ case 'layers_opacity' :
108
+ case 'layers_visibility' :
109
+ case 'layers_timestamp' :
110
+ // we ignore those params as they are now obsolete
111
+ // see adr/2021_03_16_url_param_structure.md
112
+ break
113
+
114
+ // if no special work to do, we just copy past legacy params to the new viewer
115
+
116
+ default :
117
+ newValue = legacyValue
118
+ }
119
+
120
+ if ( newValue ) {
121
+ // When receiving a query, the application will encode the URI components
122
+ // We decode those so that the new query won't encode encoded character
123
+ // for example, we avoid having " " becoming %2520 in the URI
124
+ newQuery [ key ] = decodeURIComponent ( newValue )
125
+ }
126
+ }
127
+
46
128
const handleLegacyParams = ( legacyParams , store , to , next ) => {
47
129
log . info ( `Legacy permalink with param=` , legacyParams )
48
130
// if so, we transfer all old param (stored before vue-router's /#) and transfer them to the MapView
49
131
// we will also transform legacy zoom level here (see comment below)
50
132
const newQuery = { ...to . query }
51
133
const { projection } = store . state . position
52
134
let legacyCoordinates = [ ]
53
- let legacyCoordinatesAreExpressedInWGS84 = false
135
+ let latlongCoordinates = [ ]
136
+
54
137
Object . keys ( legacyParams ) . forEach ( ( param ) => {
55
- let value
56
-
57
- let key = param
58
- switch ( param ) {
59
- case 'zoom' :
60
- // the legacy viewer always expresses its zoom level in the LV95 context (so in SwissCoordinateSystem)
61
- if ( ! ( projection instanceof SwissCoordinateSystem ) ) {
62
- value = LV95 . transformCustomZoomLevelToStandard ( legacyParams [ param ] )
63
- if ( projection instanceof CustomCoordinateSystem ) {
64
- value = projection . transformStandardZoomLevelToCustom ( value )
65
- }
66
- } else {
67
- value = legacyParams [ param ]
68
- }
69
- key = 'z'
70
- break
71
-
72
- // storing coordinate parts for later conversion
73
- case 'E' :
74
- case 'X' :
75
- case 'lon' :
76
- legacyCoordinates [ 0 ] = Number ( legacyParams [ param ] )
77
- break
78
- case 'N' :
79
- case 'Y' :
80
- case 'lat' :
81
- legacyCoordinates [ 1 ] = Number ( legacyParams [ param ] )
82
- break
83
-
84
- case 'lon' :
85
- case 'lat' :
86
- legacyCoordinatesAreExpressedInWGS84 = true
87
- break
88
-
89
- // taking all layers related param aside so that they can be processed later (see below)
90
- // this only occurs if the syntax is recognized as a mf-geoadmin3 syntax (or legacy)
91
- case 'layers' :
92
- if ( isLayersUrlParamLegacy ( legacyParams [ param ] ) ) {
93
- // for legacy layers param, we need to give the whole search query
94
- // as it needs to look for layers, layers_visibility, layers_opacity and
95
- // layers_timestamp param altogether
96
- const layers = getLayersFromLegacyUrlParams (
97
- store . state . layers . config ,
98
- window . location . search
99
- )
100
- value = layers . map ( ( layer ) => transformLayerIntoUrlString ( layer ) ) . join ( ';' )
101
- log . debug ( 'Importing legacy layers as' , value )
102
- } else {
103
- // if not legacy, we let it go as it is
104
- value = legacyParams [ param ]
105
- }
106
- break
107
- case 'layers_opacity' :
108
- case 'layers_visibility' :
109
- case 'layers_timestamp' :
110
- // we ignore those params as they are now obsolete
111
- // see adr/2021_03_16_url_param_structure.md
112
- break
113
-
114
- // if no special work to do, we just copy past legacy params to the new viewer
115
-
116
- default :
117
- value = legacyParams [ param ]
118
- }
138
+ handleLegacyParam (
139
+ param ,
140
+ legacyParams [ param ] ,
141
+ store ,
142
+ newQuery ,
143
+ latlongCoordinates ,
144
+ legacyCoordinates
145
+ )
146
+ } )
119
147
120
- // if a legacy coordinate (x/y, N/E or lon/lat) was used, we need to build the center param from them
121
- if ( legacyCoordinates . length === 2 && legacyCoordinates [ 0 ] && legacyCoordinates [ 1 ] ) {
122
- // if lon/lat were used, we need to re-project them in the current projection system
123
- if ( legacyCoordinatesAreExpressedInWGS84 ) {
124
- legacyCoordinates = proj4 ( WGS84 . epsg , projection . epsg , legacyCoordinates )
125
- } else if ( projection . epsg !== LV95 . epsg ) {
126
- // if the current projection is not LV95, we also need to re-project x/y or N/E
127
- // (the legacy viewer was always writing coordinates in LV95 in the URL)
128
- legacyCoordinates = proj4 ( LV95 . epsg , projection . epsg , legacyCoordinates )
129
- }
130
- newQuery [ 'center' ] = legacyCoordinates . join ( ',' )
148
+ // Convert legacies coordinates if needed
149
+ if ( latlongCoordinates . length === 2 ) {
150
+ legacyCoordinates = proj4 ( WGS84 . epsg , projection . epsg , latlongCoordinates )
151
+ } else if ( legacyCoordinates . length === 2 ) {
152
+ if ( projection . epsg !== LV95 . epsg ) {
153
+ // if the current projection is not LV95, we also need to re-project x/y or N/E
154
+ // (the legacy viewer was always writing coordinates in LV95 in the URL)
155
+ legacyCoordinates = proj4 ( LV95 . epsg , projection . epsg , legacyCoordinates )
131
156
}
132
- if ( value ) {
133
- // When receiving a query, the application will encode the URI components
134
- // We decode those so that the new query won't encode encoded character
135
- // for example, we avoid having " " becoming %2520 in the URI
136
- newQuery [ key ] = decodeURIComponent ( value )
137
- }
138
- } )
157
+ }
158
+
159
+ // if a legacy coordinate (x/y, N/E or lon/lat) was used, we need to build the
160
+ // center param from them
161
+ if ( legacyCoordinates . length === 2 ) {
162
+ newQuery [ 'center' ] = legacyCoordinates . join ( ',' )
163
+ }
139
164
140
165
// removing old query part (new ones will be added by vue-router after the /# part of the URL)
141
166
const urlWithoutQueryParam = window . location . href . substr ( 0 , window . location . href . indexOf ( '?' ) )
0 commit comments