Skip to content

Commit 736dee2

Browse files
#8334 Review mapType configuration and docs (#9012)
Co-authored-by: Lorenzo Natali <lorenzo.natali@geosolutionsgroup.com>
1 parent c6fad76 commit 736dee2

File tree

7 files changed

+79
-70
lines changed

7 files changed

+79
-70
lines changed

docs/developer-guide/local-config.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,24 @@ This is the main structure:
9999
"leaflet": { ... },
100100
"cesium": { ... }
101101
},
102-
// allow to define which 2D or 3D map library should be used based on the device
102+
// allow to define the default visualization mode of the app and
103+
// which 2D or 3D map library should be used based on the device
103104
// the configuration below is the default one
104-
// structure -> { mapType: { [visualizationMode]: { [deviceType]: mapLibrary } } }
105105
// note: this configuration does not support expressions
106106
"mapType": {
107-
"2D": {
108-
"desktop": "openlayers",
109-
"mobile": "leaflet"
110-
},
111-
"3D": {
112-
"desktop": "cesium",
113-
"mobile": "cesium"
107+
// the default visualization mode of the app, it could be "2D" or "3D"
108+
"defaultVisualizationMode": "2D",
109+
// map library to use based on the visualization mode and device
110+
// structure -> { visualizationModes: { [visualizationMode]: { [deviceType]: mapLibrary } } }
111+
"visualizationModes": {
112+
"2D": {
113+
"desktop": "openlayers",
114+
"mobile": "leaflet"
115+
},
116+
"3D": {
117+
"desktop": "cesium",
118+
"mobile": "cesium"
119+
}
114120
}
115121
},
116122
"plugins": {

docs/developer-guide/map-query-parameters.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The parameters can be passed in a query-string-like section, after the `#<path>?
1313
Example:
1414

1515
```text
16-
#/viewer/openlayers/new?center=0,0&zoom=5
16+
#/viewer/new?center=0,0&zoom=5
1717
```
1818

1919
!!! note
@@ -23,8 +23,8 @@ Example:
2323

2424
Sometimes the request parameters can be too big to be passed in the URL, for instance when dealing with an entire map, or complex data. To overcome this kind of situations, an adhoc `POST` service available at `<mapstore-base-path>/rest/config/setParams` allows to pass the parameters in the request payload `application/x-www-form-urlencoded`.
2525
The parameters will be then passed to the client (using a temporary `queryParams-{random-UUID}` variable in `sessionStorage`).
26-
Near the parameters, an additional `page` value can be passed together with the params to specify to which url be redirect. If no page attribute is specified by default redirection happens to `#/viewer/openlayers/config`.
27-
The UUID used in the `queryParams-{random-UUID}` variable name is being added to the redirect URL in a query parameter named `queryParamsID=`. Assuming to use the default redirect value, the url will then look like the following: `#/viewer/openlayers/config?queryParamsID={random-UUID}`.
26+
Near the parameters, an additional `page` value can be passed together with the params to specify to which url be redirect. If no page attribute is specified by default redirection happens to `#/viewer/config`.
27+
The UUID used in the `queryParams-{random-UUID}` variable name is being added to the redirect URL in a query parameter named `queryParamsID=`. Assuming to use the default redirect value, the url will then look like the following: `#/viewer/config?queryParamsID={random-UUID}`.
2828

2929
Example `application/x-www-form-urlencoded` request payload (URL encoded):
3030

@@ -39,7 +39,7 @@ Here a sample page you can create to test the service:
3939
<script>
4040
const POST_PATH = "rest/config/setParams";
4141
const queryParameters = {
42-
"page": '../../#/viewer/openlayers/config',
42+
"page": '../../#/viewer/config',
4343
"map": {"version":2,"map":{"projection":"EPSG:900913","units":"m","center":{"x":1250000,"y":5370000,"crs":"EPSG:900913"},"zoom":5,"maxExtent":[-20037508.34,-20037508.34,20037508.34,20037508.34],"layers":[{"type":"osm","title":"Open Street Map","name":"mapnik","source":"osm","group":"background","visibility":true}]}},
4444
"featureinfo": '',
4545
"bbox": '',
@@ -121,7 +121,7 @@ Here a sample page you can create to test the service:
121121
<fieldset>
122122
<legend>Params:</legend>
123123
<label for="map">map:</label><br/><textarea id="map" name="map"></textarea><br/>
124-
<label for="page">page:</label><br/><input type="text" id="page" name="page" value="../../#/viewer/openlayers/config"></input><br/>
124+
<label for="page">page:</label><br/><input type="text" id="page" name="page" value="../../#/viewer/config"></input><br/>
125125
<label for="featureinfo">featureinfo:</label><br/><textarea id="featureinfo" name="featureinfo"></textarea><br/>
126126
<label for="bbox">bbox:</label><br/><input type="text" id="bbox" name="bbox"></input><br/>
127127
<label for="center">center:</label><br/><input type="text" id="center" name="center"></input><br/>
@@ -145,13 +145,13 @@ Optional parameter "filterNameList" allows limiting request to the specific laye
145145
It will be effectively used only if it's passed as non-empty array of layer names.
146146
Omitting or passing an empty array will have the same effect.
147147
148-
GET: `#/viewer/openlayers/config?featureinfo={"lat": 43.077, "lng": 12.656, "filterNameList": []}`
148+
GET: `#/viewer/config?featureinfo={"lat": 43.077, "lng": 12.656, "filterNameList": []}`
149149
150-
GET: `#/viewer/openlayers/config?featureinfo={"lat": 43.077, "lng": 12.656, "filterNameList": ["layerName1", "layerName2"]}`
150+
GET: `#/viewer/config?featureinfo={"lat": 43.077, "lng": 12.656, "filterNameList": ["layerName1", "layerName2"]}`
151151
152152
#### Simplified syntax
153153
154-
GET: `#/viewer/openlayers/config?featureInfo=38.72,-95.625`
154+
GET: `#/viewer/config?featureInfo=38.72,-95.625`
155155
156156
Where lon,lat values are comma-separated respecting order.
157157
@@ -162,40 +162,40 @@ Allows to pass the entire map JSON definition (see the map configuration format
162162
GET:
163163
164164
```text
165-
#/viewer/openlayers/config?map={"version":2,"map":{"projection":"EPSG:900913","units":"m","center":{"x":1250000,"y":5370000,"crs":"EPSG:900913"},"zoom":5,"maxExtent":[-20037508.34,-20037508.34,20037508.34,20037508.34],"layers":[{"type":"osm","title":"Open Street Map","name":"mapnik","source":"osm","group":"background","visibility":true}]}}
165+
#/viewer/config?map={"version":2,"map":{"projection":"EPSG:900913","units":"m","center":{"x":1250000,"y":5370000,"crs":"EPSG:900913"},"zoom":5,"maxExtent":[-20037508.34,-20037508.34,20037508.34,20037508.34],"layers":[{"type":"osm","title":"Open Street Map","name":"mapnik","source":"osm","group":"background","visibility":true}]}}
166166
```
167167
168168
It also allows partial overriding of existing map configuration by passing only specific properties of the root object and/or the internal "map" object.
169169
170170
Following example will override "catalogServices" and "mapInfoConfiguration":
171171
172172
```text
173-
#/viewer/openlayers/config?map={"mapInfoConfiguration":{"trigger":"click","infoFormat":"text/html"},"catalogServices":{"services": {"wms": {"url": "http://example.com/geoserver/wms","type": "wms","title": "WMS","autoload": true}},"selectedService": "wms"}}
173+
#/viewer/config?map={"mapInfoConfiguration":{"trigger":"click","infoFormat":"text/html"},"catalogServices":{"services": {"wms": {"url": "http://example.com/geoserver/wms","type": "wms","title": "WMS","autoload": true}},"selectedService": "wms"}}
174174
```
175175
176176
### Center / Zoom
177177
178-
GET: `#/viewer/openlayers/config?center=0,0&zoom=5`
178+
GET: `#/viewer/config?center=0,0&zoom=5`
179179
180180
Where lon,lat values are comma-separated respecting order.
181181
182182
### Marker / Zoom
183183
184-
GET: `#/viewer/openlayers/config?marker=0,0&zoom=5`
184+
GET: `#/viewer/config?marker=0,0&zoom=5`
185185
186186
Where lon,lat values are comma-separated respecting order.
187187
188188
### Bbox
189189
190-
GET: `#/viewer/openlayers/config?bbox=8,8,53,53`
190+
GET: `#/viewer/config?bbox=8,8,53,53`
191191
192192
Where values are `minLongitude, minLatitude, maxLongitude, maxLatitude` respecting order.
193193
194194
### AddLayers
195195
196196
This is a shortened syntax for `CATALOG:ADD_LAYERS_FROM_CATALOGS` action described down below.
197197
198-
GET: `#/viewer/openlayers/config?addLayers=layer1;service,layer2&layerFilters=attributeLayer1='value';attributeLayer2='value2'`
198+
GET: `#/viewer/config?addLayers=layer1;service,layer2&layerFilters=attributeLayer1='value';attributeLayer2='value2'`
199199
200200
`addLayers` parameter is a comma separated list of `<layerName>;<service>` (`service` is optional, and if present is separated
201201
from the layerName by a `;`.
@@ -217,7 +217,7 @@ In this case search execution will be postponed up to the moment when layer is a
217217
If so, it will postpone search to ensure that layer is added to the map. Otherwise, in case of no matches, search will execute
218218
immediately.
219219
220-
GET: `#/viewer/openlayers/new?addLayers=layer1;service&mapinfo=layer1&mapInfoFilter=BB='cc'`
220+
GET: `#/viewer/new?addLayers=layer1;service&mapinfo=layer1&mapInfoFilter=BB='cc'`
221221
222222
Where:
223223
@@ -231,11 +231,11 @@ Allows to dynamically add background to the map and activate it.
231231
Supports default backgrounds provided by static service defined in `localConfig.json` (`default_map_backgrounds`) as well
232232
as other layers:
233233
234-
`#/viewer/openlayers/new?background=Sentinel;default_map_backgrounds`
234+
`#/viewer/new?background=Sentinel;default_map_backgrounds`
235235
236-
`#/viewer/openlayers/new?background=layer1;service`
236+
`#/viewer/new?background=layer1;service`
237237
238-
`#/viewer/openlayers/new?background=layer2`
238+
`#/viewer/new?background=layer2`
239239
240240
Where:
241241
@@ -275,7 +275,7 @@ Example:
275275
}
276276
```
277277
278-
GET: `#/viewer/openlayers/config?actions=[{"type": "ZOOM_TO_EXTENT","extent": [1,2,3,4],"crs": "EPSG:4326","maxZoom": 8}]`
278+
GET: `#/viewer/config?actions=[{"type": "ZOOM_TO_EXTENT","extent": [1,2,3,4],"crs": "EPSG:4326","maxZoom": 8}]`
279279
280280
For more details check out the [zoomToExtent](https://mapstore.geosolutionsgroup.com/mapstore/docs/#actions.map.zoomToExtent) in the framework documentation.
281281
@@ -302,12 +302,12 @@ Example:
302302
}
303303
```
304304
305-
GET: `#/viewer/openlayers/config?actions=[{"type":"SEARCH:SEARCH_WITH_FILTER","cql_filter":"ID=75","layer":"WORKSPACE:LAYER_NAME"}]`
305+
GET: `#/viewer/config?actions=[{"type":"SEARCH:SEARCH_WITH_FILTER","cql_filter":"ID=75","layer":"WORKSPACE:LAYER_NAME"}]`
306306
307307
The sample request below illustrates how two actions can be concatenated:
308308
309309
```text
310-
https://dev-mapstore.geosolutionsgroup.com/mapstore/#/viewer/openlayers/4093?actions=[{"type":"SEARCH:SEARCH_WITH_FILTER","cql_filter":"STATE_FIPS=34","layer":"topp:states"},{"type":"ZOOM_TO_EXTENT","extent":[-77.48202256347649,38.74612266051003,-72.20858506347648,40.66664704515103],"crs":"EPSG:4326","maxZoom":8}]
310+
https://dev-mapstore.geosolutionsgroup.com/mapstore/#/viewer/4093?actions=[{"type":"SEARCH:SEARCH_WITH_FILTER","cql_filter":"STATE_FIPS=34","layer":"topp:states"},{"type":"ZOOM_TO_EXTENT","extent":[-77.48202256347649,38.74612266051003,-72.20858506347648,40.66664704515103],"crs":"EPSG:4326","maxZoom":8}]
311311
```
312312
313313
The MapStore invocation URL above executes the following operations:
@@ -332,7 +332,7 @@ Example:
332332
}
333333
```
334334
335-
GET: `#/viewer/openlayers/config?actions=[{"type":"SEARCH:SCHEDULE_SEARCH_WITH_FILTER","cql_filter":"ID=75","layer":"WORKSPACE:LAYER_NAME"},{"type":"CATALOG:ADD_LAYERS_FROM_CATALOGS","layers":["WORKSPACE:LAYER_NAME"],"sources":["catalog1"]}]`
335+
GET: `#/viewer/config?actions=[{"type":"SEARCH:SCHEDULE_SEARCH_WITH_FILTER","cql_filter":"ID=75","layer":"WORKSPACE:LAYER_NAME"},{"type":"CATALOG:ADD_LAYERS_FROM_CATALOGS","layers":["WORKSPACE:LAYER_NAME"],"sources":["catalog1"]}]`
336336
337337
#### Add Layers
338338
@@ -355,7 +355,7 @@ Example:
355355
}
356356
```
357357
358-
GET: `#/viewer/openlayers/config?actions=[{"type":"CATALOG:ADD_LAYERS_FROM_CATALOGS","layers":["layer1", "layer2", "workspace:externallayername"],"sources":["catalog1", "catalog2", {"type":"WMS","url":"https://example.com/wms"}]}]`
358+
GET: `#/viewer/config?actions=[{"type":"CATALOG:ADD_LAYERS_FROM_CATALOGS","layers":["layer1", "layer2", "workspace:externallayername"],"sources":["catalog1", "catalog2", {"type":"WMS","url":"https://example.com/wms"}]}]`
359359
360360
Data of resulting layer can be additionally filtered by passing "CQL_FILTER" into the options array. Each element of array corresponds to the layer defined in action:
361361
@@ -368,6 +368,6 @@ Data of resulting layer can be additionally filtered by passing "CQL_FILTER" int
368368
}
369369
```
370370
371-
GET `#/viewer/openlayers/config?actions=[{"type":"CATALOG:ADD_LAYERS_FROM_CATALOGS","layers":["layer1","layer2","workspace:externallayername"],"sources":["catalog1","catalog2",{"type":"WMS","url":"https://example.com/wms"}],"options": [{"params":{"CQL_FILTER":"NAME='value'"}}, {}, {"params":{"CQL_FILTER":"NAME='value2'"}}]}]`
371+
GET `#/viewer/config?actions=[{"type":"CATALOG:ADD_LAYERS_FROM_CATALOGS","layers":["layer1","layer2","workspace:externallayername"],"sources":["catalog1","catalog2",{"type":"WMS","url":"https://example.com/wms"}],"options": [{"params":{"CQL_FILTER":"NAME='value'"}}, {}, {"params":{"CQL_FILTER":"NAME='value2'"}}]}]`
372372
373373
Number of objects passed to the options can be different to the number of layers, in this case options will be applied to the first X layers, where X is the length of options array.

docs/developer-guide/mapstore-migration-guide.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This is a list of things to check if you want to update from a previous version
2727
The map configuration stores the information related to the visualization mode 2D or 3D after saving a map.
2828
This update include also following changes:
2929

30-
- `maptype` configuration inside the initialState of localConfig needs to be removed in favor of the global mapType configuration
30+
- `maptype` default state configuration inside the initialState of `localConfig.json` needs to be removed. If a MapStore project needs a particular setup (eg. use only OpenLayers for 2D maps, initialize the app in 3D, ...) it is possible to override the default map libraries configuration with the new `mapType` property in the `localConfig.json` file, see documentation [here](local-config.md#application-configuration).
3131

3232
```diff
3333
{
@@ -49,25 +49,6 @@ This update include also following changes:
4949

5050
- the application does not expose the pathname of the viewer with `mapType` anymore. Example: the old path `/viewer/openlayers/1` becomes `/viewer/1`
5151

52-
- it is possible to change the map library based on the device using the new `mapType` configuration in localConfig.json. This configuration is only needed for project with custom map library settings. The downstream projects based on the MapStore product don't need this update
53-
54-
```diff
55-
{
56-
// ...
57-
+ "mapType": {
58-
+ "2D": {
59-
+ "desktop": "openlayers",
60-
+ "mobile": "leaflet"
61-
+ },
62-
+ "3D": {
63-
+ "desktop": "cesium",
64-
+ "mobile": "cesium"
65-
+ }
66-
+ },
67-
// ...
68-
}
69-
```
70-
7152
- the app pages inside a MapStore project must be updated with a new entry, only for projects with custom pages and that are using context applications, here an example:
7253

7354
```js

web/client/components/map/enhancers/autoMapType.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88

99
import React from 'react';
10-
import { getMapLibraryFromVisualizationMode, VisualizationModes } from '../../../utils/MapTypeUtils';
10+
import { getMapLibraryFromVisualizationMode } from '../../../utils/MapTypeUtils';
1111

1212
const autoMapType = (Component) => props => (
1313
<Component
14-
mapType={getMapLibraryFromVisualizationMode(props?.map?.visualizationMode || VisualizationModes._2D)}
14+
mapType={getMapLibraryFromVisualizationMode(props?.map?.visualizationMode)}
1515
{...props}
1616
/>
1717
);

web/client/reducers/maptype.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import { MAP_PLUGIN_LOAD } from '../actions/map';
1111
import { MAP_CONFIG_LOADED } from '../actions/config';
1212

1313
import {
14-
getMapLibraryFromVisualizationMode,
15-
VisualizationModes
14+
getMapLibraryFromVisualizationMode
1615
} from '../utils/MapTypeUtils';
1716

1817
/**
@@ -27,11 +26,11 @@ import {
2726
* }
2827
*/
2928
function maptype(state = {
30-
mapType: getMapLibraryFromVisualizationMode(VisualizationModes._2D)
29+
mapType: getMapLibraryFromVisualizationMode()
3130
}, action) {
3231
switch (action.type) {
3332
case MAP_CONFIG_LOADED:
34-
const visualizationMode = action?.config?.map?.visualizationMode || VisualizationModes._2D;
33+
const visualizationMode = action?.config?.map?.visualizationMode;
3534
return {
3635
...state,
3736
mapType: getMapLibraryFromVisualizationMode(visualizationMode)

web/client/utils/MapTypeUtils.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const mapLibrariesConfiguration = {
2424
}
2525
};
2626

27-
const DEFAULT_MAP_TYPE_CONFIG = {
27+
const DEFAULT_VISUALIZATION_MODES_CONFIG = {
2828
[VisualizationModes._2D]: {
2929
mobile: MapLibraries.LEAFLET,
3030
desktop: MapLibraries.OPENLAYERS
@@ -35,6 +35,12 @@ const DEFAULT_MAP_TYPE_CONFIG = {
3535
}
3636
};
3737

38+
const getDefaultVisualizationMode = () => {
39+
const customMapTypeConfig = getConfigProp('mapType') || {};
40+
const { defaultVisualizationMode = VisualizationModes._2D } = customMapTypeConfig;
41+
return defaultVisualizationMode;
42+
};
43+
3844
/**
3945
* Check if a map configuration is in 3D mode
4046
* @param {object} map map configuration
@@ -48,7 +54,7 @@ export const is3DVisualizationMode = (map) => map?.visualizationMode === Visuali
4854
* @returns {string} "2D" or "3D" value
4955
*/
5056
export const getVisualizationModeFromMapLibrary = (mapLibrary) => {
51-
const { visualizationMode = VisualizationModes._2D } = mapLibrariesConfiguration[mapLibrary] || {};
57+
const { visualizationMode = getDefaultVisualizationMode() } = mapLibrariesConfiguration[mapLibrary] || {};
5258
return visualizationMode;
5359
};
5460

@@ -57,12 +63,13 @@ export const getVisualizationModeFromMapLibrary = (mapLibrary) => {
5763
* @param {string} visualizationMode the name of the visualization mode, one of "2D" or "3D"
5864
* @returns {string} leaflet", "openlayers" or "cesium" value
5965
*/
60-
export const getMapLibraryFromVisualizationMode = (visualizationMode = VisualizationModes._2D) => {
66+
export const getMapLibraryFromVisualizationMode = (visualizationMode = getDefaultVisualizationMode()) => {
6167
const { mobile } = getBrowserProperties();
6268
const customMapTypeConfig = getConfigProp('mapType') || {};
69+
const { visualizationModes = {} } = customMapTypeConfig;
6370
const config = {
64-
...DEFAULT_MAP_TYPE_CONFIG[visualizationMode],
65-
...customMapTypeConfig[visualizationMode]
71+
...DEFAULT_VISUALIZATION_MODES_CONFIG[visualizationMode],
72+
...visualizationModes[visualizationMode]
6673
};
6774
const device = mobile ? 'mobile' : 'desktop';
6875
return config[device];

web/client/utils/__tests__/MapTypeUtils-test.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ import {
1212
replaceMapType,
1313
removeMapType,
1414
getVisualizationModeFromMapLibrary,
15-
getMapLibraryFromVisualizationMode
15+
getMapLibraryFromVisualizationMode,
16+
VisualizationModes,
17+
MapLibraries
1618
} from '../MapTypeUtils';
1719

20+
import { setConfigProp } from '../ConfigUtils';
21+
1822
const testHashes = [
1923
["/viewer/openlayers/1234", "openlayers"],
2024
["/viewer/openlayers/new", "openlayers"],
@@ -123,12 +127,24 @@ describe('MapTypeUtils', () => {
123127
});
124128
});
125129
it('testing getVisualizationModeFromMapLibrary', () => {
126-
expect(getVisualizationModeFromMapLibrary('leaflet')).toBe('2D');
127-
expect(getVisualizationModeFromMapLibrary('openlayers')).toBe('2D');
128-
expect(getVisualizationModeFromMapLibrary('cesium')).toBe('3D');
130+
expect(getVisualizationModeFromMapLibrary()).toBe(VisualizationModes._2D);
131+
expect(getVisualizationModeFromMapLibrary(MapLibraries.LEAFLET)).toBe(VisualizationModes._2D);
132+
expect(getVisualizationModeFromMapLibrary(MapLibraries.OPENLAYERS)).toBe(VisualizationModes._2D);
133+
expect(getVisualizationModeFromMapLibrary(MapLibraries.CESIUM)).toBe(VisualizationModes._3D);
134+
setConfigProp('mapType', {
135+
defaultVisualizationMode: VisualizationModes._3D
136+
});
137+
expect(getVisualizationModeFromMapLibrary()).toBe(VisualizationModes._3D);
138+
setConfigProp('mapType', undefined);
129139
});
130140
it('testing getMapLibraryFromVisualizationMode (default)', () => {
131-
expect(getMapLibraryFromVisualizationMode('2D')).toBe('openlayers');
132-
expect(getMapLibraryFromVisualizationMode('3D')).toBe('cesium');
141+
expect(getMapLibraryFromVisualizationMode()).toBe(MapLibraries.OPENLAYERS);
142+
expect(getMapLibraryFromVisualizationMode(VisualizationModes._2D)).toBe(MapLibraries.OPENLAYERS);
143+
expect(getMapLibraryFromVisualizationMode(VisualizationModes._3D)).toBe(MapLibraries.CESIUM);
144+
setConfigProp('mapType', {
145+
defaultVisualizationMode: VisualizationModes._3D
146+
});
147+
expect(getMapLibraryFromVisualizationMode()).toBe(MapLibraries.CESIUM);
148+
setConfigProp('mapType', undefined);
133149
});
134150
});

0 commit comments

Comments
 (0)