Skip to content

Commit 1fb07d0

Browse files
dsuren1offtherailz
andauthored
#12553: Fix - WMC export fails when maxExtent is undefined (#12554)
* 12553: Fix - WMC export fails when maxExtent is undefined * updated unit tests * Apply suggestion from @offtherailz --------- Co-authored-by: Lorenzo Natali <lorenzo.natali@geosolutionsgroup.com>
1 parent 603e57b commit 1fb07d0

3 files changed

Lines changed: 224 additions & 21 deletions

File tree

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ViewContext xmlns="http://www.opengis.net/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ol="http://openlayers.org/context" xmlns:ms="http://geo-solutions.it/mapstore/context" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd">
3+
<General>
4+
<Title>MapStore Context</Title>
5+
<Abstract>This is a map exported from MapStore2.</Abstract>
6+
<BoundingBox minx="-447353.25587372016" miny="3817753.15151658" maxx="4562023.82912628" maxy="6138992.826157694" SRS="EPSG:900913"/>
7+
<Extension>
8+
<ol:maxExtent minx="-447353.25587372016" miny="3817753.15151658" maxx="4562023.82912628" maxy="6138992.826157694"/>
9+
<ms:GroupList>
10+
<ms:Group id="Default" title="Default" expanded="true"/>
11+
<ms:Group id="37b5eb60-5189-11ea-8531-a737d86e9a07" title="Some Group" expanded="true"/>
12+
<ms:Group id="37b5eb60-5189-11ea-8531-a737d86e9a07.44bc9340-5189-11ea-8531-a737d86e9a07" title="Some Group" expanded="true"/>
13+
</ms:GroupList>
14+
<ms:CatalogServices selectedService="gs_stable_csw">
15+
<ms:Service serviceName="gs_stable_csw">
16+
<ms:Attribute name="url" type="string">https://gs-stable.geo-solutions.it/geoserver/csw</ms:Attribute>
17+
<ms:Attribute name="type" type="string">csw</ms:Attribute>
18+
<ms:Attribute name="title" type="string">GeoSolutions GeoServer CSW</ms:Attribute>
19+
<ms:Attribute name="autoload" type="boolean">true</ms:Attribute>
20+
<ms:Attribute name="jsObject" type="object">{"parameter1":"value&lt;>","parameter2":1,"parameter3":{"parameter4":2},"parameter6":null}</ms:Attribute>
21+
</ms:Service>
22+
<ms:Service serviceName="gs_stable_wms">
23+
<ms:Attribute name="url" type="string">https://gs-stable.geo-solutions.it/geoserver/wms</ms:Attribute>
24+
<ms:Attribute name="type" type="string">wms</ms:Attribute>
25+
<ms:Attribute name="title" type="string">GeoSolutions GeoServer WMS</ms:Attribute>
26+
<ms:Attribute name="autoload" type="boolean">false</ms:Attribute>
27+
</ms:Service>
28+
<ms:Service serviceName="gs_stable_wmts">
29+
<ms:Attribute name="url" type="string">https://gs-stable.geo-solutions.it/geoserver/gwc/service/wmts</ms:Attribute>
30+
<ms:Attribute name="type" type="string">wmts</ms:Attribute>
31+
<ms:Attribute name="title" type="string">GeoSolutions GeoServer WMTS</ms:Attribute>
32+
<ms:Attribute name="autoload" type="boolean">false</ms:Attribute>
33+
</ms:Service>
34+
</ms:CatalogServices>
35+
<ms:center x="-83.01860427856452" y="36.23686543982026" crs="EPSG:4326"/>
36+
<ms:zoom>3</ms:zoom>
37+
</Extension>
38+
</General>
39+
<LayerList>
40+
<Layer queryable="0" hidden="1">
41+
<Name>s2cloudless:s2cloudless</Name>
42+
<Title>Sentinel 2 Cloudless</Title>
43+
<Server service="OGC:WMS" version="1.3.0">
44+
<OnlineResource xlink:type="simple" xlink:href="https://1maps.geo-solutions.it/geoserver/wms"/>
45+
</Server>
46+
<FormatList>
47+
<Format current="1">image/jpeg</Format>
48+
</FormatList>
49+
<Extension>
50+
<ol:singleTile>false</ol:singleTile>
51+
<ol:transparent>true</ol:transparent>
52+
<ol:isBaseLayer>true</ol:isBaseLayer>
53+
<ol:opacity>1</ol:opacity>
54+
<ms:group>background</ms:group>
55+
</Extension>
56+
</Layer>
57+
<Layer queryable="0" hidden="0">
58+
<Name>gs:ETOPO_Shadow</Name>
59+
<Title>ETOPO Shadow</Title>
60+
<Server service="OGC:WMS" version="1.3.0">
61+
<OnlineResource xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wms"/>
62+
</Server>
63+
<StyleList>
64+
<Style>
65+
<Name>stylename</Name>
66+
<Title>A boring default style</Title>
67+
</Style>
68+
</StyleList>
69+
<Extension>
70+
<ol:maxExtent minx="-20037508.34" miny="-20037508.34" maxx="20037508.34" maxy="20037508.34"/>
71+
<ol:singleTile>false</ol:singleTile>
72+
<ol:transparent>true</ol:transparent>
73+
<ol:isBaseLayer>false</ol:isBaseLayer>
74+
<ol:opacity>1</ol:opacity>
75+
<ms:group>37b5eb60-5189-11ea-8531-a737d86e9a07.44bc9340-5189-11ea-8531-a737d86e9a07</ms:group>
76+
</Extension>
77+
</Layer>
78+
<Layer queryable="0" hidden="0">
79+
<Name>mapstore:Meteorite_Landings_from_NASA_Open_Data_Portal</Name>
80+
<Title>Meteorite Landings from NASA Open Data Portal</Title>
81+
<Server service="OGC:WMS" version="1.3.0">
82+
<OnlineResource xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wms"/>
83+
</Server>
84+
<DimensionList>
85+
<Dimension name="time" units="ISO8601" default="2101-01-01T00:00:00Z">1583-01-01T00:00:00.000Z/2101-01-01T00:00:00.000Z/PT1S</Dimension>
86+
</DimensionList>
87+
<StyleList>
88+
<Style>
89+
<Name>mapstore:meteorites</Name>
90+
<Title>Meteorite</Title>
91+
</Style>
92+
</StyleList>
93+
<Extension>
94+
<ol:maxExtent minx="-20037508.34" miny="-20037508.34" maxx="20037508.34" maxy="20037508.34"/>
95+
<ol:singleTile>true</ol:singleTile>
96+
<ol:transparent>true</ol:transparent>
97+
<ol:isBaseLayer>false</ol:isBaseLayer>
98+
<ol:opacity>1</ol:opacity>
99+
<ms:group>37b5eb60-5189-11ea-8531-a737d86e9a07</ms:group>
100+
<ms:search type="wfs" xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wfs"/>
101+
<ms:DimensionList>
102+
<ms:Dimension name="time" type="multidim-extension" xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/gwc/service/wmts"/>
103+
</ms:DimensionList>
104+
</Extension>
105+
</Layer>
106+
<Layer queryable="0" hidden="0">
107+
<Name>mapstore:states</Name>
108+
<Title>states</Title>
109+
<Server service="OGC:WMS" version="1.3.0">
110+
<OnlineResource xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wms"/>
111+
</Server>
112+
<FormatList>
113+
<Format current="1">image/png</Format>
114+
</FormatList>
115+
<Extension>
116+
<ol:maxExtent minx="-13917188.693592682" miny="2855355.382299433" maxx="-7422899.184910233" maxy="6359070.895688462"/>
117+
<ol:singleTile>false</ol:singleTile>
118+
<ol:transparent>true</ol:transparent>
119+
<ol:isBaseLayer>false</ol:isBaseLayer>
120+
<ol:opacity>1</ol:opacity>
121+
<ms:group>37b5eb60-5189-11ea-8531-a737d86e9a07</ms:group>
122+
<ms:search type="wfs" xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wfs"/>
123+
<ms:filter>{"searchUrl":null,"featureTypeConfigUrl":null,"showGeneratedFilter":false,"attributePanelExpanded":true,"spatialPanelExpanded":true,"crossLayerExpanded":true,"showDetailsPanel":false,"groupLevels":5,"useMapProjection":false,"toolbarEnabled":true,"groupFields":[{"id":1,"logic":"OR","index":0}],"maxFeaturesWPS":5,"filterFields":[{"rowId":1581959068162,"groupId":1,"attribute":"land_km","operator":">","value":100000,"type":"number","fieldOptions":{"valuesCount":0,"currentPage":1},"exception":null}],"spatialField":{"method":"Circle","operation":"INTERSECTS","geometry":{"id":"8c6ea070-51a7-11ea-82fe-2bce7d4e64fe","type":"Polygon","extent":[-10247583.345629543,3521681.013624397,-7950544.348505222,5818720.010748717],"center":[-9099063.847067382,4670200.512186557],"coordinates":[[[-7950544.348505222,4670200.512186557],[-7952810.689381311,4742316.6481908215],[-7959600.767797531,4814148.174753006],[-7970887.786416465,4885411.605654472],[-7986627.200532176,4955825.696690616],[-8006756.893867798,5025112.555613257],[-8031197.42372012,5092998.738844383],[-8059852.334483632,5159216.330633026],[-8092608.538316733,5223504.000396337],[-8129336.761447779,5285608.034072003],[-8169892.054359602,5345283.3354117405],[-8214114.363839028,5402294.393264214],[-8261829.164633797,5456416.211029952],[-8312848.148223987,5507435.194620143],[-8366969.965989726,5555149.995414911],[-8423981.023842199,5599372.304894337],[-8483656.325181935,5639927.59780616],[-8545760.358857602,5676655.820937207],[-8610048.028620914,5709412.024770307],[-8676265.620409556,5738066.935533819],[-8744151.803640682,5762507.465386141],[-8813438.662563324,5782637.158721764],[-8883852.753599467,5798376.572837473],[-8955116.184500933,5809663.591456408],[-9026947.711063117,5816453.6698726285],[-9099063.847067382,5818720.010748717],[-9171179.983071648,5816453.6698726285],[-9243011.509633832,5809663.591456409],[-9314274.940535298,5798376.572837474],[-9384689.031571442,5782637.158721764],[-9453975.890494082,5762507.465386141],[-9521862.073725209,5738066.935533819],[-9588079.66551385,5709412.024770306],[-9652367.335277162,5676655.820937206],[-9714471.36895283,5639927.59780616],[-9774146.670292566,5599372.304894337],[-9831157.728145039,5555149.995414911],[-9885279.545910778,5507435.194620143],[-9936298.529500967,5456416.211029952],[-9984013.330295736,5402294.393264214],[-10028235.639775163,5345283.335411741],[-10068790.932686985,5285608.034072004],[-10105519.155818032,5223504.000396337],[-10138275.359651132,5159216.330633027],[-10166930.270414643,5092998.7388443835],[-10191370.800266966,5025112.555613258],[-10211500.493602589,4955825.696690617],[-10227239.907718299,4885411.605654472],[-10238526.926337233,4814148.174753007],[-10245317.004753454,4742316.6481908215],[-10247583.345629543,4670200.512186557],[-10245317.004753454,4598084.376182293],[-10238526.926337233,4526252.8496201085],[-10227239.907718299,4454989.418718642],[-10211500.493602589,4384575.327682498],[-10191370.800266966,4315288.468759857],[-10166930.270414643,4247402.2855287315],[-10138275.359651132,4181184.6937400885],[-10105519.155818032,4116897.0239767767],[-10068790.932686985,4054792.990301111],[-10028235.639775163,3995117.6889613736],[-9984013.330295736,3938106.6311089005],[-9936298.529500969,3883984.813343162],[-9885279.545910778,3832965.8297529714],[-9831157.728145039,3785251.0289582037],[-9774146.670292566,3741028.7194787767],[-9714471.368952828,3700473.426566954],[-9652367.335277162,3663745.2034359076],[-9588079.66551385,3630988.9996028068],[-9521862.073725209,3602334.0888392953],[-9453975.890494082,3577893.5589869726],[-9384689.03157144,3557763.8656513495],[-9314274.940535298,3542024.4515356408],[-9243011.509633832,3530737.432916706],[-9171179.983071646,3523947.3545004856],[-9099063.847067382,3521681.013624397],[-9026947.711063119,3523947.3545004856],[-8955116.184500933,3530737.4329167055],[-8883852.753599469,3542024.4515356408],[-8813438.662563322,3557763.86565135],[-8744151.803640682,3577893.5589869726],[-8676265.620409558,3602334.0888392953],[-8610048.028620914,3630988.9996028068],[-8545760.358857602,3663745.203435908],[-8483656.325181935,3700473.4265669542],[-8423981.023842199,3741028.7194787767],[-8366969.965989726,3785251.0289582033],[-8312848.148223988,3832965.829752971],[-8261829.1646337975,3883984.8133431617],[-8214114.363839028,3938106.6311089005],[-8169892.054359602,3995117.6889613727],[-8129336.76144778,4054792.99030111],[-8092608.538316733,4116897.023976776],[-8059852.334483633,4181184.6937400876],[-8031197.42372012,4247402.2855287315],[-8006756.893867798,4315288.468759856],[-7986627.200532176,4384575.327682497],[-7970887.786416465,4454989.418718643],[-7959600.767797532,4526252.849620108],[-7952810.689381311,4598084.376182293],[-7950544.348505222,4670200.512186557]]],"radius":1148519.49856216,"style":{},"projection":"EPSG:3857"},"attribute":"geom"},"simpleFilterFields":[],"crossLayerFilter":null,"autocompleteEnabled":true}</ms:filter>
124+
</Extension>
125+
</Layer>
126+
<Layer queryable="0" hidden="0">
127+
<Name>gs:ne_110m_ocean</Name>
128+
<Title>Ocean</Title>
129+
<Server service="OGC:WMS" version="1.3.0">
130+
<OnlineResource xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wms"/>
131+
</Server>
132+
<Extension>
133+
<ol:maxExtent minx="-20037508.342789244" miny="-20801248.80884599" maxx="20037508.34" maxy="20037508.34"/>
134+
<ol:singleTile>false</ol:singleTile>
135+
<ol:transparent>true</ol:transparent>
136+
<ol:isBaseLayer>false</ol:isBaseLayer>
137+
<ol:opacity>0.8</ol:opacity>
138+
<ms:group>Default</ms:group>
139+
<ms:search type="wfs" xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wfs"/>
140+
</Extension>
141+
</Layer>
142+
<Layer queryable="0" hidden="0">
143+
<Name>mapstore:Types</Name>
144+
<Title>Types</Title>
145+
<Server service="OGC:WMS" version="1.3.0">
146+
<OnlineResource xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wms"/>
147+
</Server>
148+
<FormatList>
149+
<Format current="1">image/png</Format>
150+
</FormatList>
151+
<Extension>
152+
<ol:maxExtent minx="-20037508.34" miny="-20037508.34" maxx="20037508.34" maxy="20037508.34"/>
153+
<ol:singleTile>false</ol:singleTile>
154+
<ol:transparent>true</ol:transparent>
155+
<ol:isBaseLayer>false</ol:isBaseLayer>
156+
<ol:opacity>1</ol:opacity>
157+
<ms:group>Default</ms:group>
158+
<ms:search type="wfs" xlink:type="simple" xlink:href="https://gs-stable.geo-solutions.it/geoserver/wfs"/>
159+
</Extension>
160+
</Layer>
161+
</LayerList>
162+
</ViewContext>

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

