@vcmap/core 5.0.0-rc.1 → 5.0.0-rc.12

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.
Files changed (185) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +3 -2
  3. package/index.d.ts +2085 -1969
  4. package/index.js +137 -131
  5. package/package.json +14 -22
  6. package/src/category/appBackedCategory.js +76 -0
  7. package/src/category/category.js +417 -0
  8. package/src/category/categoryCollection.js +145 -0
  9. package/src/cesium/cesium3DTileFeature.js +1 -1
  10. package/src/classRegistry.js +162 -0
  11. package/src/context.js +72 -0
  12. package/src/{vcs/vcm/util/featureProvider → featureProvider}/abstractFeatureProvider.js +8 -9
  13. package/src/{vcs/vcm/util/featureProvider → featureProvider}/featureProviderHelpers.js +4 -5
  14. package/src/{vcs/vcm/util/featureProvider → featureProvider}/featureProviderSymbols.js +0 -0
  15. package/src/{vcs/vcm/util/featureProvider → featureProvider}/tileProviderFeatureProvider.js +4 -2
  16. package/src/{vcs/vcm/util/featureProvider → featureProvider}/wmsFeatureProvider.js +25 -18
  17. package/src/{vcs/vcm/interaction → interaction}/abstractInteraction.js +19 -18
  18. package/src/{vcs/vcm/interaction → interaction}/coordinateAtPixel.js +6 -9
  19. package/src/{vcs/vcm/interaction → interaction}/eventHandler.js +3 -3
  20. package/src/{vcs/vcm/interaction → interaction}/featureAtPixelInteraction.js +6 -19
  21. package/src/{vcs/vcm/interaction → interaction}/featureProviderInteraction.js +2 -13
  22. package/src/{vcs/vcm/interaction → interaction}/interactionChain.js +11 -32
  23. package/src/{vcs/vcm/interaction → interaction}/interactionType.js +1 -5
  24. package/src/{vcs/vcm/layer/cesium/cesiumTilesetCesium.js → layer/cesium/cesiumTilesetCesiumImpl.js} +10 -13
  25. package/src/{vcs/vcm/layer → layer}/cesium/clusterContext.js +0 -0
  26. package/src/{vcs/vcm/layer/cesium/dataSourceCesium.js → layer/cesium/dataSourceCesiumImpl.js} +5 -3
  27. package/src/{vcs/vcm/layer/cesium/openStreetMapCesium.js → layer/cesium/openStreetMapCesiumImpl.js} +6 -7
  28. package/src/{vcs/vcm/layer/cesium/rasterLayerCesium.js → layer/cesium/rasterLayerCesiumImpl.js} +5 -6
  29. package/src/{vcs/vcm/layer/cesium/singleImageCesium.js → layer/cesium/singleImageCesiumImpl.js} +5 -6
  30. package/src/{vcs/vcm/layer/cesium/terrainCesium.js → layer/cesium/terrainCesiumImpl.js} +4 -5
  31. package/src/{vcs/vcm/layer/cesium/tmsCesium.js → layer/cesium/tmsCesiumImpl.js} +6 -7
  32. package/src/{vcs/vcm/layer/cesium/vectorCesium.js → layer/cesium/vectorCesiumImpl.js} +6 -7
  33. package/src/{vcs/vcm/layer → layer}/cesium/vectorContext.js +0 -0
  34. package/src/{vcs/vcm/layer/cesium/vectorRasterTileCesium.js → layer/cesium/vectorRasterTileCesiumImpl.js} +5 -6
  35. package/src/{vcs/vcm/layer → layer}/cesium/vectorTileImageryProvider.js +1 -2
  36. package/src/{vcs/vcm/layer/cesium/wmsCesium.js → layer/cesium/wmsCesiumImpl.js} +6 -7
  37. package/src/{vcs/vcm/layer/cesium/wmtsCesium.js → layer/cesium/wmtsCesiumImpl.js} +6 -7
  38. package/src/{vcs/vcm/layer → layer}/cesium/x3dmHelper.js +0 -0
  39. package/src/{vcs/vcm/layer/cesiumTileset.js → layer/cesiumTilesetLayer.js} +38 -37
  40. package/src/{vcs/vcm/layer/czml.js → layer/czmlLayer.js} +14 -17
  41. package/src/{vcs/vcm/layer/dataSource.js → layer/dataSourceLayer.js} +38 -29
  42. package/src/{vcs/vcm/layer → layer}/featureLayer.js +27 -31
  43. package/src/{vcs/vcm/layer/featureStore.js → layer/featureStoreLayer.js} +54 -54
  44. package/src/{vcs/vcm/layer/featureStoreChanges.js → layer/featureStoreLayerChanges.js} +98 -82
  45. package/src/{vcs/vcm/layer/featureStoreState.js → layer/featureStoreLayerState.js} +1 -2
  46. package/src/{vcs/vcm/layer → layer}/featureVisibility.js +9 -6
  47. package/src/{vcs/vcm/layer → layer}/geojsonHelpers.js +15 -41
  48. package/src/{vcs/vcm/layer/geojson.js → layer/geojsonLayer.js} +19 -22
  49. package/src/{vcs/vcm/layer → layer}/globalHider.js +8 -32
  50. package/src/{vcs/vcm/layer → layer}/layer.js +63 -20
  51. package/src/{vcs/vcm/layer → layer}/layerImplementation.js +2 -3
  52. package/src/{vcs/vcm/layer → layer}/layerState.js +0 -1
  53. package/src/{vcs/vcm/layer → layer}/layerSymbols.js +0 -0
  54. package/src/{vcs/vcm/layer/oblique/layerOblique.js → layer/oblique/layerObliqueImpl.js} +4 -4
  55. package/src/{vcs/vcm/layer → layer}/oblique/obliqueHelpers.js +2 -2
  56. package/src/{vcs/vcm/layer/oblique/vectorOblique.js → layer/oblique/vectorObliqueImpl.js} +7 -9
  57. package/src/{vcs/vcm/layer/openStreetMap.js → layer/openStreetMapLayer.js} +32 -33
  58. package/src/{vcs/vcm/layer/openlayers/layerOpenlayers.js → layer/openlayers/layerOpenlayersImpl.js} +5 -6
  59. package/src/layer/openlayers/openStreetMapOpenlayersImpl.js +26 -0
  60. package/src/{vcs/vcm/layer/openlayers/rasterLayerOpenlayers.js → layer/openlayers/rasterLayerOpenlayersImpl.js} +15 -14
  61. package/src/{vcs/vcm/layer/openlayers/singleImageOpenlayers.js → layer/openlayers/singleImageOpenlayersImpl.js} +6 -7
  62. package/src/{vcs/vcm/layer/openlayers/tileDebugOpenlayers.js → layer/openlayers/tileDebugOpenlayersImpl.js} +5 -6
  63. package/src/{vcs/vcm/layer/openlayers/tmsOpenlayers.js → layer/openlayers/tmsOpenlayersImpl.js} +7 -8
  64. package/src/{vcs/vcm/layer/openlayers/vectorOpenlayers.js → layer/openlayers/vectorOpenlayersImpl.js} +8 -9
  65. package/src/{vcs/vcm/layer/openlayers/vectorTileOpenlayers.js → layer/openlayers/vectorTileOpenlayersImpl.js} +6 -7
  66. package/src/{vcs/vcm/layer/openlayers/wmsOpenlayers.js → layer/openlayers/wmsOpenlayersImpl.js} +7 -8
  67. package/src/{vcs/vcm/layer/openlayers/wmtsOpenlayers.js → layer/openlayers/wmtsOpenlayersImpl.js} +7 -8
  68. package/src/{vcs/vcm/layer/pointCloud.js → layer/pointCloudLayer.js} +26 -34
  69. package/src/{vcs/vcm/layer → layer}/rasterLayer.js +18 -20
  70. package/src/{vcs/vcm/layer/singleImage.js → layer/singleImageLayer.js} +20 -20
  71. package/src/{vcs/vcm/layer → layer}/terrainHelpers.js +13 -49
  72. package/src/{vcs/vcm/layer/terrain.js → layer/terrainLayer.js} +13 -14
  73. package/src/{vcs/vcm/layer → layer}/tileLoadedHelper.js +5 -5
  74. package/src/{vcs/vcm/layer → layer}/tileProvider/mvtTileProvider.js +22 -5
  75. package/src/layer/tileProvider/staticGeojsonTileProvider.js +81 -0
  76. package/src/{vcs/vcm/layer → layer}/tileProvider/tileProvider.js +16 -8
  77. package/src/{vcs/vcm/layer → layer}/tileProvider/urlTemplateTileProvider.js +20 -6
  78. package/src/{vcs/vcm/layer/tms.js → layer/tmsLayer.js} +19 -20
  79. package/src/{vcs/vcm/layer → layer}/vectorHelpers.js +5 -5
  80. package/src/{vcs/vcm/layer/vector.js → layer/vectorLayer.js} +38 -48
  81. package/src/{vcs/vcm/layer → layer}/vectorProperties.js +3 -4
  82. package/src/{vcs/vcm/layer → layer}/vectorSymbols.js +0 -0
  83. package/src/{vcs/vcm/layer/vectorTile.js → layer/vectorTileLayer.js} +55 -54
  84. package/src/{vcs/vcm/layer/wfs.js → layer/wfsLayer.js} +19 -20
  85. package/src/{vcs/vcm/layer → layer}/wmsHelpers.js +1 -1
  86. package/src/{vcs/vcm/layer/wms.js → layer/wmsLayer.js} +22 -23
  87. package/src/{vcs/vcm/layer/wmts.js → layer/wmtsLayer.js} +20 -21
  88. package/src/{vcs/vcm/maps → map}/baseOLMap.js +5 -6
  89. package/src/{vcs/vcm/maps → map}/cameraLimiter.js +11 -17
  90. package/src/{vcs/vcm/maps/cesium.js → map/cesiumMap.js} +21 -34
  91. package/src/{vcs/vcm/maps → map}/mapState.js +0 -1
  92. package/src/{vcs/vcm/maps/oblique.js → map/obliqueMap.js} +42 -57
  93. package/src/{vcs/vcm/maps/openlayers.js → map/openlayersMap.js} +17 -15
  94. package/src/{vcs/vcm/maps/map.js → map/vcsMap.js} +41 -22
  95. package/src/oblique/defaultObliqueCollection.js +62 -0
  96. package/src/{vcs/vcm/oblique → oblique}/helpers.js +13 -44
  97. package/src/{vcs/vcm/oblique/ObliqueCollection.js → oblique/obliqueCollection.js} +117 -37
  98. package/src/{vcs/vcm/oblique/ObliqueDataSet.js → oblique/obliqueDataSet.js} +67 -26
  99. package/src/{vcs/vcm/oblique/ObliqueImage.js → oblique/obliqueImage.js} +1 -2
  100. package/src/{vcs/vcm/oblique/ObliqueImageMeta.js → oblique/obliqueImageMeta.js} +4 -5
  101. package/src/{vcs/vcm/oblique/ObliqueProvider.js → oblique/obliqueProvider.js} +17 -12
  102. package/src/{vcs/vcm/oblique/ObliqueView.js → oblique/obliqueView.js} +31 -2
  103. package/src/{vcs/vcm/oblique/ObliqueViewDirection.js → oblique/obliqueViewDirection.js} +0 -3
  104. package/src/{vcs/vcm/oblique → oblique}/parseImageJson.js +20 -12
  105. package/src/ol/geom/circle.js +1 -1
  106. package/src/ol/render/canvas/canvasTileRenderer.js +0 -1
  107. package/src/overrideClassRegistry.js +204 -0
  108. package/src/{vcs/vcm/util/style → style}/declarativeStyleItem.js +43 -20
  109. package/src/{vcs/vcm/util/style → style}/shapesCategory.js +0 -2
  110. package/src/style/styleFactory.js +29 -0
  111. package/src/{vcs/vcm/util/style → style}/styleHelpers.js +3 -14
  112. package/src/{vcs/vcm/util/style → style}/styleItem.js +23 -86
  113. package/src/{vcs/vcm/util/style → style}/vectorStyleItem.js +73 -85
  114. package/src/{vcs/vcm/util/style → style}/writeStyle.js +4 -7
  115. package/src/{vcs/vcm/util → util}/clipping/clippingObject.js +10 -12
  116. package/src/{vcs/vcm/util → util}/clipping/clippingObjectManager.js +2 -3
  117. package/src/{vcs/vcm/util → util}/clipping/clippingPlaneHelper.js +4 -8
  118. package/src/{vcs/vcm/util → util}/collection.js +16 -4
  119. package/src/{vcs/vcm/util → util}/dateTime.js +0 -0
  120. package/src/{vcs/vcm/util → util}/exclusiveManager.js +0 -0
  121. package/src/{vcs/vcm/util → util}/extent.js +18 -12
  122. package/src/{vcs/vcm/util → util}/featureconverter/circleToCesium.js +0 -0
  123. package/src/{vcs/vcm/util → util}/featureconverter/convert.js +0 -0
  124. package/src/util/featureconverter/extent3D.js +181 -0
  125. package/src/{vcs/vcm/util → util}/featureconverter/featureconverterHelper.js +1 -1
  126. package/src/{vcs/vcm/util → util}/featureconverter/lineStringToCesium.js +0 -0
  127. package/src/{vcs/vcm/util → util}/featureconverter/pointToCesium.js +3 -3
  128. package/src/{vcs/vcm/util → util}/featureconverter/polygonToCesium.js +1 -1
  129. package/src/util/fetch.js +32 -0
  130. package/src/{vcs/vcm/util → util}/geometryHelpers.js +0 -0
  131. package/src/{vcs/vcm/util → util}/indexedCollection.js +24 -2
  132. package/src/{vcs/vcm/util → util}/isMobile.js +0 -0
  133. package/src/{vcs/vcm/util → util}/layerCollection.js +49 -12
  134. package/src/{vcs/vcm/util → util}/locale.js +1 -1
  135. package/src/{vcs/vcm/util → util}/mapCollection.js +91 -34
  136. package/src/{vcs/vcm/util → util}/math.js +0 -0
  137. package/src/util/overrideCollection.js +223 -0
  138. package/src/{vcs/vcm/util → util}/projection.js +39 -29
  139. package/src/{vcs/vcm/util → util}/splitScreen.js +10 -10
  140. package/src/{vcs/vcm/util → util}/urlHelpers.js +0 -0
  141. package/src/{vcs/vcm/util → util}/viewpoint.js +5 -9
  142. package/src/vcsApp.js +471 -0
  143. package/src/vcsAppContextHelpers.js +121 -0
  144. package/src/{vcs/vcm/event/vcsEvent.js → vcsEvent.js} +2 -3
  145. package/src/{vcs/vcm/object.js → vcsObject.js} +2 -10
  146. package/tests/data/buildings/tileset.json +428 -0
  147. package/tests/data/dynamicPointCzml.json +64 -0
  148. package/tests/data/oblique/imageData/imagev34.json +352 -0
  149. package/tests/data/oblique/imageData/imagev35.json +54 -0
  150. package/tests/data/oblique/imageData/imagev35PerImageSize.json +53 -0
  151. package/tests/data/oblique/tiledImageData/12/2199/1342.json +1 -0
  152. package/tests/data/oblique/tiledImageData/12/2199/1343.json +1 -0
  153. package/tests/data/oblique/tiledImageData/12/2199/1344.json +1 -0
  154. package/tests/data/oblique/tiledImageData/12/2200/1342.json +1 -0
  155. package/tests/data/oblique/tiledImageData/12/2200/1343.json +1 -0
  156. package/tests/data/oblique/tiledImageData/12/2200/1344.json +1 -0
  157. package/tests/data/oblique/tiledImageData/12/2201/1342.json +1 -0
  158. package/tests/data/oblique/tiledImageData/12/2201/1343.json +1 -0
  159. package/tests/data/oblique/tiledImageData/12/2201/1344.json +1 -0
  160. package/tests/data/oblique/tiledImageData/image.json +1 -0
  161. package/tests/data/terrain/13/8800/6485.terrain +0 -0
  162. package/tests/data/terrain/13/8800/6486.terrain +0 -0
  163. package/tests/data/terrain/13/8801/6485.terrain +0 -0
  164. package/tests/data/terrain/13/8801/6486.terrain +0 -0
  165. package/tests/data/terrain/layer.json +136 -0
  166. package/tests/data/testGeoJSON.json +161 -0
  167. package/tests/data/tile.pbf +0 -0
  168. package/tests/unit/helpers/cesiumHelpers.js +272 -0
  169. package/tests/unit/helpers/getFileNameFromUrl.js +12 -0
  170. package/tests/unit/helpers/helpers.js +11 -0
  171. package/tests/unit/helpers/imageHelpers.js +20 -0
  172. package/tests/unit/helpers/importJSON.js +15 -0
  173. package/tests/unit/helpers/obliqueData.js +76 -0
  174. package/tests/unit/helpers/obliqueHelpers.js +112 -0
  175. package/tests/unit/helpers/openlayersHelpers.js +22 -0
  176. package/tests/unit/helpers/terrain/terrainData.js +46 -0
  177. package/src/vcs/vcm/classRegistry.js +0 -106
  178. package/src/vcs/vcm/globalCollections.js +0 -11
  179. package/src/vcs/vcm/layer/buildings.js +0 -17
  180. package/src/vcs/vcm/layer/cesium/pointCloudCesium.js +0 -58
  181. package/src/vcs/vcm/layer/openlayers/openStreetMapOpenlayers.js +0 -27
  182. package/src/vcs/vcm/layer/tileProvider/staticGeojsonTileProvider.js +0 -67
  183. package/src/vcs/vcm/layer/tileProvider/tileProviderFactory.js +0 -28
  184. package/src/vcs/vcm/util/featureconverter/extent3d.js +0 -154
  185. package/src/vcs/vcm/util/style/styleFactory.js +0 -48
