Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 62154e9

Browse filesBrowse files
authored
1 parent 3442eda commit 62154e9
Copy full SHA for 62154e9

10 files changed

+75-31Lines changed: 75 additions & 31 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎web/client/actions/config.js‎

Copy file name to clipboardExpand all lines: web/client/actions/config.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ const MAP_SAVED = 'MAP:MAP_SAVED';
2222
* Configure the viewer to display the map
2323
* @param {object} conf map config
2424
* @param {number} mapId map resource id
25-
* @param {boolean} zoomToMaxExtent if true, trigger zooming to map's max extent instead of the zoom value specified in the config
25+
* @param {boolean} zoomToExtent if provided, zooms to this extent after the map is configured
2626
*/
27-
function configureMap(conf, mapId, zoomToMaxExtent) {
27+
function configureMap(conf, mapId, zoomToExtent) {
2828
return {
2929
type: MAP_CONFIG_LOADED,
3030
config: conf,
3131
legacy: !!mapId,
3232
mapId: mapId,
33-
zoomToMaxExtent
33+
zoomToExtent
3434
};
3535
}
3636

Collapse file

‎web/client/components/import/dragZone/enhancers/useFiles.js‎

Copy file name to clipboardExpand all lines: web/client/components/import/dragZone/enhancers/useFiles.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = compose(
1616
zoom: map.map.zoom || zoom,
1717
center: map.map.center || center
1818
}
19-
}, null, map.map.zoom === undefined);
19+
}, null, !map.map.zoom && (map.map.bbox || {bounds: map.map.maxExtent}));
2020
}
2121
if (layers.length > 0) {
2222
setLayers(layers, warnings); // TODO: warnings
Collapse file

‎web/client/components/map/openlayers/Map.jsx‎

Copy file name to clipboardExpand all lines: web/client/components/map/openlayers/Map.jsx
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class OpenlayersMap extends React.Component {
590590
this.props.hookRegister.registerHook(mapUtils.GET_COORDINATES_FROM_PIXEL_HOOK, (pixel) => {
591591
return this.map.getCoordinateFromPixel(pixel);
592592
});
593-
this.props.hookRegister.registerHook(mapUtils.ZOOM_TO_EXTENT_HOOK, (extent, { padding, crs, maxZoom: zoomLevel, duration } = {}) => {
593+
this.props.hookRegister.registerHook(mapUtils.ZOOM_TO_EXTENT_HOOK, (extent, { padding, crs, maxZoom: zoomLevel, duration} = {}) => {
594594
let bounds = CoordinatesUtils.reprojectBbox(extent, crs, this.props.projection);
595595
// if EPSG:4326 with max extent (-180, -90, 180, 90) bounds are 0,0,0,0. In this case zoom to max extent
596596
// TODO: improve this to manage all degenerated bounding boxes.
@@ -602,7 +602,9 @@ class OpenlayersMap extends React.Component {
602602
if (bounds && bounds[0] === bounds[2] && bounds[1] === bounds[3] && isNil(maxZoom)) {
603603
maxZoom = 21; // TODO: allow to this maxZoom to be customizable
604604
}
605+
605606
this.map.getView().fit(bounds, {
607+
size: this.map.getSize(),
606608
padding: padding && [padding.top || 0, padding.right || 0, padding.bottom || 0, padding.left || 0],
607609
maxZoom,
608610
duration
Collapse file

‎web/client/epics/config.js‎

Copy file name to clipboardExpand all lines: web/client/epics/config.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export const loadMapConfigAndConfigureMap = (action$, store) =>
7575

7676
export const zoomToMaxExtentOnConfigureMap = action$ =>
7777
action$.ofType(MAP_CONFIG_LOADED)
78-
.filter(({zoomToMaxExtent}) => zoomToMaxExtent)
78+
.filter(action => !!action.zoomToExtent)
7979
.delay(300) // without the delay the map zoom will not change
80-
.map(({config}) => zoomToExtent(get(config, 'map.maxExtent'), get(config, 'map.projection')));
80+
.map(({config, zoomToExtent: extent}) => zoomToExtent(extent.bounds, extent.crs || get(config, 'map.projection')));
8181

8282
export const loadMapInfoEpic = action$ =>
8383
action$.ofType(LOAD_MAP_INFO)
Collapse file

‎web/client/epics/mapexport.js‎

Copy file name to clipboardExpand all lines: web/client/epics/mapexport.js
+19-9Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,29 @@ function MapExportError(title, message) {
3131
this.message = message;
3232
}
3333

34-
const saveMap = state => MapUtils.saveMapConfiguration(
35-
mapSelector(state),
36-
layersSelector(state),
37-
groupsSelector(state),
38-
backgroundListSelector(state),
39-
textSearchConfigSelector(state),
40-
mapOptionsToSaveSelector(state)
41-
);
34+
const saveMap = (state, addBbox = false) => {
35+
const savedConfig = MapUtils.saveMapConfiguration(
36+
mapSelector(state),
37+
layersSelector(state),
38+
groupsSelector(state),
39+
backgroundListSelector(state),
40+
textSearchConfigSelector(state),
41+
mapOptionsToSaveSelector(state)
42+
);
43+
44+
return addBbox ? {
45+
...savedConfig,
46+
map: {
47+
...savedConfig.map,
48+
bbox: mapSelector(state).bbox
49+
}
50+
} : savedConfig;
51+
};
4252

4353
const PersistMap = {
4454
mapstore2: (state) => Rx.Observable.of([JSON.stringify(saveMap(state)), 'map.json', 'application/json']),
4555
wmc: (state) => {
46-
const config = saveMap(state);
56+
const config = saveMap(state, true);
4757
const layers = get(config, 'map.layers', []).filter(layer => !!layer.url && layer.type === 'wms');
4858

4959
if (layers.length === 0) {
Collapse file

‎web/client/epics/maptemplates.js‎

Copy file name to clipboardExpand all lines: web/client/epics/maptemplates.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { error as showError } from '../actions/notifications';
1515
import { isLoggedIn } from '../selectors/security';
1616
import { setTemplates, setMapTemplatesLoaded, setTemplateData, setTemplateLoading, CLEAR_MAP_TEMPLATES, OPEN_MAP_TEMPLATES_PANEL,
1717
MERGE_TEMPLATE, REPLACE_TEMPLATE } from '../actions/maptemplates';
18-
import { zoomToExtent } from '../actions/map';
1918
import { templatesSelector, mapTemplatesLoadedSelector } from '../selectors/maptemplates';
2019
import { templatesSelector as contextTemplatesSelector } from '../selectors/context';
2120
import { mapSelector } from '../selectors/map';
@@ -156,8 +155,7 @@ export const replaceTemplateEpic = (action$, store) => action$
156155
zoom: config.map.zoom || zoom,
157156
center: config.map.center || center
158157
}
159-
}), null),
160-
...(config.map.zoom === undefined ? [zoomToExtent(config.map.maxExtent, config.map.projection)] : [])
158+
}), null, !config.map.zoom && (config.map.bbox || config.map.maxExtent))
161159
] : []))))
162160
.let(wrapStartStop(
163161
setTemplateLoading(id, true),
Collapse file

‎web/client/test-resources/wmc/context.wmc‎

Copy file name to clipboardExpand all lines: web/client/test-resources/wmc/context.wmc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<ms:Group id="groupid1.groupid2" title="Group2" expanded="false"/>
2323
<ms:Group id="groupid3" title="Group3" expanded="true"/>
2424
</ms:GroupList>
25+
<ms:center xmlns:ms="http://geo-solutions.it/mapstore/context" x="1.5" y="2.5" crs="EPSG:3857"/>
26+
<ms:zoom xmlns:ms="http://geo-solutions.it/mapstore/context">7</ms:zoom>
2527
</Extension>
2628
</General>
2729
<LayerList>
Collapse file

‎web/client/test-resources/wmc/exported-context.wmc‎

Copy file name to clipboardExpand all lines: web/client/test-resources/wmc/exported-context.wmc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<ms:Group id="37b5eb60-5189-11ea-8531-a737d86e9a07" title="Some Group" expanded="true"/>
1212
<ms:Group id="37b5eb60-5189-11ea-8531-a737d86e9a07.44bc9340-5189-11ea-8531-a737d86e9a07" title="Some Group" expanded="true"/>
1313
</ms:GroupList>
14+
<ms:center x="-83.01860427856452" y="36.23686543982026" crs="EPSG:4326"/>
15+
<ms:zoom>3</ms:zoom>
1416
</Extension>
1517
</General>
1618
<LayerList>
Collapse file

‎web/client/utils/ogc/WMC/index.js‎

Copy file name to clipboardExpand all lines: web/client/utils/ogc/WMC/index.js
+40-10Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { Parser } from 'xml2js';
10-
import { keys, values, get, head, isArray, mapValues, uniqWith, findIndex, pick } from 'lodash';
10+
import { keys, values, get, head, isArray, mapValues, uniqWith, findIndex, pick, has } from 'lodash';
1111
import uuidv1 from 'uuid/v1';
1212

1313
import {
@@ -84,6 +84,7 @@ const parseBoolean = (string = '') => {
8484
const removeEmptyProps = (obj) => keys(obj).filter(key => obj[key] !== undefined).reduce((result, key) => ({...result, [key]: obj[key]}), {});
8585

8686
const isValidMaxExtentObject = (obj) => !!(obj && obj.minx && obj.miny && obj.maxx && obj.maxy);
87+
const isValidBboxObject = (obj) => !!(obj && isValidMaxExtentObject(obj.bounds) && obj.crs);
8788

8889
/**
8990
* Generates MapStore map configuration object from a WMC string.
@@ -135,18 +136,28 @@ export const toMapConfig = (wmcString, generateLayersGroup = false) => {
135136
const globalExtensions = rootTagExtractor(general, 'Extension');
136137

137138
const maxExtentExtension = olTagExtractor(globalExtensions, 'maxExtent');
138-
const bbox = rootTagExtractor(general, 'BoundingBox');
139+
const bboxTag = rootTagExtractor(general, 'BoundingBox');
139140

140141
// if we have maxExtent in Extension then use that otherwise use bbox information
141142
const maxExtentObj = mapValues(
142143
maxExtentExtension && pickAttributeValues(maxExtentExtension, 'minx', 'miny', 'maxx', 'maxy') ||
143-
pickAttributeValues(bbox, 'minx', 'miny', 'maxx', 'maxy'),
144+
pickAttributeValues(bboxTag, 'minx', 'miny', 'maxx', 'maxy'),
144145
parseFloat
145146
);
146147
const maxExtent = isValidMaxExtentObject(maxExtentObj) &&
147148
[maxExtentObj.minx, maxExtentObj.miny, maxExtentObj.maxx, maxExtentObj.maxy] ||
148149
defaultValues.maxExtent;
149-
const projection = attrExtractor(bbox, 'SRS') || defaultValues.projection; // from bbox or default
150+
const projection = attrExtractor(bboxTag, 'SRS') || defaultValues.projection; // from bbox or default
151+
152+
// extract bbox
153+
const bboxObj = {
154+
bounds: mapValues(
155+
pickAttributeValues(bboxTag, 'minx', 'miny', 'maxx', 'maxy'),
156+
parseFloat
157+
),
158+
crs: attrExtractor(bboxTag, 'SRS')
159+
};
160+
const bbox = isValidBboxObject(bboxObj) ? bboxObj : undefined;
150161

151162
const layerGroup = generateLayersGroup ? uuidv1() : undefined;
152163

@@ -257,14 +268,24 @@ export const toMapConfig = (wmcString, generateLayersGroup = false) => {
257268
title: viewContextTitle || layerGroup
258269
}] : [])];
259270

271+
const msCenter = msTagExtractor(globalExtensions, 'center');
272+
const center = {
273+
...mapValues(pickAttributeValues(msCenter, 'x', 'y'), parseFloat),
274+
crs: attrExtractor(msCenter, 'crs')
275+
};
276+
const zoom = parseFloat(get(msTagExtractor(globalExtensions, 'zoom'), 'charContent'));
277+
260278
const msMapConfig = {
261279
catalogServices: {},
262280
map: {
263281
maxExtent,
282+
bbox: zoom ? undefined : bbox,
264283
projection,
265284
backgrounds: [],
266285
groups,
267-
layers
286+
layers,
287+
center: has(center, 'x', 'y', 'crs') ? center : undefined,
288+
zoom
268289
},
269290
version: 2
270291
};
@@ -315,10 +336,10 @@ export const toWMC = (
315336
attributes: makeSimpleXlink(href)
316337
});
317338

318-
const {maxExtent, projection, layers, groups} = map;
339+
const {maxExtent, bbox, projection, layers, groups, center, zoom} = map;
319340

320-
const makeMaxExtentFromBbox = bbox => {
321-
const reprojectedBbox = reprojectBbox(bbox.bounds, bbox.crs, projection);
341+
const makeMaxExtentFromBbox = bboxObj => {
342+
const reprojectedBbox = reprojectBbox(bboxObj.bounds, bboxObj.crs, projection);
322343
return {
323344
name: 'maxExtent',
324345
attributes: objectToAttributes({
@@ -350,7 +371,13 @@ export const toWMC = (
350371
expanded: group.expanded
351372
})
352373
}))
353-
} : null], namespaces.ms);
374+
} : null, center && {
375+
name: 'center',
376+
attributes: objectToAttributes(center)
377+
}, zoom && {
378+
name: 'zoom',
379+
textContent: zoom.toString()
380+
}], namespaces.ms);
354381

355382
const layerList = {
356383
name: 'LayerList',
@@ -513,7 +540,10 @@ export const toWMC = (
513540
textContent: abstract
514541
}, {
515542
name: 'BoundingBox',
516-
attributes: objectToAttributes({
543+
attributes: objectToAttributes(isValidBboxObject(bbox) ? {
544+
...bbox.bounds,
545+
SRS: bbox.crs
546+
} : {
517547
minx: maxExtent[0],
518548
miny: maxExtent[1],
519549
maxx: maxExtent[2],
Collapse file

‎web/client/utils/ogc/__tests__/WMC-test.js‎

Copy file name to clipboardExpand all lines: web/client/utils/ogc/__tests__/WMC-test.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ describe('WMC tests', () => {
2222
expect(config.map.maxExtent).toEqual([-1, 1, -1, 1]);
2323
expect(config.map.projection).toBe('EPSG:3857');
2424
expect(config.map.backgrounds).toEqual([]);
25-
expect(config.map.center).toNotExist();
26-
expect(config.map.zoom).toNotExist();
25+
expect(config.map.center).toEqual({x: 1.5, y: 2.5, crs: "EPSG:3857"});
26+
expect(config.map.zoom).toBe(7);
2727
expect(config.map.groups).toExist();
2828
expect(config.map.groups.length).toBe(4);
2929
expect(config.map.groups[0].id).toBe('Default');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.