Lines changed: 13 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, mapValues, uniqWith, findIndex, pick, has, toPairs, castArray } from 'lodash';
10+
import { keys, values, get, head, mapValues, uniqWith, findIndex, pick, has, toPairs, castArray, isEmpty } from 'lodash';
1111
import { v1 as uuidv1 } from 'uuid';
1212

1313
import {
@@ -392,15 +392,18 @@ export const toWMC = (
392392
};
393393
};
394394

395-
const olExtensionsGeneral = assignNamespace([{
396-
name: 'maxExtent',
397-
attributes: objectToAttributes({
398-
minx: maxExtent[0],
399-
miny: maxExtent[1],
400-
maxx: maxExtent[2],
401-
maxy: maxExtent[3]
402-
})
403-
}], namespaces.ol);
395+
const maxExtentFromBbox = isEmpty(bbox) ? null : makeMaxExtentFromBbox(bbox);
396+
const olExtensionsGeneral = !isEmpty(maxExtentFromBbox)
397+
? castArray(maxExtentFromBbox)
398+
: assignNamespace([{
399+
name: 'maxExtent',
400+
attributes: objectToAttributes({
401+
minx: maxExtent[0],
402+
miny: maxExtent[1],
403+
maxx: maxExtent[2],
404+
maxy: maxExtent[3]
405+
})
406+
}], namespaces.ol);
404407
const msExtensionsGeneral = assignNamespace([groups.length > 0 ? {
405408
name: 'GroupList',
406409
children: groups.map(group => ({

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

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,54 @@ describe('WMC tests', () => {
332332
done(new Error('Expected toMapConfig to throw an error!'));
333333
});
334334
});
335-
it('toWMC', () =>
336-
Promise.all([
337-
axios.get('base/web/client/test-resources/wmc/config.json'),
338-
axios.get('base/web/client/test-resources/wmc/exported-context.wmc')
339-
]).then(([{data: config}, {data: context}]) => {
340-
const exportedLines = toWMC(config, {}).split('\n').map(r => r.trim()).filter(e => e);
341-
const contextLines = context.split('\n').map(r => r.trim()).filter(e => e);
335+
describe('WMC export tests', () => {
336+
it('toWMC', () =>
337+
Promise.all([
338+
axios.get('base/web/client/test-resources/wmc/config.json'),
339+
axios.get('base/web/client/test-resources/wmc/exported-context.wmc')
340+
]).then(([{data: config}, {data: context}]) => {
341+
const exportedLines = toWMC(config, {}).split('\n').map(r => r.trim()).filter(e => e);
342+
const contextLines = context.split('\n').map(r => r.trim()).filter(e => e);
342343

343-
zip(exportedLines, contextLines).forEach(([exportedLine, contextLine], i) =>
344-
expect({text: exportedLine, line: i + 1}).toEqual({text: contextLine, line: i + 1}));
345-
})
346-
);
344+
zip(exportedLines, contextLines).forEach(([exportedLine, contextLine], i) =>
345+
expect({text: exportedLine, line: i + 1}).toEqual({text: contextLine, line: i + 1}));
346+
})
347+
);
348+
it('Empty maxExtent should not fail', () => {
349+
Promise.all([
350+
axios.get('base/web/client/test-resources/wmc/config.json'),
351+
axios.get('base/web/client/test-resources/wmc/exported-context.wmc')
352+
]).then(([{data: config}, {data: context}]) => {
353+
const _config = omit(config, "map.maxExtent"); // remove mapExtent
354+
const exportedLines = toWMC(_config, {}).split('\n').map(r => r.trim()).filter(e => e);
355+
const contextLines = context.split('\n').map(r => r.trim()).filter(e => e);
356+
357+
zip(exportedLines, contextLines).forEach(([exportedLine, contextLine], i) =>
358+
expect({text: exportedLine, line: i + 1}).toEqual({text: contextLine, line: i + 1}));
359+
});
360+
});
361+
it('bbox should take precedence over maxExtent', () => {
362+
Promise.all([
363+
axios.get('base/web/client/test-resources/wmc/config.json'),
364+
axios.get('base/web/client/test-resources/wmc/context-bbox.wmc')
365+
]).then(([{data: config}, {data: context}]) => {
366+
const _config = {
367+
...config,
368+
map: {
369+
...config.map,
370+
bbox: {bounds: {
371+
minx: -447353.25587372016,
372+
miny: 3817753.15151658,
373+
maxx: 4562023.82912628,
374+
maxy: 6138992.826157694
375+
}, crs: "EPSG:900913"}
376+
}
377+
};
378+
const exportedLines = toWMC(_config, {}).split('\n').map(r => r.trim()).filter(e => e);
379+
const contextLines = context.split('\n').map(r => r.trim()).filter(e => e);
380+
zip(exportedLines, contextLines).forEach(([exportedLine, contextLine], i) =>
381+
expect({text: exportedLine, line: i + 1}).toEqual({text: contextLine, line: i + 1}));
382+
});
383+
});
384+
});
347385
});

0 commit comments

Comments
 (0)