File without changes
@@ -1,7 +1,7 @@
1
1
  import { EasingFunction } from '@vcmap/cesium';
2
2
  import { parseBoolean, parseNumber } from '@vcsuite/parsers';
3
3
  import Projection, { wgs84Projection } from './projection.js';
4
- import VcsObject from '../object.js';
4
+ import VcsObject from '../vcsObject.js';
5
5
  import Extent from './extent.js';
6
6
 
7
7
  /**
@@ -10,7 +10,6 @@ import Extent from './extent.js';
10
10
  * @param {number} right
11
11
  * @param {number} epsilon
12
12
  * @returns {boolean}
13
- * @export
14
13
  */
15
14
  export function propertyEqualsEpsilon(left, right, epsilon) {
16
15
  return Math.abs(left - right) <= epsilon;
@@ -22,7 +21,6 @@ export function propertyEqualsEpsilon(left, right, epsilon) {
22
21
  * @param {number} right angle in degree
23
22
  * @param {number} epsilon in degree
24
23
  * @returns {boolean}
25
- * @export
26
24
  */
27
25
  export function angleEqualsEpsilon(left, right, epsilon) {
28
26
  const diff = (left - right) - Math.trunc((left - right) / 360) * 360;
@@ -36,7 +34,6 @@ export function angleEqualsEpsilon(left, right, epsilon) {
36
34
  * @param {import("ol/coordinate").Coordinate} right
37
35
  * @param {number} epsilon
38
36
  * @returns {boolean}
39
- * @export
40
37
  */
41
38
  export function coordinateEqualsEpsilon(left, right, epsilon) {
42
39
  return left !== null && right !== null &&
@@ -60,12 +57,11 @@ export function coordinateEqualsEpsilon(left, right, epsilon) {
60
57
  /**
61
58
  * A Viewpoint Object
62
59
  * @class
63
- * @export
64
60
  * @extends {VcsObject}
65
61
  * @api stable
66
62
  */
67
63
  class ViewPoint extends VcsObject {
68
- static get className() { return 'vcs.vcm.util.ViewPoint'; }
64
+ static get className() { return 'ViewPoint'; }
69
65
 
70
66
  /**
71
67
  * @param {ViewPointOptions} options
@@ -158,9 +154,9 @@ class ViewPoint extends VcsObject {
158
154
  * @returns {ViewPointOptions} returns a options object. This object can be used to reconstruct a new viewpoint
159
155
  * @api stable
160
156
  */
161
- getConfigObject() {
157
+ toJSON() {
162
158
  return {
163
- ...super.getConfigObject(),
159
+ ...super.toJSON(),
164
160
  distance: this.distance,
165
161
  cameraPosition: this.cameraPosition ? this.cameraPosition.slice() : null,
166
162
  groundPosition: this.groundPosition ? this.groundPosition.slice() : null,
@@ -179,7 +175,7 @@ class ViewPoint extends VcsObject {
179
175
  * @api stable
180
176
  */
181
177
  clone() {
182
- return new ViewPoint(this.getConfigObject());
178
+ return new ViewPoint(this.toJSON());
183
179
  }
184
180
 
185
181
  /**
package/src/vcsApp.js ADDED
@@ -0,0 +1,471 @@
1
+ import { getLogger as getLoggerByName } from '@vcsuite/logger';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { check } from '@vcsuite/check';
4
+ import Context from './context.js';
5
+ import {
6
+ contextIdSymbol,
7
+ destroyCollection,
8
+ deserializeViewPoint,
9
+ deserializeMap,
10
+ getLayerIndex,
11
+ serializeLayer,
12
+ deserializeLayer,
13
+ } from './vcsAppContextHelpers.js';
14
+ import makeOverrideCollection from './util/overrideCollection.js';
15
+ import CategoryCollection from './category/categoryCollection.js';
16
+ import MapCollection from './util/mapCollection.js';
17
+ import VcsMap from './map/vcsMap.js';
18
+ import Layer from './layer/layer.js';
19
+ import Collection from './util/collection.js';
20
+ import ObliqueCollection from './oblique/obliqueCollection.js';
21
+ import ViewPoint from './util/viewpoint.js';
22
+ import StyleItem from './style/styleItem.js';
23
+ import IndexedCollection from './util/indexedCollection.js';
24
+ import VcsEvent from './vcsEvent.js';
25
+ import { setDefaultProjectionOptions } from './util/projection.js';
26
+ import ObliqueMap from './map/obliqueMap.js';
27
+ import OverrideClassRegistry from './overrideClassRegistry.js';
28
+ import ClassRegistry, {
29
+ categoryClassRegistry,
30
+ featureProviderClassRegistry, getObjectFromClassRegistry,
31
+ layerClassRegistry,
32
+ mapClassRegistry,
33
+ styleClassRegistry,
34
+ tileProviderClassRegistry,
35
+ } from './classRegistry.js';
36
+
37
+ /**
38
+ * @returns {import("@vcsuite/logger").Logger}
39
+ */
40
+ function getLogger() {
41
+ return getLoggerByName('init');
42
+ }
43
+
44
+ /**
45
+ * @type {Map<string, VcsApp>}
46
+ */
47
+ const vcsApps = new Map();
48
+
49
+ /**
50
+ * @class
51
+ */
52
+ class VcsApp {
53
+ constructor() {
54
+ /**
55
+ * @type {string}
56
+ * @private
57
+ */
58
+ this._id = uuidv4();
59
+ /**
60
+ * @type {Context}
61
+ * @private
62
+ */
63
+ this._defaultDynamicContext = new Context({ id: '_defaultDynamicContext' });
64
+ /**
65
+ * @type {Context}
66
+ * @private
67
+ */
68
+ this._dynamicContext = this._defaultDynamicContext;
69
+
70
+ const getDynamicContextId = () => this._dynamicContext.id;
71
+
72
+ /**
73
+ * @type {OverrideClassRegistry<VcsMap>}
74
+ * @private
75
+ */
76
+ this._mapClassRegistry = new OverrideClassRegistry(mapClassRegistry);
77
+ /**
78
+ * @type {OverrideMapCollection}
79
+ * @private
80
+ */
81
+ // @ts-ignore
82
+ this._maps = makeOverrideCollection(
83
+ new MapCollection(),
84
+ getDynamicContextId,
85
+ null,
86
+ deserializeMap.bind(null, this),
87
+ VcsMap,
88
+ );
89
+ /**
90
+ * @type {OverrideClassRegistry<Layer>}
91
+ * @private
92
+ */
93
+ this._layerClassRegistry = new OverrideClassRegistry(layerClassRegistry);
94
+ /**
95
+ * @type {OverrideLayerCollection}
96
+ * @private
97
+ */
98
+ // @ts-ignore
99
+ this._layers = makeOverrideCollection(
100
+ this._maps.layerCollection,
101
+ getDynamicContextId,
102
+ serializeLayer.bind(null, this),
103
+ deserializeLayer.bind(null, this),
104
+ Layer,
105
+ getLayerIndex,
106
+ );
107
+ /**
108
+ * @type {OverrideCollection<import("@vcmap/core").ObliqueCollection>}
109
+ * @private
110
+ */
111
+ this._obliqueCollections = makeOverrideCollection(
112
+ new Collection(),
113
+ getDynamicContextId,
114
+ null,
115
+ config => new ObliqueCollection(config),
116
+ ObliqueCollection,
117
+ );
118
+ /**
119
+ * @type {OverrideCollection<import("@vcmap/core").ViewPoint>}
120
+ * @private
121
+ */
122
+ this._viewPoints = makeOverrideCollection(
123
+ new Collection(),
124
+ getDynamicContextId,
125
+ null,
126
+ deserializeViewPoint,
127
+ ViewPoint,
128
+ );
129
+ /**
130
+ * @type {OverrideClassRegistry<StyleItem>}
131
+ * @private
132
+ */
133
+ this._styleClassRegistry = new OverrideClassRegistry(styleClassRegistry);
134
+ /**
135
+ * @type {OverrideCollection<import("@vcmap/core").StyleItem>}
136
+ * @private
137
+ */
138
+ this._styles = makeOverrideCollection(
139
+ new Collection(),
140
+ getDynamicContextId,
141
+ null,
142
+ getObjectFromClassRegistry.bind(null, this._styleClassRegistry),
143
+ StyleItem,
144
+ );
145
+
146
+ /**
147
+ * @type {IndexedCollection<Context>}
148
+ * @private
149
+ */
150
+ this._contexts = new IndexedCollection('id');
151
+ this._contexts.add(this._dynamicContext);
152
+ /**
153
+ * @type {OverrideClassRegistry<import("@vcmap/core").Category<Object|import("@vcmap/core").VcsObject>>}
154
+ * @private
155
+ */
156
+ this._categoryClassRegisty = new OverrideClassRegistry(categoryClassRegistry);
157
+ /**
158
+ * @type {CategoryCollection}
159
+ * @private
160
+ */
161
+ this._categories = new CategoryCollection(this);
162
+ /**
163
+ * @type {import("@vcmap/core").VcsEvent<void>}
164
+ * @private
165
+ */
166
+ this._destroyed = new VcsEvent();
167
+ /**
168
+ * @type {Promise<void>}
169
+ * @private
170
+ */
171
+ this._contextMutationPromise = Promise.resolve();
172
+ /**
173
+ * @type {OverrideClassRegistry<*>}
174
+ * @private
175
+ */
176
+ this._categoryItemClassRegistry = new OverrideClassRegistry(new ClassRegistry());
177
+ /**
178
+ * @type {OverrideClassRegistry<import("@vcmap/core").TileProvider>}
179
+ * @private
180
+ */
181
+ this._tileProviderClassRegsitry = new OverrideClassRegistry(tileProviderClassRegistry);
182
+ /**
183
+ * @type {OverrideClassRegistry<import("@vcmap/core").AbstractFeatureProvider>}
184
+ * @private
185
+ */
186
+ this._featureProviderClassRegsitry = new OverrideClassRegistry(featureProviderClassRegistry);
187
+ vcsApps.set(this._id, this);
188
+ }
189
+
190
+ /**
191
+ * @type {string}
192
+ * @readonly
193
+ */
194
+ get id() { return this._id; }
195
+
196
+ /**
197
+ * @type {OverrideMapCollection}
198
+ * @readonly
199
+ */
200
+ get maps() { return this._maps; }
201
+
202
+ /**
203
+ * @type {OverrideLayerCollection}
204
+ * @readonly
205
+ */
206
+ get layers() { return this._layers; }
207
+
208
+ /**
209
+ * @type {OverrideCollection<import("@vcmap/core").ObliqueCollection>}
210
+ * @readonly
211
+ */
212
+ get obliqueCollections() { return this._obliqueCollections; }
213
+
214
+ /**
215
+ * @type {OverrideCollection<import("@vcmap/core").ViewPoint>}
216
+ * @readonly
217
+ */
218
+ get viewPoints() { return this._viewPoints; }
219
+
220
+ /**
221
+ * @type {OverrideCollection<import("@vcmap/core").StyleItem>}
222
+ * @readonly
223
+ */
224
+ get styles() { return this._styles; }
225
+
226
+ /**
227
+ * @type {CategoryCollection}
228
+ * @readonly
229
+ */
230
+ get categories() { return this._categories; }
231
+
232
+ /**
233
+ * @type {VcsEvent<void>}
234
+ * @readonly
235
+ */
236
+ get destroyed() { return this._destroyed; }
237
+
238
+ /**
239
+ * @returns {VcsEvent<Context>}
240
+ * @readonly
241
+ */
242
+ get contextAdded() { return this._contexts.added; }
243
+
244
+ /**
245
+ * @returns {VcsEvent<Context>}
246
+ * @readonly
247
+ */
248
+ get contextRemoved() { return this._contexts.removed; }
249
+
250
+ /**
251
+ * @type {string}
252
+ * @readonly
253
+ */
254
+ get dynamicContextId() { return this._dynamicContext.id; }
255
+
256
+ /**
257
+ * @type {OverrideClassRegistry<VcsMap>}
258
+ * @readonly
259
+ */
260
+ get mapClassRegistry() { return this._mapClassRegistry; }
261
+
262
+ /**
263
+ * @type {OverrideClassRegistry<Layer>}
264
+ * @readonly
265
+ */
266
+ get layerClassRegistry() { return this._layerClassRegistry; }
267
+
268
+ /**
269
+ * @type {OverrideClassRegistry<StyleItem>}
270
+ * @readonly
271
+ */
272
+ get styleClassRegistry() { return this._styleClassRegistry; }
273
+
274
+ /**
275
+ * @type {OverrideClassRegistry<import("@vcmap/core").Category<Object|import("@vcmap/core").VcsObject>>}
276
+ * @readonly
277
+ */
278
+ get categoryClassRegistry() { return this._categoryClassRegisty; }
279
+
280
+ /**
281
+ * @type {OverrideClassRegistry<*>}
282
+ * @readonly
283
+ */
284
+ get categoryItemClassRegistry() { return this._categoryItemClassRegistry; }
285
+
286
+ /**
287
+ * @type {OverrideClassRegistry<import("@vcmap/core").TileProvider>}
288
+ * @readonly
289
+ */
290
+ get tileProviderClassRegistry() { return this._tileProviderClassRegsitry; }
291
+
292
+ /**
293
+ * @type {OverrideClassRegistry<import("@vcmap/core").AbstractFeatureProvider>}
294
+ * @readonly
295
+ */
296
+ get featureProviderClassRegistry() { return this._featureProviderClassRegsitry; }
297
+
298
+ /**
299
+ * @param {string} id
300
+ * @returns {Context}
301
+ */
302
+ getContextById(id) {
303
+ return this._contexts.getByKey(id);
304
+ }
305
+
306
+ /**
307
+ * @param {Context} context
308
+ * @returns {Promise<void>}
309
+ * @protected
310
+ */
311
+ async _parseContext(context) {
312
+ const { config } = context;
313
+ if (config.projection) { // XXX this needs fixing. this should be _projections_ and there should be a `defaultProjection`
314
+ setDefaultProjectionOptions(config.projection);
315
+ }
316
+
317
+ await this._styles.parseItems(config.styles, context.id);
318
+ await this._layers.parseItems(config.layers, context.id);
319
+ // TODO add flights & ade here
320
+
321
+ await this._obliqueCollections.parseItems(config.obliqueCollections, context.id);
322
+ await this._viewPoints.parseItems(config.viewpoints, context.id);
323
+ await this._maps.parseItems(config.maps, context.id);
324
+
325
+ if (Array.isArray(config.categories)) {
326
+ await Promise.all((config.categories).map(async ({ name, items }) => {
327
+ await this._categories.parseCategoryItems(name, items, context.id);
328
+ }));
329
+ }
330
+ }
331
+
332
+ /**
333
+ * @param {Context} context
334
+ * @returns {Promise<void>}
335
+ * @protected
336
+ */
337
+ async _setContextState(context) {
338
+ const { config } = context;
339
+ [...this._layers]
340
+ .filter(l => l[contextIdSymbol] === context.id)
341
+ .forEach((l) => {
342
+ if (l.activeOnStartup) {
343
+ l.activate()
344
+ .catch((err) => {
345
+ getLogger().error(`Failed to activate active on startup layer ${l.name}`);
346
+ getLogger().error(err);
347
+ this._layers.remove(l);
348
+ l.destroy();
349
+ });
350
+ }
351
+ });
352
+
353
+ const activeObliqueCollection = [...this._obliqueCollections]
354
+ .find(c => c[contextIdSymbol] === context.id && c.activeOnStartup);
355
+
356
+ if (activeObliqueCollection) {
357
+ [...this._maps]
358
+ .filter(m => m instanceof ObliqueMap)
359
+ .forEach((m) => { /** @type {ObliqueMap} */ (m).setCollection(activeObliqueCollection); });
360
+ }
361
+
362
+ if (config.startingMapName) {
363
+ await this._maps.setActiveMap(config.startingMapName);
364
+ } else if (!this._maps.activeMap && this._maps.size > 0) {
365
+ await this._maps.setActiveMap([...this._maps][0].name);
366
+ }
367
+
368
+ if (config.startingViewPointName && this._maps.activeMap) {
369
+ const startViewPoint = this._viewPoints.getByKey(config.startingViewPointName);
370
+ if (startViewPoint) {
371
+ await this._maps.activeMap.gotoViewPoint(startViewPoint);
372
+ }
373
+ }
374
+ }
375
+
376
+ /**
377
+ * @param {Context} context
378
+ * @returns {Promise<void>}
379
+ */
380
+ addContext(context) {
381
+ check(context, Context);
382
+
383
+ this._contextMutationPromise = this._contextMutationPromise
384
+ .then(async () => {
385
+ if (this._contexts.has(context)) {
386
+ getLogger().info(`context with id ${context.id} already loaded`);
387
+ return;
388
+ }
389
+
390
+ await this._parseContext(context);
391
+ await this._setContextState(context);
392
+ this._contexts.add(context);
393
+ });
394
+ return this._contextMutationPromise;
395
+ }
396
+
397
+ /**
398
+ * @param {string} contextId
399
+ * @returns {Promise<void>}
400
+ * @protected
401
+ */
402
+ async _removeContext(contextId) {
403
+ await Promise.all([
404
+ this._maps.removeContext(contextId),
405
+ this._layers.removeContext(contextId),
406
+ this._viewPoints.removeContext(contextId),
407
+ this._styles.removeContext(contextId),
408
+ this._obliqueCollections.removeContext(contextId),
409
+ ]);
410
+ }
411
+
412
+ /**
413
+ * @param {string} contextId
414
+ * @returns {Promise<void>}
415
+ */
416
+ removeContext(contextId) {
417
+ this._contextMutationPromise = this._contextMutationPromise
418
+ .then(async () => {
419
+ const context = this._contexts.getByKey(contextId);
420
+ if (!context) {
421
+ getLogger().info(`context with id ${contextId} has alread been removed`);
422
+ return;
423
+ }
424
+ await this._removeContext(contextId);
425
+ this._contexts.remove(context);
426
+ });
427
+
428
+ return this._contextMutationPromise;
429
+ }
430
+
431
+ /**
432
+ * Destroys the app and all its collections, their content and ui managers.
433
+ */
434
+ destroy() {
435
+ Object.defineProperty(this, '_contextMutationPromise', {
436
+ get() {
437
+ throw new Error('VcsApp was destroyed');
438
+ },
439
+ });
440
+ vcsApps.delete(this._id);
441
+ destroyCollection(this._maps);
442
+ destroyCollection(this._layers);
443
+ destroyCollection(this._obliqueCollections);
444
+ destroyCollection(this._viewPoints);
445
+ destroyCollection(this._styles);
446
+ destroyCollection(this._contexts);
447
+ destroyCollection(this._categories);
448
+ this._mapClassRegistry.destroy();
449
+ this._layerClassRegistry.destroy();
450
+ this._styleClassRegistry.destroy();
451
+ this._categoryClassRegisty.destroy();
452
+ this._categoryItemClassRegistry.destroy();
453
+ this._tileProviderClassRegsitry.destroy();
454
+ this._featureProviderClassRegsitry.destroy();
455
+ this.destroyed.raiseEvent();
456
+ this.destroyed.destroy();
457
+ }
458
+ }
459
+
460
+ /**
461
+ * @param {string} id
462
+ * @returns {VcsApp}
463
+ */
464
+ export function getVcsAppById(id) {
465
+ return vcsApps.get(id);
466
+ }
467
+
468
+ window.vcs = window.vcs || {};
469
+ window.vcs.apps = vcsApps;
470
+
471
+ export default VcsApp;
@@ -0,0 +1,121 @@
1
+ import { getLogger as getLoggerByName } from '@vcsuite/logger';
2
+ import ViewPoint from './util/viewpoint.js';
3
+ import { getObjectFromClassRegistry } from './classRegistry.js';
4
+
5
+ /**
6
+ * @returns {import("@vcsuite/logger").Logger}
7
+ */
8
+ function getLogger() {
9
+ return getLoggerByName('init');
10
+ }
11
+
12
+ /**
13
+ * @type {symbol}
14
+ */
15
+ export const contextIdSymbol = Symbol('contextId');
16
+
17
+ /**
18
+ * @typedef {LayerOptions} ContextLayerOptions
19
+ * @property {string|StyleItemOptions} [style]
20
+ * @property {TileProviderOptions} [tileProvider]
21
+ * @property {AbstractFeatureProviderOptions} [featureProvider]
22
+ */
23
+
24
+ /**
25
+ * @param {import("@vcmap/core").VcsApp} vcsApp
26
+ * @param {VcsMapOptions} mapConfig
27
+ * @returns {import("@vcmap/core").VcsMap|null}
28
+ */
29
+ export function deserializeMap(vcsApp, mapConfig) {
30
+ const map = getObjectFromClassRegistry(vcsApp.mapClassRegistry, mapConfig);
31
+ if (map) {
32
+ map.layerCollection = vcsApp.layers;
33
+ }
34
+ return map;
35
+ }
36
+
37
+ /**
38
+ * @param {ViewPointOptions} viewPointObject
39
+ * @returns {null|import("@vcmap/core").ViewPoint}
40
+ */
41
+ export function deserializeViewPoint(viewPointObject) {
42
+ const viewpoint = new ViewPoint(viewPointObject);
43
+ if (viewpoint && viewpoint.isValid()) {
44
+ return viewpoint;
45
+ }
46
+ getLogger().warning(`Viewpoint ${viewPointObject.name} is not valid`);
47
+ return null;
48
+ }
49
+
50
+ /**
51
+ * @param {import("@vcmap/core").VcsApp} vcsApp
52
+ * @param {ContextLayerOptions} layerConfig
53
+ * @returns {import("@vcmap/core").Layer|null}
54
+ */
55
+ export function deserializeLayer(vcsApp, layerConfig) {
56
+ let style;
57
+ if (layerConfig.style) {
58
+ if (typeof layerConfig.style === 'string') {
59
+ style = vcsApp.styles.getByKey(layerConfig.style);
60
+ } else {
61
+ style = getObjectFromClassRegistry(vcsApp.styleClassRegistry, layerConfig.style);
62
+ }
63
+ } // TODO highlightStyle
64
+
65
+ let tileProvider;
66
+ if (layerConfig.tileProvider) {
67
+ tileProvider = getObjectFromClassRegistry(vcsApp.tileProviderClassRegistry, layerConfig.tileProvider);
68
+ }
69
+
70
+ let featureProvider;
71
+ if (layerConfig.featureProvider) {
72
+ featureProvider = getObjectFromClassRegistry(vcsApp.featureProviderClassRegistry, layerConfig.featureProvider);
73
+ }
74
+
75
+ return getObjectFromClassRegistry(
76
+ vcsApp.layerClassRegistry,
77
+ { ...layerConfig, style, tileProvider, featureProvider },
78
+ );
79
+ }
80
+
81
+ /**
82
+ * @param {import("@vcmap/core").VcsApp} vcsApp
83
+ * @param {import("@vcmap/core").Layer} layer
84
+ * @returns {ContextLayerOptions}
85
+ */
86
+ export function serializeLayer(vcsApp, layer) {
87
+ const serializedLayer = /** @type {ContextLayerOptions} */ (layer.toJSON());
88
+ serializedLayer.zIndex = layer[vcsApp.layers.zIndexSymbol];
89
+ if (
90
+ /** @type {StyleItemOptions} */ (serializedLayer?.style)?.name &&
91
+ vcsApp.styles.hasKey(/** @type {StyleItemOptions} */ (serializedLayer.style).name)
92
+ ) {
93
+ serializedLayer.style = /** @type {StyleItemOptions} */ (serializedLayer.style).name;
94
+ } // TODO highlightStyle
95
+ return serializedLayer;
96
+ }
97
+
98
+ /**
99
+ * @param {import("@vcmap/core").Layer} current
100
+ * @param {import("@vcmap/core").Layer} previous
101
+ * @param {number} currentIndex
102
+ * @returns {number|null}
103
+ */
104
+ export function getLayerIndex(current, previous, currentIndex) {
105
+ if (current.zIndex !== previous.zIndex) {
106
+ return null;
107
+ }
108
+ return currentIndex;
109
+ }
110
+
111
+ /**
112
+ * @param {import("@vcmap/core").Collection<*>} collection
113
+ */
114
+ export function destroyCollection(collection) {
115
+ [...collection].forEach((i) => {
116
+ if (i.destroy && !i.isDestroyed) {
117
+ i.destroy();
118
+ }
119
+ });
120
+ collection.destroy();
121
+ }
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * @class
3
3
  * @template {*} T
4
- * @export
5
4
  * @api
6
5
  */
7
6
  class VcsEvent {
@@ -58,7 +57,7 @@ class VcsEvent {
58
57
  * @api
59
58
  */
60
59
  raiseEvent(event) {
61
- this._listeners.forEach((cb) => {
60
+ [...this._listeners].forEach((cb) => {
62
61
  cb(event);
63
62
  });
64
63
  }
@@ -70,7 +69,7 @@ class VcsEvent {
70
69
  async awaitRaisedEvent(event) {
71
70
  const promises = new Array(this._listeners.size);
72
71
  let i = 0;
73
- this._listeners.forEach((cb) => {
72
+ [...this._listeners].forEach((cb) => {
74
73
  promises[i] = cb(event);
75
74
  i += 1;
76
75
  });