@vcmap/core 5.0.0-rc.26 → 5.0.0-rc.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +282 -137
- package/index.js +6 -5
- package/package.json +3 -3
- package/src/category/category.js +16 -16
- package/src/category/categoryCollection.js +13 -14
- package/src/interaction/eventHandler.js +4 -4
- package/src/layer/featureVisibility.js +3 -4
- package/src/layer/globalHider.js +1 -1
- package/src/layer/layer.js +2 -1
- package/src/layer/vectorLayer.js +7 -0
- package/src/oblique/helpers.js +7 -9
- package/src/ol/feature.js +28 -0
- package/src/overrideClassRegistry.js +17 -17
- package/src/style/arcStyle.js +74 -30
- package/src/style/declarativeStyleItem.js +2 -3
- package/src/util/editor/editFeaturesSession.js +150 -166
- package/src/util/editor/editGeometrySession.js +69 -47
- package/src/util/editor/editorHelpers.js +3 -1
- package/src/util/editor/editorSessionHelpers.js +11 -3
- package/src/util/editor/editorSymbols.js +5 -0
- package/src/util/editor/interactions/editFeaturesMouseOverInteraction.js +15 -49
- package/src/util/editor/interactions/editGeometryMouseOverInteraction.js +16 -33
- package/src/util/editor/interactions/ensureHandlerSelectionInteraction.js +5 -5
- package/src/util/editor/interactions/selectFeatureMouseOverInteraction.js +143 -0
- package/src/util/editor/interactions/selectMultiFeatureInteraction.js +17 -11
- package/src/util/editor/interactions/selectSingleFeatureInteraction.js +27 -8
- package/src/util/editor/interactions/translateVertexInteraction.js +2 -3
- package/src/util/editor/selectFeaturesSession.js +287 -0
- package/src/util/editor/transformation/transformationHandler.js +4 -9
- package/src/util/editor/transformation/transformationTypes.js +1 -0
- package/src/util/featureconverter/convert.js +1 -1
- package/src/util/indexedCollection.js +19 -3
- package/src/util/layerCollection.js +4 -2
- package/src/util/overrideCollection.js +33 -20
- package/src/vcsApp.js +107 -85
- package/src/vcsModule.js +129 -0
- package/src/{vcsAppContextHelpers.js → vcsModuleHelpers.js} +5 -5
- package/src/category/appBackedCategory.js +0 -89
- package/src/context.js +0 -89
|
@@ -109,12 +109,28 @@ class IndexedCollection extends Collection {
|
|
|
109
109
|
let target = targetIndex;
|
|
110
110
|
target = target >= 0 ? target : 0;
|
|
111
111
|
target = target < this._array.length ? target : this._array.length - 1;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
if (itemIndex !== target) {
|
|
113
|
+
this._array.splice(itemIndex, 1);
|
|
114
|
+
this._array.splice(target, 0, item);
|
|
115
|
+
this.moved.raiseEvent(item);
|
|
116
|
+
}
|
|
115
117
|
return target;
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Moves an item to a provided index
|
|
122
|
+
* @param {T} item
|
|
123
|
+
* @param {number} targetIndex
|
|
124
|
+
* @returns {number|null} the new index of the item
|
|
125
|
+
*/
|
|
126
|
+
moveTo(item, targetIndex) {
|
|
127
|
+
const index = this._array.indexOf(item);
|
|
128
|
+
if (index > -1) {
|
|
129
|
+
return this._move(item, index, targetIndex);
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
118
134
|
/**
|
|
119
135
|
* Lowers an item within the array
|
|
120
136
|
* @param {T} item
|
|
@@ -98,7 +98,7 @@ class LayerCollection extends IndexedCollection {
|
|
|
98
98
|
get zIndexSymbol() { return this._zIndexSymbol; }
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
* The current global hider
|
|
101
|
+
* The current global hider of these layers
|
|
102
102
|
* @type {GlobalHider}
|
|
103
103
|
*/
|
|
104
104
|
get globalHider() {
|
|
@@ -106,8 +106,10 @@ class LayerCollection extends IndexedCollection {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
109
|
+
* The current global hider of these layers
|
|
110
|
+
* @type {GlobalHider}
|
|
110
111
|
* @param {GlobalHider} globalHider
|
|
112
|
+
* @returns {void}
|
|
111
113
|
*/
|
|
112
114
|
set globalHider(globalHider) {
|
|
113
115
|
check(globalHider, GlobalHider);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// eslint-disable-next-line max-classes-per-file
|
|
3
3
|
import { check } from '@vcsuite/check';
|
|
4
4
|
import { getLogger as getLoggerByName } from '@vcsuite/logger';
|
|
5
|
-
import {
|
|
5
|
+
import { moduleIdSymbol } from '../vcsModuleHelpers.js';
|
|
6
6
|
import Collection from './collection.js';
|
|
7
7
|
import VcsEvent from '../vcsEvent.js';
|
|
8
8
|
|
|
@@ -23,8 +23,9 @@ function getLogger() {
|
|
|
23
23
|
* @property {function(T):T|null} override - returns the overriden item or null if the item could not be inserted (this would be the result of a race condition)
|
|
24
24
|
* @property {Map<string, Array<Object>>} shadowMap
|
|
25
25
|
* @property {function(Array<Object>, string):Promise<void>} parseItems
|
|
26
|
-
* @property {function(string):
|
|
27
|
-
* @property {function(string):
|
|
26
|
+
* @property {function(string):Object} getSerializedByKey
|
|
27
|
+
* @property {function(string):Promise<void>} removeModule
|
|
28
|
+
* @property {function(string):Array<Object>} serializeModule
|
|
28
29
|
* @template {*} T
|
|
29
30
|
*/
|
|
30
31
|
|
|
@@ -36,7 +37,7 @@ export const isOverrideCollection = Symbol('OverrideCollection');
|
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* @param {Collection<T>} collection
|
|
39
|
-
* @param {function():string}
|
|
40
|
+
* @param {function():string} getDynamicModuleId - function to get the current dynamic module id
|
|
40
41
|
* @param {(function(T):Object)=} serializeItem - optional function to serialize an item, defaults to returning item.toJSON or item: i => (i.toJSON || i)
|
|
41
42
|
* @param {(function(Object):(T|Promise<T>))=} deserializeItem - optional deserialization function. defaults to returning the passed object: i => i
|
|
42
43
|
* @param {*=} ctor - optional constructor to validate deserialized items against. if passed, deserializeItem must be an instance of ctor.
|
|
@@ -46,7 +47,7 @@ export const isOverrideCollection = Symbol('OverrideCollection');
|
|
|
46
47
|
*/
|
|
47
48
|
function makeOverrideCollection(
|
|
48
49
|
collection,
|
|
49
|
-
|
|
50
|
+
getDynamicModuleId,
|
|
50
51
|
serializeItem,
|
|
51
52
|
deserializeItem,
|
|
52
53
|
ctor,
|
|
@@ -91,7 +92,7 @@ function makeOverrideCollection(
|
|
|
91
92
|
}
|
|
92
93
|
const shadowsArray = overrideCollection.shadowMap.get(itemId);
|
|
93
94
|
const serializedShadow = serialize(shadow);
|
|
94
|
-
serializedShadow[
|
|
95
|
+
serializedShadow[moduleIdSymbol] = shadow[moduleIdSymbol];
|
|
95
96
|
shadowsArray.push(serializedShadow);
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -113,10 +114,10 @@ function makeOverrideCollection(
|
|
|
113
114
|
|
|
114
115
|
/**
|
|
115
116
|
* @param {Array<Object>} configArray
|
|
116
|
-
* @param {string}
|
|
117
|
+
* @param {string} moduleId
|
|
117
118
|
* @returns {Promise<void>}
|
|
118
119
|
*/
|
|
119
|
-
overrideCollection.parseItems = async function parseItems(configArray,
|
|
120
|
+
overrideCollection.parseItems = async function parseItems(configArray, moduleId) {
|
|
120
121
|
if (Array.isArray(configArray)) {
|
|
121
122
|
const instanceArray = await Promise.all(configArray.map(async (config) => {
|
|
122
123
|
const item = await deserialize(config);
|
|
@@ -124,7 +125,7 @@ function makeOverrideCollection(
|
|
|
124
125
|
getLogger().warning(`Could not load item ${config[overrideCollection.uniqueKey]} of type ${config.type}`);
|
|
125
126
|
return null;
|
|
126
127
|
}
|
|
127
|
-
item[
|
|
128
|
+
item[moduleIdSymbol] = moduleId;
|
|
128
129
|
return item;
|
|
129
130
|
}));
|
|
130
131
|
instanceArray
|
|
@@ -133,6 +134,18 @@ function makeOverrideCollection(
|
|
|
133
134
|
}
|
|
134
135
|
};
|
|
135
136
|
|
|
137
|
+
/**
|
|
138
|
+
* @param {string} key
|
|
139
|
+
* @returns {Object|undefined}
|
|
140
|
+
*/
|
|
141
|
+
overrideCollection.getSerializedByKey = function getSerializedByKey(key) {
|
|
142
|
+
const item = overrideCollection.getByKey(key);
|
|
143
|
+
if (item) {
|
|
144
|
+
return serialize(item);
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
};
|
|
148
|
+
|
|
136
149
|
overrideCollection.removed.addEventListener(async (item) => {
|
|
137
150
|
const itemId = item[overrideCollection.uniqueKey];
|
|
138
151
|
|
|
@@ -140,7 +153,7 @@ function makeOverrideCollection(
|
|
|
140
153
|
const serializedShadow = overrideCollection.shadowMap.get(itemId).pop();
|
|
141
154
|
if (serializedShadow) {
|
|
142
155
|
const reincarnation = await deserialize(serializedShadow);
|
|
143
|
-
reincarnation[
|
|
156
|
+
reincarnation[moduleIdSymbol] = serializedShadow[moduleIdSymbol];
|
|
144
157
|
// @ts-ignore
|
|
145
158
|
const index = getShadowIndex(reincarnation, item, item[overrideCollection.previousIndexSymbol]);
|
|
146
159
|
// @ts-ignore
|
|
@@ -154,18 +167,18 @@ function makeOverrideCollection(
|
|
|
154
167
|
});
|
|
155
168
|
|
|
156
169
|
overrideCollection.added.addEventListener((item) => {
|
|
157
|
-
if (!item[
|
|
158
|
-
item[
|
|
170
|
+
if (!item[moduleIdSymbol]) {
|
|
171
|
+
item[moduleIdSymbol] = getDynamicModuleId();
|
|
159
172
|
}
|
|
160
173
|
});
|
|
161
174
|
|
|
162
175
|
/**
|
|
163
|
-
* @param {string}
|
|
176
|
+
* @param {string} moduleId
|
|
164
177
|
* @returns {Promise<void>}
|
|
165
178
|
*/
|
|
166
|
-
overrideCollection.
|
|
179
|
+
overrideCollection.removeModule = async function removeModule(moduleId) {
|
|
167
180
|
overrideCollection.shadowMap.forEach((shadowsArray, name) => {
|
|
168
|
-
const newShadowsArray = shadowsArray.filter(c => c[
|
|
181
|
+
const newShadowsArray = shadowsArray.filter(c => c[moduleIdSymbol] !== moduleId);
|
|
169
182
|
if (newShadowsArray.length === 0) {
|
|
170
183
|
overrideCollection.shadowMap.delete(name);
|
|
171
184
|
} else if (newShadowsArray.length !== shadowsArray.length) {
|
|
@@ -174,7 +187,7 @@ function makeOverrideCollection(
|
|
|
174
187
|
});
|
|
175
188
|
|
|
176
189
|
await Promise.all([...overrideCollection]
|
|
177
|
-
.filter(item => item[
|
|
190
|
+
.filter(item => item[moduleIdSymbol] === moduleId)
|
|
178
191
|
.map(async (item) => {
|
|
179
192
|
overrideCollection.remove(item);
|
|
180
193
|
// @ts-ignore
|
|
@@ -191,18 +204,18 @@ function makeOverrideCollection(
|
|
|
191
204
|
overrideCollection.replaced = new VcsEvent();
|
|
192
205
|
|
|
193
206
|
/**
|
|
194
|
-
* @param {string}
|
|
207
|
+
* @param {string} moduleId
|
|
195
208
|
* @returns {Array<Object>}
|
|
196
209
|
*/
|
|
197
|
-
overrideCollection.
|
|
210
|
+
overrideCollection.serializeModule = function serializeModule(moduleId) {
|
|
198
211
|
return [...overrideCollection]
|
|
199
212
|
.map((item) => {
|
|
200
|
-
if (item[
|
|
213
|
+
if (item[moduleIdSymbol] === moduleId) {
|
|
201
214
|
return serialize(item);
|
|
202
215
|
}
|
|
203
216
|
if (overrideCollection.shadowMap.has(item[overrideCollection.uniqueKey])) {
|
|
204
217
|
return overrideCollection.shadowMap.get(item[overrideCollection.uniqueKey])
|
|
205
|
-
.find(i => i[
|
|
218
|
+
.find(i => i[moduleIdSymbol] === moduleId);
|
|
206
219
|
}
|
|
207
220
|
return null;
|
|
208
221
|
})
|
package/src/vcsApp.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { getLogger as getLoggerByName } from '@vcsuite/logger';
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import { check } from '@vcsuite/check';
|
|
4
|
-
import
|
|
4
|
+
import VcsModule from './vcsModule.js';
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
moduleIdSymbol,
|
|
7
7
|
destroyCollection,
|
|
8
8
|
deserializeViewpoint,
|
|
9
9
|
deserializeMap,
|
|
10
10
|
getLayerIndex,
|
|
11
11
|
serializeLayer,
|
|
12
12
|
deserializeLayer,
|
|
13
|
-
} from './
|
|
13
|
+
} from './vcsModuleHelpers.js';
|
|
14
14
|
import makeOverrideCollection from './util/overrideCollection.js';
|
|
15
15
|
import CategoryCollection from './category/categoryCollection.js';
|
|
16
16
|
import MapCollection from './util/mapCollection.js';
|
|
@@ -50,7 +50,7 @@ const vcsApps = new Map();
|
|
|
50
50
|
/**
|
|
51
51
|
* @type {string}
|
|
52
52
|
*/
|
|
53
|
-
export const
|
|
53
|
+
export const defaultDynamicModuleId = '_defaultDynamicModule';
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* @class
|
|
@@ -63,23 +63,23 @@ class VcsApp {
|
|
|
63
63
|
*/
|
|
64
64
|
this._id = uuidv4();
|
|
65
65
|
/**
|
|
66
|
-
* @type {
|
|
66
|
+
* @type {VcsModule}
|
|
67
67
|
* @private
|
|
68
68
|
*/
|
|
69
|
-
this.
|
|
69
|
+
this._defaultDynamicModule = new VcsModule({ _id: defaultDynamicModuleId });
|
|
70
70
|
/**
|
|
71
|
-
* @type {
|
|
71
|
+
* @type {VcsModule}
|
|
72
72
|
* @private
|
|
73
73
|
*/
|
|
74
|
-
this.
|
|
74
|
+
this._dynamicModule = this._defaultDynamicModule;
|
|
75
75
|
|
|
76
|
-
const
|
|
76
|
+
const getDynamicModuleId = () => this._dynamicModule._id;
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* @type {VcsEvent<string>}
|
|
80
80
|
* @private
|
|
81
81
|
*/
|
|
82
|
-
this.
|
|
82
|
+
this._dynamicModuleIdChanged = new VcsEvent();
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* represents the current Locale.
|
|
@@ -107,7 +107,7 @@ class VcsApp {
|
|
|
107
107
|
// @ts-ignore
|
|
108
108
|
this._maps = makeOverrideCollection(
|
|
109
109
|
new MapCollection(),
|
|
110
|
-
|
|
110
|
+
getDynamicModuleId,
|
|
111
111
|
null,
|
|
112
112
|
deserializeMap.bind(null, this),
|
|
113
113
|
VcsMap,
|
|
@@ -124,7 +124,7 @@ class VcsApp {
|
|
|
124
124
|
// @ts-ignore
|
|
125
125
|
this._layers = makeOverrideCollection(
|
|
126
126
|
this._maps.layerCollection,
|
|
127
|
-
|
|
127
|
+
getDynamicModuleId,
|
|
128
128
|
serializeLayer.bind(null, this),
|
|
129
129
|
deserializeLayer.bind(null, this),
|
|
130
130
|
Layer,
|
|
@@ -138,7 +138,7 @@ class VcsApp {
|
|
|
138
138
|
*/
|
|
139
139
|
this._obliqueCollections = makeOverrideCollection(
|
|
140
140
|
new Collection(),
|
|
141
|
-
|
|
141
|
+
getDynamicModuleId,
|
|
142
142
|
null,
|
|
143
143
|
config => new ObliqueCollection(config),
|
|
144
144
|
ObliqueCollection,
|
|
@@ -149,7 +149,7 @@ class VcsApp {
|
|
|
149
149
|
*/
|
|
150
150
|
this._viewpoints = makeOverrideCollection(
|
|
151
151
|
new Collection(),
|
|
152
|
-
|
|
152
|
+
getDynamicModuleId,
|
|
153
153
|
null,
|
|
154
154
|
deserializeViewpoint,
|
|
155
155
|
Viewpoint,
|
|
@@ -165,18 +165,18 @@ class VcsApp {
|
|
|
165
165
|
*/
|
|
166
166
|
this._styles = makeOverrideCollection(
|
|
167
167
|
new Collection(),
|
|
168
|
-
|
|
168
|
+
getDynamicModuleId,
|
|
169
169
|
null,
|
|
170
170
|
getObjectFromClassRegistry.bind(null, this._styleClassRegistry),
|
|
171
171
|
StyleItem,
|
|
172
172
|
);
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
* @type {IndexedCollection<
|
|
175
|
+
* @type {IndexedCollection<VcsModule>}
|
|
176
176
|
* @private
|
|
177
177
|
*/
|
|
178
|
-
this.
|
|
179
|
-
this.
|
|
178
|
+
this._modules = new IndexedCollection('_id');
|
|
179
|
+
this._modules.add(this._dynamicModule);
|
|
180
180
|
/**
|
|
181
181
|
* @type {OverrideClassRegistry<import("@vcmap/core").Category<Object|import("@vcmap/core").VcsObject>>}
|
|
182
182
|
* @private
|
|
@@ -196,7 +196,7 @@ class VcsApp {
|
|
|
196
196
|
* @type {Promise<void>}
|
|
197
197
|
* @private
|
|
198
198
|
*/
|
|
199
|
-
this.
|
|
199
|
+
this._moduleMutationPromise = Promise.resolve();
|
|
200
200
|
/**
|
|
201
201
|
* @type {OverrideClassRegistry<*>}
|
|
202
202
|
* @private
|
|
@@ -299,36 +299,36 @@ class VcsApp {
|
|
|
299
299
|
get destroyed() { return this._destroyed; }
|
|
300
300
|
|
|
301
301
|
/**
|
|
302
|
-
* @type {Array<
|
|
302
|
+
* @type {Array<VcsModule>}
|
|
303
303
|
* @readonly
|
|
304
304
|
*/
|
|
305
|
-
get
|
|
306
|
-
return [...this.
|
|
305
|
+
get modules() {
|
|
306
|
+
return [...this._modules];
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
/**
|
|
310
|
-
* @returns {VcsEvent<
|
|
310
|
+
* @returns {VcsEvent<VcsModule>}
|
|
311
311
|
* @readonly
|
|
312
312
|
*/
|
|
313
|
-
get
|
|
313
|
+
get moduleAdded() { return this._modules.added; }
|
|
314
314
|
|
|
315
315
|
/**
|
|
316
|
-
* @returns {VcsEvent<
|
|
316
|
+
* @returns {VcsEvent<VcsModule>}
|
|
317
317
|
* @readonly
|
|
318
318
|
*/
|
|
319
|
-
get
|
|
319
|
+
get moduleRemoved() { return this._modules.removed; }
|
|
320
320
|
|
|
321
321
|
/**
|
|
322
322
|
* @type {string}
|
|
323
323
|
* @readonly
|
|
324
324
|
*/
|
|
325
|
-
get
|
|
325
|
+
get dynamicModuleId() { return this._dynamicModule._id; }
|
|
326
326
|
|
|
327
327
|
/**
|
|
328
328
|
* @type {VcsEvent<string>}
|
|
329
329
|
* @readonly
|
|
330
330
|
*/
|
|
331
|
-
get
|
|
331
|
+
get dynamicModuleIdChanged() { return this._dynamicModuleIdChanged; }
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
334
|
* @type {OverrideClassRegistry<VcsMap>}
|
|
@@ -374,47 +374,47 @@ class VcsApp {
|
|
|
374
374
|
|
|
375
375
|
/**
|
|
376
376
|
* @param {string} id
|
|
377
|
-
* @returns {
|
|
377
|
+
* @returns {VcsModule}
|
|
378
378
|
*/
|
|
379
|
-
|
|
380
|
-
return this.
|
|
379
|
+
getModuleById(id) {
|
|
380
|
+
return this._modules.getByKey(id);
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
/**
|
|
384
|
-
* @param {
|
|
384
|
+
* @param {VcsModule} module
|
|
385
385
|
* @returns {Promise<void>}
|
|
386
386
|
* @protected
|
|
387
387
|
*/
|
|
388
|
-
async
|
|
389
|
-
const { config } =
|
|
388
|
+
async _parseModule(module) {
|
|
389
|
+
const { config } = module;
|
|
390
390
|
if (config.projection) { // XXX this needs fixing. this should be _projections_ and there should be a `defaultProjection`
|
|
391
391
|
setDefaultProjectionOptions(config.projection);
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
-
await this._styles.parseItems(config.styles,
|
|
395
|
-
await this._layers.parseItems(config.layers,
|
|
394
|
+
await this._styles.parseItems(config.styles, module._id);
|
|
395
|
+
await this._layers.parseItems(config.layers, module._id);
|
|
396
396
|
// TODO add flights & ade here
|
|
397
397
|
|
|
398
|
-
await this._obliqueCollections.parseItems(config.obliqueCollections,
|
|
399
|
-
await this._viewpoints.parseItems(config.viewpoints,
|
|
400
|
-
await this._maps.parseItems(config.maps,
|
|
398
|
+
await this._obliqueCollections.parseItems(config.obliqueCollections, module._id);
|
|
399
|
+
await this._viewpoints.parseItems(config.viewpoints, module._id);
|
|
400
|
+
await this._maps.parseItems(config.maps, module._id);
|
|
401
401
|
|
|
402
402
|
if (Array.isArray(config.categories)) {
|
|
403
403
|
await Promise.all((config.categories).map(async ({ name, items }) => {
|
|
404
|
-
await this._categories.parseCategoryItems(name, items,
|
|
404
|
+
await this._categories.parseCategoryItems(name, items, module._id);
|
|
405
405
|
}));
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
/**
|
|
410
|
-
* @param {
|
|
410
|
+
* @param {VcsModule} module
|
|
411
411
|
* @returns {Promise<void>}
|
|
412
412
|
* @protected
|
|
413
413
|
*/
|
|
414
|
-
async
|
|
415
|
-
const { config } =
|
|
414
|
+
async _setModuleState(module) {
|
|
415
|
+
const { config } = module;
|
|
416
416
|
[...this._layers]
|
|
417
|
-
.filter(l => l[
|
|
417
|
+
.filter(l => l[moduleIdSymbol] === module._id)
|
|
418
418
|
.forEach((l) => {
|
|
419
419
|
if (l.activeOnStartup) {
|
|
420
420
|
l.activate()
|
|
@@ -428,7 +428,7 @@ class VcsApp {
|
|
|
428
428
|
});
|
|
429
429
|
|
|
430
430
|
const activeObliqueCollection = [...this._obliqueCollections]
|
|
431
|
-
.find(c => c[
|
|
431
|
+
.find(c => c[moduleIdSymbol] === module._id && c.activeOnStartup);
|
|
432
432
|
|
|
433
433
|
if (activeObliqueCollection) {
|
|
434
434
|
[...this._maps]
|
|
@@ -451,86 +451,108 @@ class VcsApp {
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
/**
|
|
454
|
-
* @param {
|
|
454
|
+
* @param {VcsModule} module
|
|
455
455
|
* @returns {Promise<void>}
|
|
456
456
|
*/
|
|
457
|
-
|
|
458
|
-
check(
|
|
457
|
+
addModule(module) {
|
|
458
|
+
check(module, VcsModule);
|
|
459
459
|
|
|
460
|
-
this.
|
|
460
|
+
this._moduleMutationPromise = this._moduleMutationPromise
|
|
461
461
|
.then(async () => {
|
|
462
|
-
if (this.
|
|
463
|
-
getLogger().info(`
|
|
462
|
+
if (this._modules.has(module)) {
|
|
463
|
+
getLogger().info(`module with id ${module._id} already loaded`);
|
|
464
464
|
return;
|
|
465
465
|
}
|
|
466
466
|
|
|
467
|
-
await this.
|
|
468
|
-
await this.
|
|
469
|
-
this.
|
|
467
|
+
await this._parseModule(module);
|
|
468
|
+
await this._setModuleState(module);
|
|
469
|
+
this._modules.add(module);
|
|
470
470
|
});
|
|
471
|
-
return this.
|
|
471
|
+
return this._moduleMutationPromise;
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
/**
|
|
475
|
-
*
|
|
476
|
-
* @
|
|
475
|
+
* @param {string} moduleId
|
|
476
|
+
* @returns {VcsModuleConfig}
|
|
477
477
|
*/
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
478
|
+
serializeModule(moduleId) {
|
|
479
|
+
check(moduleId, String);
|
|
480
|
+
if (!this._modules.hasKey(moduleId)) {
|
|
481
|
+
throw new Error('VcsModule is not managed by this app, call add(module) before');
|
|
481
482
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
const config = this._modules.getByKey(moduleId).toJSON();
|
|
484
|
+
config.maps = this._maps.serializeModule(moduleId);
|
|
485
|
+
config.layers = this._layers.serializeModule(moduleId);
|
|
486
|
+
config.obliqueCollections = this._obliqueCollections.serializeModule(moduleId);
|
|
487
|
+
config.viewpoints = this._viewpoints.serializeModule(moduleId);
|
|
488
|
+
config.styles = this._styles.serializeModule(moduleId);
|
|
489
|
+
config.categories = [...this._categories]
|
|
490
|
+
.map(c => c.serializeModule(moduleId))
|
|
491
|
+
.filter(c => !!c);
|
|
492
|
+
|
|
493
|
+
return config;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* sets the given module as the dynamic
|
|
498
|
+
* @param {VcsModule} module
|
|
499
|
+
*/
|
|
500
|
+
setDynamicModule(module) {
|
|
501
|
+
if (!this._modules.has(module)) {
|
|
502
|
+
throw new Error('VcsModule is not managed by this app, call add(module) before');
|
|
503
|
+
}
|
|
504
|
+
if (this._dynamicModule !== module) {
|
|
505
|
+
this._dynamicModule = module;
|
|
506
|
+
this.dynamicModuleIdChanged.raiseEvent(this.dynamicModuleId);
|
|
485
507
|
}
|
|
486
508
|
}
|
|
487
509
|
|
|
488
510
|
/**
|
|
489
|
-
* resets the dynamic
|
|
511
|
+
* resets the dynamic VcsModule to the "defaultDynamicModule"
|
|
490
512
|
*/
|
|
491
|
-
|
|
492
|
-
this.
|
|
513
|
+
resetDynamicModule() {
|
|
514
|
+
this.setDynamicModule(this._defaultDynamicModule);
|
|
493
515
|
}
|
|
494
516
|
|
|
495
517
|
/**
|
|
496
|
-
* @param {string}
|
|
518
|
+
* @param {string} moduleId
|
|
497
519
|
* @returns {Promise<void>}
|
|
498
520
|
* @protected
|
|
499
521
|
*/
|
|
500
|
-
async
|
|
522
|
+
async _removeModule(moduleId) {
|
|
501
523
|
await Promise.all([
|
|
502
|
-
this._maps.
|
|
503
|
-
this._layers.
|
|
504
|
-
this._viewpoints.
|
|
505
|
-
this._styles.
|
|
506
|
-
this._obliqueCollections.
|
|
524
|
+
this._maps.removeModule(moduleId),
|
|
525
|
+
this._layers.removeModule(moduleId),
|
|
526
|
+
this._viewpoints.removeModule(moduleId),
|
|
527
|
+
this._styles.removeModule(moduleId),
|
|
528
|
+
this._obliqueCollections.removeModule(moduleId),
|
|
507
529
|
]);
|
|
508
530
|
}
|
|
509
531
|
|
|
510
532
|
/**
|
|
511
|
-
* @param {string}
|
|
533
|
+
* @param {string} moduleId
|
|
512
534
|
* @returns {Promise<void>}
|
|
513
535
|
*/
|
|
514
|
-
|
|
515
|
-
this.
|
|
536
|
+
removeModule(moduleId) {
|
|
537
|
+
this._moduleMutationPromise = this._moduleMutationPromise
|
|
516
538
|
.then(async () => {
|
|
517
|
-
const
|
|
518
|
-
if (!
|
|
519
|
-
getLogger().info(`
|
|
539
|
+
const module = this._modules.getByKey(moduleId);
|
|
540
|
+
if (!module) {
|
|
541
|
+
getLogger().info(`module with id ${moduleId} has already been removed`);
|
|
520
542
|
return;
|
|
521
543
|
}
|
|
522
|
-
await this.
|
|
523
|
-
this.
|
|
544
|
+
await this._removeModule(moduleId);
|
|
545
|
+
this._modules.remove(module);
|
|
524
546
|
});
|
|
525
547
|
|
|
526
|
-
return this.
|
|
548
|
+
return this._moduleMutationPromise;
|
|
527
549
|
}
|
|
528
550
|
|
|
529
551
|
/**
|
|
530
552
|
* Destroys the app and all its collections, their content and ui managers.
|
|
531
553
|
*/
|
|
532
554
|
destroy() {
|
|
533
|
-
Object.defineProperty(this, '
|
|
555
|
+
Object.defineProperty(this, '_moduleMutationPromise', {
|
|
534
556
|
get() {
|
|
535
557
|
throw new Error('VcsApp was destroyed');
|
|
536
558
|
},
|
|
@@ -541,7 +563,7 @@ class VcsApp {
|
|
|
541
563
|
destroyCollection(this._obliqueCollections);
|
|
542
564
|
destroyCollection(this._viewpoints);
|
|
543
565
|
destroyCollection(this._styles);
|
|
544
|
-
destroyCollection(this.
|
|
566
|
+
destroyCollection(this._modules);
|
|
545
567
|
destroyCollection(this._categories);
|
|
546
568
|
this._mapClassRegistry.destroy();
|
|
547
569
|
this._layerClassRegistry.destroy();
|
|
@@ -553,7 +575,7 @@ class VcsApp {
|
|
|
553
575
|
this.destroyed.raiseEvent();
|
|
554
576
|
this.destroyed.destroy();
|
|
555
577
|
this.localeChanged.destroy();
|
|
556
|
-
this.
|
|
578
|
+
this.dynamicModuleIdChanged.destroy();
|
|
557
579
|
}
|
|
558
580
|
}
|
|
559
581
|
|