Skip to content

Commit 3e70306

Browse files
authored
Fix 5397 Map info data wrongly requested for static map configurations (#5398)
* avoid load map info if id is alphanumeric or null
1 parent 89ad4b1 commit 3e70306

3 files changed

Lines changed: 48 additions & 24 deletions

File tree

web/client/config.json

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
{
2-
"map": {
3-
"projection": "EPSG:900913",
4-
"units": "m",
5-
"center": {"x": 1250000.000000, "y": 5370000.000000, "crs": "EPSG:900913"},
6-
"zoom":5,
7-
"maxExtent": [
8-
-20037508.34, -20037508.34,
9-
20037508.34, 20037508.34
10-
],
11-
"layers": [
12-
{
13-
"type": "osm",
14-
"title": "Open Street Map",
15-
"name": "mapnik",
16-
"source": "osm",
17-
"group": "background",
18-
"visibility": true
19-
}
20-
]
21-
}
22-
}
2+
"version": 2,
3+
"map": {
4+
"projection": "EPSG:900913",
5+
"units": "m",
6+
"center": {
7+
"x": 1250000.000000,
8+
"y": 5370000.000000,
9+
"crs": "EPSG:900913"
10+
},
11+
"zoom": 5,
12+
"maxExtent": [
13+
-20037508.34,
14+
-20037508.34,
15+
20037508.34,
16+
20037508.34
17+
],
18+
"layers": [
19+
{
20+
"type": "osm",
21+
"title": "Open Street Map",
22+
"name": "mapnik",
23+
"source": "osm",
24+
"group": "background",
25+
"visibility": true
26+
}
27+
]
28+
}
29+
}

web/client/epics/__tests__/config-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ describe('config epics', () => {
214214
}
215215
});
216216
});
217+
it('load existing configuration file with alphanumeric mapId', (done) => {
218+
mockAxios.onGet("/base/web/client/test-resources/testConfig.json").reply(() => ([ 200, {} ]));
219+
const checkActions = ([a]) => {
220+
expect(a).toBeTruthy();
221+
expect(a.type).toBe(MAP_CONFIG_LOADED);
222+
done();
223+
};
224+
testEpic(loadMapConfigAndConfigureMap,
225+
1,
226+
[loadMapConfig('base/web/client/test-resources/testConfig.json', 'testConfig')],
227+
checkActions
228+
);
229+
});
217230
});
218231

219232
describe('loadMapInfo', () => {

web/client/epics/config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { Observable } from 'rxjs';
99
import axios from '../libs/ajax';
10-
import { get, merge } from 'lodash';
10+
import { get, merge, isNaN } from 'lodash';
1111
import {
1212
LOAD_NEW_MAP,
1313
LOAD_MAP_CONFIG,
@@ -61,6 +61,10 @@ const mapFlowWithOverride = (configName, mapId, config, mapInfo, state, override
6161
// certain epics always function correctly
6262
// i.e. FeedbackMask disables correctly after load
6363
// TODO: investigate the root causes of the problem and come up with a better solution, if possible
64+
65+
// mapstore recognizes alphanumeric map id as static json
66+
// avoid map info requests if the configuration is static
67+
const isNumberId = !isNaN(parseFloat(mapId));
6468
return (
6569
config ?
6670
Observable.of({data: merge({}, config, overrideConfig), staticConfig: true}).delay(100) :
@@ -77,7 +81,7 @@ const mapFlowWithOverride = (configName, mapId, config, mapInfo, state, override
7781
return Observable.of(configureError({messageId: `map.errors.loading.projectionError`, errorMessageParams: {projection}}, mapId));
7882
}
7983
const mapConfig = merge({}, response.data, overrideConfig);
80-
return mapId ? Observable.of(
84+
return isNumberId ? Observable.of(
8185
configureMap(mapConfig, mapId),
8286
mapInfo ? mapInfoLoaded(mapInfo) : loadMapInfo(mapId),
8387
...(response.staticConfig ? [] : [saveMapConfig(response.data)])
@@ -91,7 +95,7 @@ const mapFlowWithOverride = (configName, mapId, config, mapInfo, state, override
9195
try {
9296
const data = JSON.parse(response.data);
9397
const mapConfig = merge({}, data, overrideConfig);
94-
return mapId ? Observable.of(configureMap(mapConfig, mapId), mapInfo ? mapInfoLoaded(mapInfo) : loadMapInfo(mapId)) :
98+
return isNumberId ? Observable.of(configureMap(mapConfig, mapId), mapInfo ? mapInfoLoaded(mapInfo) : loadMapInfo(mapId)) :
9599
Observable.of(
96100
configureMap(mapConfig, mapId),
97101
...(mapInfo ? [mapInfoLoaded(mapInfo)] : []),

0 commit comments

Comments
 (0)