-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic-map.js
112 lines (104 loc) · 3.66 KB
/
static-map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright 2021, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
// add this binding to ensure all the streams inside components are working
import '@mapstore/framework/libs/bindings/rxjsRecompose';
import url from 'url';
import main from '@mapstore/framework/product/main';
import pluginsDef from '@js/plugins/def';
import {
setLocalConfigurationFile,
setConfigProp
} from '@mapstore/framework/utils/ConfigUtils';
import axios from '@mapstore/framework/libs/ajax';
import Viewer from '@js/pages/Viewer';
import { configureMap } from '@mapstore/framework/actions/config';
import { setControlProperty } from '@mapstore/framework/actions/controls';
import security from '@mapstore/framework/reducers/security';
import omit from 'lodash/omit';
setLocalConfigurationFile('configs/localConfig.json');
setConfigProp('translationsPath', ['translations', 'ms-translations']);
setConfigProp('extensionsRegistry', 'configs/extensions.json');
// list of path that need version parameter
const pathsNeedVersion = [
'configs/',
'assets/',
'translations/',
'ms-translations/',
'print.json'
];
const version = __MAPSTORE_PROJECT_CONFIG__.version || 'dev';
axios.interceptors.request.use(
config => {
if (config.url && version && pathsNeedVersion.filter(urlEntry => config.url.match(urlEntry))[0]) {
return {
...config,
params: {
...config.params,
v: version
}
};
}
return config;
}
);
const pages = [{
name: 'home',
path: '/',
component: Viewer
}];
document.addEventListener('DOMContentLoaded', function() {
// example of initial security state
// with null this state is not initialized
const user = null;
const securityState = user && {
security: {
user: user,
token: '' // this token is applied to the request defined in the localConfig authenticationRules properties
}
};
// this is an example of dynamic map loading via query param
// there are other possibilities such use injected map data in the page
// or use the internal react routing
// the important steps is to populate the configureMap action with a valid map config
const params = url.parse(window.location.href, true).query || {};
const mapName = params.map || 'meteorites-map';
// load a base map configuration
axios.get(`configs/${mapName}.json`)
.then(({ data }) => {
// initialize the mapstore app
main({
targetId: 'container',
pages,
initialState: {
defaultState: {
...securityState
}
},
appReducers: {
security
},
appEpics: {},
printingEnabled: false
},
pluginsDef,
// TODO: use default main import to avoid override
(cfg) => ({
...cfg,
// remove epics that manage the map type for the standard product
appEpics: omit(cfg.appEpics, [
'syncMapType',
'updateLast2dMapTypeOnChangeEvents',
'restore2DMapTypeOnLocationChange'
]),
initialActions: [
setControlProperty.bind(null, 'toolbar', 'expanded', false),
configureMap.bind(null, data, 1, true)
]
}));
});
});