@vcmap/core 5.0.0-rc.0

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 (146) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +44 -0
  3. package/build/postinstall.js +44 -0
  4. package/index.js +139 -0
  5. package/package.json +92 -0
  6. package/src/cesium/cesium3DTileFeature.js +9 -0
  7. package/src/cesium/cesium3DTilePointFeature.js +9 -0
  8. package/src/cesium/cesiumVcsCameraPrimitive.js +146 -0
  9. package/src/cesium/wallpaperMaterial.js +64 -0
  10. package/src/ol/feature.js +47 -0
  11. package/src/ol/geom/circle.js +24 -0
  12. package/src/ol/geom/geometryCollection.js +33 -0
  13. package/src/ol/render/canvas/canvasTileRenderer.js +179 -0
  14. package/src/ol/source/ClusterEnhancedVectorSource.js +39 -0
  15. package/src/ol/source/VcsCluster.js +37 -0
  16. package/src/vcs/vcm/classRegistry.js +106 -0
  17. package/src/vcs/vcm/event/vcsEvent.js +89 -0
  18. package/src/vcs/vcm/globalCollections.js +11 -0
  19. package/src/vcs/vcm/interaction/abstractInteraction.js +149 -0
  20. package/src/vcs/vcm/interaction/coordinateAtPixel.js +102 -0
  21. package/src/vcs/vcm/interaction/eventHandler.js +425 -0
  22. package/src/vcs/vcm/interaction/featureAtPixelInteraction.js +286 -0
  23. package/src/vcs/vcm/interaction/featureProviderInteraction.js +54 -0
  24. package/src/vcs/vcm/interaction/interactionChain.js +124 -0
  25. package/src/vcs/vcm/interaction/interactionType.js +114 -0
  26. package/src/vcs/vcm/layer/buildings.js +17 -0
  27. package/src/vcs/vcm/layer/cesium/cesiumTilesetCesium.js +359 -0
  28. package/src/vcs/vcm/layer/cesium/clusterContext.js +95 -0
  29. package/src/vcs/vcm/layer/cesium/dataSourceCesium.js +171 -0
  30. package/src/vcs/vcm/layer/cesium/openStreetMapCesium.js +29 -0
  31. package/src/vcs/vcm/layer/cesium/pointCloudCesium.js +58 -0
  32. package/src/vcs/vcm/layer/cesium/rasterLayerCesium.js +110 -0
  33. package/src/vcs/vcm/layer/cesium/singleImageCesium.js +49 -0
  34. package/src/vcs/vcm/layer/cesium/terrainCesium.js +80 -0
  35. package/src/vcs/vcm/layer/cesium/tmsCesium.js +54 -0
  36. package/src/vcs/vcm/layer/cesium/vectorCesium.js +255 -0
  37. package/src/vcs/vcm/layer/cesium/vectorContext.js +167 -0
  38. package/src/vcs/vcm/layer/cesium/vectorRasterTileCesium.js +116 -0
  39. package/src/vcs/vcm/layer/cesium/vectorTileImageryProvider.js +246 -0
  40. package/src/vcs/vcm/layer/cesium/wmsCesium.js +71 -0
  41. package/src/vcs/vcm/layer/cesium/wmtsCesium.js +101 -0
  42. package/src/vcs/vcm/layer/cesium/x3dmHelper.js +22 -0
  43. package/src/vcs/vcm/layer/cesiumTileset.js +376 -0
  44. package/src/vcs/vcm/layer/czml.js +141 -0
  45. package/src/vcs/vcm/layer/dataSource.js +259 -0
  46. package/src/vcs/vcm/layer/featureLayer.js +261 -0
  47. package/src/vcs/vcm/layer/featureStore.js +647 -0
  48. package/src/vcs/vcm/layer/featureStoreChanges.js +360 -0
  49. package/src/vcs/vcm/layer/featureStoreState.js +19 -0
  50. package/src/vcs/vcm/layer/featureVisibility.js +435 -0
  51. package/src/vcs/vcm/layer/geojson.js +185 -0
  52. package/src/vcs/vcm/layer/geojsonHelpers.js +450 -0
  53. package/src/vcs/vcm/layer/globalHider.js +157 -0
  54. package/src/vcs/vcm/layer/layer.js +752 -0
  55. package/src/vcs/vcm/layer/layerImplementation.js +102 -0
  56. package/src/vcs/vcm/layer/layerState.js +17 -0
  57. package/src/vcs/vcm/layer/layerSymbols.js +6 -0
  58. package/src/vcs/vcm/layer/oblique/layerOblique.js +76 -0
  59. package/src/vcs/vcm/layer/oblique/obliqueHelpers.js +175 -0
  60. package/src/vcs/vcm/layer/oblique/vectorOblique.js +469 -0
  61. package/src/vcs/vcm/layer/openStreetMap.js +194 -0
  62. package/src/vcs/vcm/layer/openlayers/layerOpenlayers.js +79 -0
  63. package/src/vcs/vcm/layer/openlayers/openStreetMapOpenlayers.js +27 -0
  64. package/src/vcs/vcm/layer/openlayers/rasterLayerOpenlayers.js +121 -0
  65. package/src/vcs/vcm/layer/openlayers/singleImageOpenlayers.js +49 -0
  66. package/src/vcs/vcm/layer/openlayers/tileDebugOpenlayers.js +39 -0
  67. package/src/vcs/vcm/layer/openlayers/tmsOpenlayers.js +62 -0
  68. package/src/vcs/vcm/layer/openlayers/vectorOpenlayers.js +118 -0
  69. package/src/vcs/vcm/layer/openlayers/vectorTileOpenlayers.js +177 -0
  70. package/src/vcs/vcm/layer/openlayers/wmsOpenlayers.js +55 -0
  71. package/src/vcs/vcm/layer/openlayers/wmtsOpenlayers.js +141 -0
  72. package/src/vcs/vcm/layer/pointCloud.js +162 -0
  73. package/src/vcs/vcm/layer/rasterLayer.js +294 -0
  74. package/src/vcs/vcm/layer/singleImage.js +119 -0
  75. package/src/vcs/vcm/layer/terrain.js +122 -0
  76. package/src/vcs/vcm/layer/terrainHelpers.js +123 -0
  77. package/src/vcs/vcm/layer/tileLoadedHelper.js +72 -0
  78. package/src/vcs/vcm/layer/tileProvider/mvtTileProvider.js +104 -0
  79. package/src/vcs/vcm/layer/tileProvider/staticGeojsonTileProvider.js +67 -0
  80. package/src/vcs/vcm/layer/tileProvider/tileProvider.js +584 -0
  81. package/src/vcs/vcm/layer/tileProvider/tileProviderFactory.js +28 -0
  82. package/src/vcs/vcm/layer/tileProvider/urlTemplateTileProvider.js +106 -0
  83. package/src/vcs/vcm/layer/tms.js +121 -0
  84. package/src/vcs/vcm/layer/vector.js +632 -0
  85. package/src/vcs/vcm/layer/vectorHelpers.js +206 -0
  86. package/src/vcs/vcm/layer/vectorProperties.js +1391 -0
  87. package/src/vcs/vcm/layer/vectorSymbols.js +40 -0
  88. package/src/vcs/vcm/layer/vectorTile.js +480 -0
  89. package/src/vcs/vcm/layer/wfs.js +165 -0
  90. package/src/vcs/vcm/layer/wms.js +270 -0
  91. package/src/vcs/vcm/layer/wmsHelpers.js +65 -0
  92. package/src/vcs/vcm/layer/wmts.js +235 -0
  93. package/src/vcs/vcm/maps/baseOLMap.js +257 -0
  94. package/src/vcs/vcm/maps/cameraLimiter.js +219 -0
  95. package/src/vcs/vcm/maps/cesium.js +1192 -0
  96. package/src/vcs/vcm/maps/map.js +511 -0
  97. package/src/vcs/vcm/maps/mapState.js +17 -0
  98. package/src/vcs/vcm/maps/oblique.js +536 -0
  99. package/src/vcs/vcm/maps/openlayers.js +205 -0
  100. package/src/vcs/vcm/object.js +92 -0
  101. package/src/vcs/vcm/oblique/ObliqueCollection.js +572 -0
  102. package/src/vcs/vcm/oblique/ObliqueDataSet.js +357 -0
  103. package/src/vcs/vcm/oblique/ObliqueImage.js +247 -0
  104. package/src/vcs/vcm/oblique/ObliqueImageMeta.js +126 -0
  105. package/src/vcs/vcm/oblique/ObliqueProvider.js +433 -0
  106. package/src/vcs/vcm/oblique/ObliqueView.js +130 -0
  107. package/src/vcs/vcm/oblique/ObliqueViewDirection.js +40 -0
  108. package/src/vcs/vcm/oblique/helpers.js +483 -0
  109. package/src/vcs/vcm/oblique/parseImageJson.js +248 -0
  110. package/src/vcs/vcm/util/clipping/clippingObject.js +386 -0
  111. package/src/vcs/vcm/util/clipping/clippingObjectManager.js +312 -0
  112. package/src/vcs/vcm/util/clipping/clippingPlaneHelper.js +413 -0
  113. package/src/vcs/vcm/util/collection.js +193 -0
  114. package/src/vcs/vcm/util/dateTime.js +60 -0
  115. package/src/vcs/vcm/util/exclusiveManager.js +135 -0
  116. package/src/vcs/vcm/util/extent.js +124 -0
  117. package/src/vcs/vcm/util/featureProvider/abstractFeatureProvider.js +196 -0
  118. package/src/vcs/vcm/util/featureProvider/featureProviderHelpers.js +51 -0
  119. package/src/vcs/vcm/util/featureProvider/featureProviderSymbols.js +11 -0
  120. package/src/vcs/vcm/util/featureProvider/tileProviderFeatureProvider.js +62 -0
  121. package/src/vcs/vcm/util/featureProvider/wmsFeatureProvider.js +280 -0
  122. package/src/vcs/vcm/util/featureconverter/circleToCesium.js +215 -0
  123. package/src/vcs/vcm/util/featureconverter/convert.js +83 -0
  124. package/src/vcs/vcm/util/featureconverter/extent3d.js +154 -0
  125. package/src/vcs/vcm/util/featureconverter/featureconverterHelper.js +591 -0
  126. package/src/vcs/vcm/util/featureconverter/lineStringToCesium.js +171 -0
  127. package/src/vcs/vcm/util/featureconverter/pointToCesium.js +359 -0
  128. package/src/vcs/vcm/util/featureconverter/polygonToCesium.js +229 -0
  129. package/src/vcs/vcm/util/geometryHelpers.js +172 -0
  130. package/src/vcs/vcm/util/indexedCollection.js +158 -0
  131. package/src/vcs/vcm/util/isMobile.js +12 -0
  132. package/src/vcs/vcm/util/layerCollection.js +216 -0
  133. package/src/vcs/vcm/util/locale.js +53 -0
  134. package/src/vcs/vcm/util/mapCollection.js +363 -0
  135. package/src/vcs/vcm/util/math.js +71 -0
  136. package/src/vcs/vcm/util/projection.js +348 -0
  137. package/src/vcs/vcm/util/splitScreen.js +233 -0
  138. package/src/vcs/vcm/util/style/declarativeStyleItem.js +631 -0
  139. package/src/vcs/vcm/util/style/shapesCategory.js +67 -0
  140. package/src/vcs/vcm/util/style/styleFactory.js +48 -0
  141. package/src/vcs/vcm/util/style/styleHelpers.js +555 -0
  142. package/src/vcs/vcm/util/style/styleItem.js +226 -0
  143. package/src/vcs/vcm/util/style/vectorStyleItem.js +927 -0
  144. package/src/vcs/vcm/util/style/writeStyle.js +48 -0
  145. package/src/vcs/vcm/util/urlHelpers.js +16 -0
  146. package/src/vcs/vcm/util/viewpoint.js +333 -0
@@ -0,0 +1,1192 @@
1
+ import {
2
+ JulianDate,
3
+ Clock,
4
+ DataSourceClock,
5
+ Color,
6
+ CesiumWidget,
7
+ ShadowMode,
8
+ DataSourceDisplay,
9
+ DataSourceCollection,
10
+ RequestScheduler,
11
+ Ellipsoid,
12
+ ScreenSpaceEventHandler,
13
+ Cartesian3,
14
+ Ray,
15
+ Math as CesiumMath,
16
+ Camera,
17
+ BillboardVisualizer,
18
+ LabelVisualizer,
19
+ PointVisualizer,
20
+ CustomDataSource,
21
+ BoundingSphere,
22
+ Intersect,
23
+ CesiumInspector,
24
+ Cesium3DTilesInspector,
25
+ ImageryLayer,
26
+ PrimitiveCollection,
27
+ KeyboardEventModifier,
28
+ ScreenSpaceEventType,
29
+ Cesium3DTileset,
30
+ } from '@vcmap/cesium';
31
+
32
+ import { check, checkMaybe } from '@vcsuite/check';
33
+ import { parseBoolean, parseInteger } from '@vcsuite/parsers';
34
+ import VcsMap from './map.js';
35
+ import ViewPoint from '../util/viewpoint.js';
36
+ import Projection, { mercatorProjection } from '../util/projection.js';
37
+ import { getHeightFromTerrainProvider } from '../layer/terrainHelpers.js';
38
+ import { vcsLayerName } from '../layer/layerSymbols.js';
39
+ import { ModificationKeyType, PointerEventType, PointerKeyType } from '../interaction/interactionType.js';
40
+ import CameraLimiter from './cameraLimiter.js';
41
+ import { VcsClassRegistry } from '../classRegistry.js';
42
+
43
+ /**
44
+ * @typedef {VcsMapOptions} CesiumMapOptions
45
+ * @property {boolean} [enableLightning=true] - if true, lighting will be activated.
46
+ * @property {number} [tileCacheSize=1] - the tilecache size of cesium terrain and tile layer
47
+ * @property {boolean} [webGLaa=false] - activates webGL antialiasing (not every Browser respects this value)
48
+ * @property {CameraLimiterOptions|undefined} cameraLimiter
49
+ * @property {string|undefined} globeColor - the color of the globe, if no image is provided
50
+ * @api
51
+ */
52
+
53
+ /**
54
+ * Ensures, a primitive/imageryLayer/entity is part of a collection and placed at the correct location
55
+ * @param {import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").ImageryLayerCollection} cesiumCollection
56
+ * @param {import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").ImageryLayer|import("@vcmap/cesium").Cesium3DTileset} item
57
+ * @param {import("@vcmap/core").LayerCollection} layerCollection
58
+ * @private
59
+ */
60
+ export function ensureInCollection(cesiumCollection, item, layerCollection) {
61
+ const targetIndex = layerCollection.indexOfKey(item[vcsLayerName]);
62
+ if (targetIndex > -1) {
63
+ // @ts-ignore
64
+ if (!cesiumCollection.contains(item)) {
65
+ const primitivesLength = cesiumCollection.length;
66
+ let index = primitivesLength;
67
+ for (let i = 0; i < primitivesLength; i++) {
68
+ const collectionItem = cesiumCollection.get(i);
69
+ if (layerCollection.indexOfKey(collectionItem[vcsLayerName]) > targetIndex) {
70
+ index = i;
71
+ break;
72
+ }
73
+ }
74
+ // @ts-ignore
75
+ cesiumCollection.add(item, index);
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @param {import("@vcmap/cesium").DataSourceCollection} dataSourceCollection
82
+ * @param {import("@vcmap/cesium").CustomDataSource} dataSource
83
+ * @param {import("@vcmap/core").LayerCollection} layerCollection
84
+ * @private
85
+ */
86
+ export async function ensureInDataSourceCollection(dataSourceCollection, dataSource, layerCollection) {
87
+ const targetIndex = layerCollection.indexOfKey(dataSource[vcsLayerName]);
88
+ if (targetIndex > -1) {
89
+ if (!dataSourceCollection.contains(dataSource)) {
90
+ await dataSourceCollection.add(dataSource);
91
+ }
92
+
93
+ const dataSourceLength = dataSourceCollection.length;
94
+ let index = dataSourceLength;
95
+ for (let i = 0; i < dataSourceLength; i++) {
96
+ const collectionItem = dataSourceCollection.get(i);
97
+ if (layerCollection.indexOfKey(collectionItem[vcsLayerName]) > targetIndex) {
98
+ index = i;
99
+ break;
100
+ }
101
+ }
102
+ let actualIndex = dataSourceCollection.indexOf(dataSource);
103
+
104
+ if (index > actualIndex) {
105
+ index -= 1;
106
+ }
107
+ if (actualIndex < index) {
108
+ while (actualIndex < index) {
109
+ dataSourceCollection.raise(dataSource);
110
+ actualIndex = dataSourceCollection.indexOf(dataSource);
111
+ }
112
+ } else if (actualIndex > index) {
113
+ while (actualIndex > index) {
114
+ dataSourceCollection.lower(dataSource);
115
+ actualIndex = dataSourceCollection.indexOf(dataSource);
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ /**
122
+ * @param {import("@vcmap/cesium").PrimitiveCollection} primitiveCollection
123
+ * @param {import("@vcmap/cesium").PrimitiveCollection} item
124
+ * @param {import("@vcmap/core").LayerCollection} layerCollection
125
+ * @private
126
+ */
127
+ export function indexChangedOnPrimitive(primitiveCollection, item, layerCollection) {
128
+ const { destroyPrimitives } = primitiveCollection;
129
+ primitiveCollection.destroyPrimitives = false;
130
+ primitiveCollection.remove(item);
131
+ ensureInCollection(primitiveCollection, item, layerCollection);
132
+ primitiveCollection.destroyPrimitives = destroyPrimitives;
133
+ }
134
+
135
+ /**
136
+ * @param {import("@vcmap/cesium").ImageryLayerCollection} imageryLayerCollection
137
+ * @param {import("@vcmap/cesium").ImageryLayer} item
138
+ * @param {import("@vcmap/core").LayerCollection} layerCollection
139
+ * @private
140
+ */
141
+ export function indexChangedOnImageryLayer(imageryLayerCollection, item, layerCollection) {
142
+ imageryLayerCollection.remove(item, false);
143
+ ensureInCollection(imageryLayerCollection, item, layerCollection);
144
+ }
145
+
146
+ /**
147
+ * @param {import("@vcmap/cesium").DataSourceCollection} dataSourceCollection
148
+ * @param {import("@vcmap/cesium").CustomDataSource} item
149
+ * @param {import("@vcmap/core").LayerCollection} layerCollection
150
+ * @private
151
+ */
152
+ export function indexChangedOnDataSource(dataSourceCollection, item, layerCollection) {
153
+ ensureInDataSourceCollection(dataSourceCollection, item, layerCollection);
154
+ }
155
+
156
+ /**
157
+ * @param {import("@vcmap/cesium").DataSourceClock} source
158
+ * @param {import("@vcmap/cesium").Clock} target
159
+ * @returns {import("@vcmap/cesium").Event.RemoveCallback}
160
+ * @private
161
+ */
162
+ export function synchronizeClock(source, target) {
163
+ target.clockRange = source.clockRange;
164
+ target.clockStep = source.clockStep;
165
+ target.multiplier = source.multiplier;
166
+ if (!target.startTime || !target.startTime.equals(source.startTime) ||
167
+ !target.stopTime || !target.stopTime.equals(source.stopTime)) {
168
+ target.startTime = source.startTime;
169
+ target.stopTime = source.stopTime;
170
+ target.currentTime = source.currentTime;
171
+ }
172
+ return source.definitionChanged.addEventListener((e, prop, value) => {
173
+ target[prop] = value;
174
+ });
175
+ }
176
+
177
+ /**
178
+ * @param {import("@vcmap/cesium").Cesium3DTileset} cesium3DTileset
179
+ * @param {boolean} debug
180
+ */
181
+ function setDebugOnCesium3DTileset(cesium3DTileset, debug) {
182
+ cesium3DTileset.debugShowRenderingStatistics = debug;
183
+ cesium3DTileset.debugShowBoundingVolume = debug;
184
+ cesium3DTileset.debugShowContentBoundingVolume = debug;
185
+ }
186
+
187
+ /**
188
+ * @param {Array<import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").Cesium3DTileset|import("@vcmap/cesium").ImageryLayer|import("ol/layer/Layer").default|import("@vcmap/cesium").CustomDataSource>} visualizations
189
+ * @param {boolean} debug
190
+ */
191
+ function setDebugOnVisualizations(visualizations, debug) {
192
+ visualizations
193
+ .filter(viz => viz instanceof Cesium3DTileset)
194
+ .forEach(/** @param {import("@vcmap/cesium").Cesium3DTileset} tileset */ (tileset) => {
195
+ setDebugOnCesium3DTileset(tileset, debug);
196
+ });
197
+ }
198
+
199
+ /**
200
+ * Cesium Globe Map Class (3D map)
201
+ * @class
202
+ * @export
203
+ * @extends {VcsMap}
204
+ * @api stable
205
+ */
206
+ class CesiumMap extends VcsMap {
207
+ static get className() { return 'vcs.vcm.maps.Cesium'; }
208
+
209
+ /**
210
+ * @returns {CesiumMapOptions}
211
+ */
212
+ static getDefaultOptions() {
213
+ return {
214
+ ...VcsMap.getDefaultOptions(),
215
+ enableLightning: true,
216
+ tileCacheSize: 1,
217
+ webGLaa: false,
218
+ cameraLimiter: undefined,
219
+ globeColor: '#3f47cc',
220
+ };
221
+ }
222
+
223
+ /**
224
+ * @param {CesiumMapOptions} options
225
+ */
226
+ constructor(options) {
227
+ super(options);
228
+
229
+ const defaultOptions = CesiumMap.getDefaultOptions();
230
+ /**
231
+ * the Cesium Viewer
232
+ * @type {?import("@vcmap/cesium").CesiumWidget}
233
+ * @private
234
+ */
235
+ this._cesiumWidget = null;
236
+
237
+ /**
238
+ * clock for animated data
239
+ * @type {import("@vcmap/cesium").Clock}
240
+ */
241
+ this.dataSourceDisplayClock = new Clock({ shouldAnimate: true });
242
+
243
+ const defaultClock = new DataSourceClock();
244
+ defaultClock.currentTime = this.dataSourceDisplayClock.currentTime;
245
+ /**
246
+ * default clock is set, when no datasource clock is active
247
+ * @type {import("@vcmap/cesium").DataSourceClock}
248
+ * @private
249
+ */
250
+ this._defaultClock = defaultClock;
251
+
252
+ /**
253
+ * clocks of active data sources
254
+ * the last clock of the array corresponds to the active dataSourceDisplayClock
255
+ * @type {Array<import("@vcmap/cesium").DataSourceClock>}
256
+ * @private
257
+ */
258
+ this._dataSourceClocks = [];
259
+
260
+ /**
261
+ * Whether the debug mode is active or not
262
+ * @type {boolean}
263
+ * @api stable
264
+ */
265
+ this.debugMode = false;
266
+
267
+ /** @type {boolean} */
268
+ this.enableLightning = parseBoolean(options.enableLightning, defaultOptions.enableLightning);
269
+
270
+ /** @type {number} */
271
+ this.tileCacheSize = parseInteger(options.tileCacheSize, defaultOptions.tileCacheSize);
272
+
273
+ /** @type {import("@vcmap/cesium").ScreenSpaceEventHandler} */
274
+ this.screenSpaceEventHandler = null;
275
+ /**
276
+ * @type {Array<function():void>}
277
+ * @private
278
+ */
279
+ this._screenSpaceListeners = [];
280
+
281
+ /**
282
+ * @type {import("@vcmap/cesium").JulianDate}
283
+ */
284
+ this.defaultJDate = JulianDate.fromDate(new Date(2014, 6, 20, 13, 0, 0, 0));
285
+
286
+ /** @type {boolean} */
287
+ this.webGLaa = parseBoolean(options.webGLaa, defaultOptions.webGLaa);
288
+
289
+ /**
290
+ * @type {import("@vcmap/cesium").Color}
291
+ * @api
292
+ */
293
+ this.globeColor = Color.fromCssColorString(options.globeColor || defaultOptions.globeColor);
294
+
295
+ /** @type {import("@vcmap/cesium").DataSourceDisplay|null} */
296
+ this._clusterDataSourceDisplay = null;
297
+
298
+ /**
299
+ * @type {import("@vcmap/cesium").TerrainProvider}
300
+ * @private
301
+ */
302
+ this._terrainProvider = null;
303
+
304
+ /**
305
+ * @type {import("@vcmap/cesium").TerrainProvider}
306
+ * @api
307
+ */
308
+ this.defaultTerrainProvider = null;
309
+ /**
310
+ * @type {CameraLimiter|null}
311
+ * @private
312
+ */
313
+ this._cameraLimiter = null;
314
+ /**
315
+ * @type {CameraLimiterOptions}
316
+ * @private
317
+ */
318
+ this._cameraLimiterOptions = options.cameraLimiter || defaultOptions.cameraLimiter;
319
+ /**
320
+ * @type {Function}
321
+ * @private
322
+ */
323
+ this._terrainProviderChangedListener = null;
324
+ /**
325
+ * @type {Function}
326
+ * @private
327
+ */
328
+ this._preUpdateListener = null;
329
+ /**
330
+ * @type {Function}
331
+ * @private
332
+ */
333
+ this._clockTickListener = null;
334
+ /**
335
+ * @type {Function}
336
+ * @private
337
+ */
338
+ this._clockSyncListener = null;
339
+
340
+ /**
341
+ * @type {Function}
342
+ * @private
343
+ */
344
+ this._removeClusterClockTickListener = null;
345
+
346
+ /**
347
+ * @type {boolean}
348
+ * @private
349
+ */
350
+ this._debug = false;
351
+ }
352
+
353
+ /**
354
+ * @returns {import("@vcmap/cesium").TerrainProvider}
355
+ * @api
356
+ * @readonly
357
+ */
358
+ get terrainProvider() {
359
+ return this._terrainProvider;
360
+ }
361
+
362
+ /**
363
+ * A camera limit to not allow the camera to get too close to the globe.
364
+ * @type {CameraLimiter|null}
365
+ * @api
366
+ */
367
+ get cameraLimiter() {
368
+ return this._cameraLimiter;
369
+ }
370
+
371
+ /**
372
+ * @param {CameraLimiter|null} limiter
373
+ */
374
+ set cameraLimiter(limiter) {
375
+ checkMaybe(limiter, CameraLimiter);
376
+
377
+ if (this._cameraLimiter !== limiter) {
378
+ this._cameraLimiter = limiter;
379
+ if (this._cameraLimiter && !this._preUpdateListener && this._cesiumWidget) {
380
+ this._setupPreUpdateListener();
381
+ } else if (!this._cameraLimiter && this._preUpdateListener) {
382
+ this._preUpdateListener();
383
+ this._preUpdateListener = null;
384
+ }
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Show the CesiumInspector and the Cesium3DTileInspector. In addition show the bounding volume on all Cesium3DTilesets
390
+ * plus their rendering statistics.
391
+ * @type {boolean}
392
+ * @api
393
+ */
394
+ get debug() {
395
+ return this._debug;
396
+ }
397
+
398
+ /**
399
+ * @param {boolean} debug
400
+ */
401
+ set debug(debug) {
402
+ check(debug, Boolean);
403
+
404
+ if (this._debug !== debug) {
405
+ this._debug = debug;
406
+ if (this.initialized) {
407
+ this._setDebug();
408
+ }
409
+ }
410
+ }
411
+
412
+ /**
413
+ * @private
414
+ */
415
+ _setupPreUpdateListener() {
416
+ this._preUpdateListener = this._cesiumWidget.scene.preUpdate.addEventListener(() => {
417
+ if (this._cameraLimiter) {
418
+ this._cameraLimiter.limitCamera(this._cesiumWidget.scene.camera);
419
+ }
420
+ });
421
+ }
422
+
423
+ /**
424
+ * @param {ModificationKeyType} key
425
+ * @param {number} pointer
426
+ * @param {PointerEventType} pointerEvent
427
+ * @param {{ position: (import("@vcmap/cesium").Cartesian2|undefined), endPosition: (import("@vcmap/cesium").Cartesian2|undefined) }} csEvent
428
+ * @private
429
+ */
430
+ _raisePointerInteraction(key, pointer, pointerEvent, csEvent) {
431
+ // eslint-disable-next-line
432
+ const multipleTouch = this.screenSpaceEventHandler._positions.length > 1;
433
+ this.pointerInteractionEvent.raiseEvent({
434
+ map: this,
435
+ windowPosition: csEvent.position || csEvent.endPosition,
436
+ key,
437
+ pointer,
438
+ multipleTouch,
439
+ pointerEvent,
440
+ });
441
+ }
442
+
443
+ /**
444
+ * @private
445
+ */
446
+ _setupInteractions() {
447
+ const mods = [
448
+ { csModifier: KeyboardEventModifier.ALT, vcsModifier: ModificationKeyType.ALT },
449
+ { csModifier: KeyboardEventModifier.CTRL, vcsModifier: ModificationKeyType.CTRL },
450
+ { csModifier: KeyboardEventModifier.SHIFT, vcsModifier: ModificationKeyType.SHIFT },
451
+ { csModifier: undefined, vcsModifier: ModificationKeyType.NONE },
452
+ ];
453
+
454
+ const types = [
455
+ { type: ScreenSpaceEventType.LEFT_DOWN, pointerEvent: PointerEventType.DOWN, pointer: PointerKeyType.LEFT },
456
+ { type: ScreenSpaceEventType.LEFT_UP, pointerEvent: PointerEventType.UP, pointer: PointerKeyType.LEFT },
457
+ { type: ScreenSpaceEventType.RIGHT_DOWN, pointerEvent: PointerEventType.DOWN, pointer: PointerKeyType.RIGHT },
458
+ { type: ScreenSpaceEventType.RIGHT_UP, pointerEvent: PointerEventType.UP, pointer: PointerKeyType.RIGHT },
459
+ { type: ScreenSpaceEventType.MIDDLE_DOWN, pointerEvent: PointerEventType.DOWN, pointer: PointerKeyType.MIDDLE },
460
+ { type: ScreenSpaceEventType.MIDDLE_UP, pointerEvent: PointerEventType.UP, pointer: PointerKeyType.MIDDLE },
461
+ { type: ScreenSpaceEventType.MOUSE_MOVE, pointerEvent: PointerEventType.MOVE, pointer: PointerKeyType.ALL },
462
+ ];
463
+
464
+ this._screenSpaceListeners = types.map(({ pointerEvent, pointer, type }) => {
465
+ return mods.map(({ csModifier, vcsModifier }) => {
466
+ this.screenSpaceEventHandler.setInputAction((csEvent) => {
467
+ this._raisePointerInteraction(vcsModifier, pointer, pointerEvent, csEvent);
468
+ }, type, csModifier);
469
+ return () => { this.screenSpaceEventHandler.removeInputAction(type, csModifier); };
470
+ });
471
+ }).flat();
472
+ }
473
+
474
+ /**
475
+ * initializes the map
476
+ * @returns {Promise<void>}
477
+ */
478
+ async initialize() {
479
+ if (!this.initialized) {
480
+ this._cesiumWidget = new CesiumWidget(this.mapElement, {
481
+ requestRenderMode: false,
482
+ scene3DOnly: true,
483
+ imageryProvider: false,
484
+ shadows: false,
485
+ terrainShadows: ShadowMode.ENABLED,
486
+ contextOptions: { webgl: { failIfMajorPerformanceCaveat: false, antialias: this.webGLaa } },
487
+ });
488
+ this._cesiumWidget.scene.globe.tileCacheSize = this.tileCacheSize;
489
+ this._cesiumWidget.scene.globe.baseColor = this.globeColor;
490
+
491
+ /** @type {import("@vcmap/cesium").DataSourceDisplay} */
492
+ this.dataSourceDisplay = new DataSourceDisplay({
493
+ scene: this._cesiumWidget.scene,
494
+ dataSourceCollection: new DataSourceCollection(),
495
+ });
496
+
497
+ this._cesiumWidget.scene.frameState.creditDisplay.update = () => {};
498
+ this._cesiumWidget.scene.frameState.creditDisplay.beginFrame = () => {};
499
+ this._cesiumWidget.scene.frameState.creditDisplay.endFrame = () => {};
500
+
501
+ const { clock } = this._cesiumWidget;
502
+ clock.shouldAnimate = true;
503
+ this._clockTickListener = clock.onTick.addEventListener(() => {
504
+ this.dataSourceDisplayClock.tick();
505
+ const time = this.dataSourceDisplayClock.currentTime;
506
+ this.dataSourceDisplay.update(time);
507
+ });
508
+
509
+ // deactivate cesium Requestthrottling let the browser manage that
510
+ // RequestScheduler.throttleRequests = false;
511
+ RequestScheduler.maximumRequestsPerServer = 12;
512
+
513
+ this._cesiumWidget.scene.shadowMap.maximumDistance = 5000.0;
514
+ this._cesiumWidget.scene.shadowMap.darkness = 0.6;
515
+ this._cesiumWidget.scene.globe.depthTestAgainstTerrain = true;
516
+ this._cesiumWidget.scene.highDynamicRange = false;
517
+ // this._cesiumWidget.scene.logarithmicDepthBuffer = false; // TODO observe this
518
+ this._cesiumWidget.scene.imagerySplitPosition = 0.5;
519
+
520
+ this._cesiumWidget.scene.globe.enableLighting = this.enableLightning;
521
+
522
+ this.setDay(this.defaultJDate);
523
+
524
+ // hide default cesium credits container
525
+ const creditsContainer = document.getElementsByClassName('cesium-widget-credits');
526
+ if (creditsContainer) {
527
+ for (let i = 0; i < creditsContainer.length; i++) {
528
+ const element = /** @type {HTMLElement} */ (creditsContainer[i]);
529
+ element.style.display = 'none';
530
+ }
531
+ }
532
+
533
+ if (this._cameraLimiterOptions && !this._cameraLimiter) {
534
+ this._cameraLimiter = new CameraLimiter(this._cameraLimiterOptions);
535
+ }
536
+
537
+ if (this._cameraLimiter) {
538
+ this._setupPreUpdateListener();
539
+ }
540
+ this.screenSpaceEventHandler = new ScreenSpaceEventHandler(this._cesiumWidget.scene.canvas);
541
+ this._setupInteractions();
542
+ this.initialized = true;
543
+
544
+ this.defaultTerrainProvider = this._cesiumWidget.scene.terrainProvider;
545
+ this._terrainProvider = this.defaultTerrainProvider;
546
+ this._terrainProviderChangedListener =
547
+ this._cesiumWidget.scene.terrainProviderChanged.addEventListener(this._terrainProviderChanged.bind(this));
548
+ if (this._debug) {
549
+ this._setDebug();
550
+ }
551
+ }
552
+ }
553
+
554
+ /**
555
+ * @inheritDoc
556
+ * @returns {Promise<void>}
557
+ */
558
+ async activate() {
559
+ await super.activate();
560
+ if (this.active) {
561
+ this._cesiumWidget.useDefaultRenderLoop = true;
562
+ this._cesiumWidget.resize();
563
+ }
564
+ }
565
+
566
+ /**
567
+ * @inheritDoc
568
+ */
569
+ deactivate() {
570
+ super.deactivate();
571
+ if (this._cesiumWidget) {
572
+ this._cesiumWidget.useDefaultRenderLoop = false;
573
+ }
574
+ }
575
+
576
+ /**
577
+ * getHeight for coordinates
578
+ * @param {Array<import("ol/coordinate").Coordinate>} positions - in web mercator
579
+ * @returns {Promise<Array<import("ol/coordinate").Coordinate>>} the array of coordinates with heights updated in place
580
+ * @api stable
581
+ */
582
+ getHeightFromTerrain(positions) {
583
+ const { terrainProvider } = this._cesiumWidget.scene;
584
+ return terrainProvider.readyPromise.then(() => {
585
+ if (terrainProvider.availability) {
586
+ return getHeightFromTerrainProvider(
587
+ /** @type {import("@vcmap/cesium").CesiumTerrainProvider} */(terrainProvider),
588
+ positions,
589
+ mercatorProjection,
590
+ positions,
591
+ );
592
+ }
593
+ return Promise.resolve(positions);
594
+ });
595
+ }
596
+
597
+ /**
598
+ * @inheritDoc
599
+ * @returns {Promise<null|ViewPoint>}
600
+ */
601
+ async getViewPoint() {
602
+ return this.getViewPointSync();
603
+ }
604
+
605
+ /**
606
+ * @inheritDoc
607
+ * @returns {ViewPoint|null}
608
+ */
609
+ getViewPointSync() {
610
+ if (!this._cesiumWidget || !this._cesiumWidget.scene || !this.target) {
611
+ return null;
612
+ }
613
+ const cam = this._cesiumWidget.scene.camera;
614
+ const cameraPositionCartesian = cam.position;
615
+ let groundPosition = null;
616
+ let distance = null;
617
+ const ray = new Ray(cam.position, cam.direction);
618
+ const groundPositionCartesian = this._cesiumWidget.scene.globe.pick(ray, this._cesiumWidget.scene);
619
+ if (groundPositionCartesian) {
620
+ distance = Cartesian3.distance(groundPositionCartesian, cameraPositionCartesian);
621
+ const groundPositionCartographic = Ellipsoid.WGS84.cartesianToCartographic(groundPositionCartesian);
622
+ groundPosition = [
623
+ CesiumMath.toDegrees(groundPositionCartographic.longitude),
624
+ CesiumMath.toDegrees(groundPositionCartographic.latitude),
625
+ groundPositionCartographic.height,
626
+ ];
627
+ }
628
+
629
+ const cameraPositionCartographic = cam.positionCartographic;
630
+ const cameraPosition = [
631
+ CesiumMath.toDegrees(cameraPositionCartographic.longitude),
632
+ CesiumMath.toDegrees(cameraPositionCartographic.latitude),
633
+ cameraPositionCartographic.height,
634
+ ];
635
+ return new ViewPoint({
636
+ groundPosition,
637
+ cameraPosition,
638
+ distance,
639
+ heading: CesiumMath.toDegrees(cam.heading),
640
+ pitch: CesiumMath.toDegrees(cam.pitch),
641
+ roll: CesiumMath.toDegrees(cam.roll),
642
+ });
643
+ }
644
+
645
+ /**
646
+ * @param {ViewPoint} viewpoint
647
+ * @param {number=} optMaximumHeight
648
+ * @returns {Promise<void>}
649
+ * @inheritDoc
650
+ */
651
+ async gotoViewPoint(viewpoint, optMaximumHeight) {
652
+ if (this.movementDisabled || !viewpoint.isValid()) {
653
+ return;
654
+ }
655
+
656
+ let cameraPosition = null;
657
+ const { distance } = viewpoint;
658
+ const heading = CesiumMath.toRadians(viewpoint.heading);
659
+ const pitch = CesiumMath.toRadians(viewpoint.pitch);
660
+ const roll = CesiumMath.toRadians(viewpoint.roll);
661
+ if (viewpoint.cameraPosition) {
662
+ const cameraCoords = viewpoint.cameraPosition;
663
+ cameraPosition = Cartesian3.fromDegrees(cameraCoords[0], cameraCoords[1], cameraCoords[2]);
664
+ } else {
665
+ if (!viewpoint.groundPosition) {
666
+ return;
667
+ }
668
+ const groundPositionCoords = viewpoint.groundPosition;
669
+ if (!groundPositionCoords[2]) {
670
+ const positions = await this.getHeightFromTerrain([Projection.wgs84ToMercator(groundPositionCoords)]);
671
+ groundPositionCoords[2] = positions[0][2];
672
+ }
673
+ const groundPosition = Cartesian3.fromDegrees(
674
+ groundPositionCoords[0], groundPositionCoords[1], groundPositionCoords[2],
675
+ );
676
+ const clonedCamera = new Camera(this._cesiumWidget.scene);
677
+ const options = {
678
+ destination: groundPosition,
679
+ orientation: {
680
+ heading,
681
+ pitch,
682
+ roll,
683
+ },
684
+ };
685
+ clonedCamera.setView(options);
686
+ clonedCamera.moveBackward(distance);
687
+
688
+ cameraPosition = clonedCamera.position;
689
+ }
690
+ const cam = this._cesiumWidget.scene.camera;
691
+ const cameraOptions = {
692
+ heading,
693
+ pitch,
694
+ roll,
695
+ };
696
+ cameraPosition = cameraPosition || null;
697
+ cam.cancelFlight();
698
+ if (viewpoint.animate) {
699
+ await new Promise((resolve) => {
700
+ const flightOptions = {
701
+ destination: cameraPosition,
702
+ orientation: cameraOptions,
703
+ complete: () => { resolve(); },
704
+ cancel: () => { resolve(); },
705
+ };
706
+
707
+ if (viewpoint.duration) {
708
+ flightOptions.duration = viewpoint.duration;
709
+ }
710
+
711
+ if (viewpoint.easingFunction) {
712
+ flightOptions.easingFunction = viewpoint.easingFunction;
713
+ }
714
+
715
+ if (optMaximumHeight) {
716
+ flightOptions.maximumHeight = optMaximumHeight;
717
+ }
718
+ cam.flyTo(flightOptions);
719
+ });
720
+ } else {
721
+ cam.setView({
722
+ destination: cameraPosition,
723
+ orientation: cameraOptions,
724
+ });
725
+ }
726
+ }
727
+
728
+ /**
729
+ * @inheritDoc
730
+ * @param {import("ol/coordinate").Coordinate} coordinate - in mercator
731
+ * @returns {number}
732
+ */
733
+ getCurrentResolution(coordinate) {
734
+ const cam = this._cesiumWidget.scene.camera;
735
+ const wgs84Coordinate = Projection.mercatorToWgs84(coordinate);
736
+ const distance = Cartesian3
737
+ .distance(Cartesian3.fromDegrees(wgs84Coordinate[0], wgs84Coordinate[1], wgs84Coordinate[2]), cam.position);
738
+
739
+ const fov = Math.PI / 3.0;
740
+ const width = this.mapElement.offsetWidth;
741
+ const height = this.mapElement.offsetHeight;
742
+ const aspectRatio = width / height;
743
+ const fovy = Math.atan(Math.tan(fov * 0.5) / aspectRatio) * 2.0;
744
+ const visibleMeters = 2 * distance * Math.tan(fovy / 2);
745
+ const relativeCircumference = Math.cos(Math.abs(CesiumMath.toRadians(wgs84Coordinate[1])));
746
+ const visibleMapUnits = visibleMeters / relativeCircumference;
747
+
748
+ return visibleMapUnits / height;
749
+ }
750
+
751
+ /**
752
+ * @param {boolean} bool
753
+ * @inheritDoc
754
+ */
755
+ disableMovement(bool) {
756
+ super.disableMovement(bool);
757
+ this._cesiumWidget.scene.screenSpaceCameraController.enableInputs = !bool;
758
+ }
759
+
760
+ /**
761
+ * set dataSource clock as display clock to visualize time dependent animation
762
+ * @param {import("@vcmap/cesium").DataSourceClock} clock
763
+ * @api stable
764
+ */
765
+ setDataSourceDisplayClock(clock) {
766
+ const activeClock = this._dataSourceClocks[this._dataSourceClocks.length - 1];
767
+ if (clock !== activeClock) {
768
+ if (this._clockSyncListener) {
769
+ this._clockSyncListener();
770
+ this._clockSyncListener = null;
771
+ }
772
+ this._clockSyncListener = synchronizeClock(clock, this.dataSourceDisplayClock);
773
+ }
774
+ this._dataSourceClocks.push(clock);
775
+ }
776
+
777
+ /**
778
+ * unset dataSource clock
779
+ * @param {import("@vcmap/cesium").DataSourceClock} clock
780
+ * @api stable
781
+ */
782
+ unsetDataSourceDisplayClock(clock) {
783
+ const idx = this._dataSourceClocks.lastIndexOf(clock);
784
+ if (idx > -1) {
785
+ this._dataSourceClocks.splice(idx, 1);
786
+ if (idx === this._dataSourceClocks.length) {
787
+ const activeClock = this._dataSourceClocks[this._dataSourceClocks.length - 1] || this._defaultClock;
788
+ if (this._clockSyncListener) {
789
+ this._clockSyncListener();
790
+ this._clockSyncListener = null;
791
+ }
792
+ this._clockSyncListener = synchronizeClock(activeClock, this.dataSourceDisplayClock);
793
+ }
794
+ }
795
+ }
796
+
797
+ /**
798
+ * sets the position of the sun according to the day
799
+ * @param {import("@vcmap/cesium").JulianDate} julianDate See the Cesium API
800
+ * @api stable
801
+ */
802
+ setDay(julianDate) {
803
+ this._cesiumWidget.clock.currentTime = julianDate;
804
+ this._cesiumWidget.clock.multiplier = 1;
805
+ }
806
+
807
+ /**
808
+ * sets the lighting of the globe with the sun as a light source
809
+ * @param {boolean} value
810
+ * @api stable
811
+ */
812
+ setLightning(value) {
813
+ this.enableLightning = value;
814
+ this._cesiumWidget.scene.globe.enableLighting = value;
815
+ }
816
+
817
+ /**
818
+ * returns the cesium Widget Object
819
+ * @returns {import("@vcmap/cesium").CesiumWidget}
820
+ * @api stable
821
+ */
822
+ getCesiumWidget() {
823
+ return this._cesiumWidget;
824
+ }
825
+
826
+ /**
827
+ * returns the Entities Collection
828
+ * @returns {import("@vcmap/cesium").EntityCollection}
829
+ * @api stable
830
+ */
831
+ getEntities() {
832
+ return this.dataSourceDisplay.defaultDataSource.entities;
833
+ }
834
+
835
+ /**
836
+ * returns the dataSourceCollection associated with the scene
837
+ * @returns {import("@vcmap/cesium").DataSourceCollection}
838
+ * @api stable
839
+ */
840
+ getDatasources() {
841
+ return this.dataSourceDisplay.dataSources;
842
+ }
843
+
844
+ /**
845
+ * Returns the cluster dataSourceDisplays dataSources.
846
+ * This datasource can only handle Entities with Billboards, Labels or Points.
847
+ * @returns {import("@vcmap/cesium").DataSourceCollection}
848
+ * @api stable
849
+ */
850
+ getClusterDatasources() {
851
+ if (this._clusterDataSourceDisplay) {
852
+ return this._clusterDataSourceDisplay.dataSources;
853
+ }
854
+
855
+ const dataSourceCollection = new DataSourceCollection();
856
+ function visualizersCallback(scene, entityCluster, dataSource) {
857
+ const { entities } = dataSource;
858
+ return [new BillboardVisualizer(entityCluster, entities),
859
+ new LabelVisualizer(entityCluster, entities),
860
+ new PointVisualizer(entityCluster, entities),
861
+ ];
862
+ }
863
+
864
+ this._clusterDataSourceDisplay = new DataSourceDisplay({
865
+ scene: this._cesiumWidget.scene,
866
+ dataSourceCollection,
867
+ visualizersCallback,
868
+ });
869
+
870
+ this._removeClusterClockTickListener =
871
+ this._cesiumWidget.clock.onTick.addEventListener((clock) => {
872
+ this._clusterDataSourceDisplay.update(clock.currentTime);
873
+ });
874
+
875
+ return dataSourceCollection;
876
+ }
877
+
878
+ /**
879
+ * @inheritDoc
880
+ * @param {import("@vcmap/core").Layer} layer
881
+ */
882
+ indexChanged(layer) {
883
+ const viz = this.getVisualizationsForLayer(layer);
884
+ if (viz) {
885
+ viz.forEach((item) => {
886
+ if (item instanceof PrimitiveCollection) {
887
+ indexChangedOnPrimitive(this.getScene().primitives, item, this.layerCollection);
888
+ } else if (item instanceof ImageryLayer) {
889
+ indexChangedOnImageryLayer(this.getScene().imageryLayers, item, this.layerCollection);
890
+ } else if (item instanceof CustomDataSource) {
891
+ indexChangedOnDataSource(this.dataSourceDisplay.dataSources, item, this.layerCollection);
892
+ }
893
+ });
894
+ }
895
+ }
896
+
897
+ /**
898
+ * Internal API used to register visualizations from layer implementations
899
+ * @param {import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").Cesium3DTileset} primitiveCollection
900
+ */
901
+ addPrimitiveCollection(primitiveCollection) {
902
+ if (this.validateVisualization(primitiveCollection)) {
903
+ this.addVisualization(primitiveCollection);
904
+ if (this._debug && primitiveCollection instanceof Cesium3DTileset) {
905
+ setDebugOnCesium3DTileset(primitiveCollection, this._debug);
906
+ }
907
+ ensureInCollection(this.getScene().primitives, primitiveCollection, this.layerCollection);
908
+ }
909
+ }
910
+
911
+ /**
912
+ * Internal API to unregister the visualization for a layers implementation
913
+ * @param {import("@vcmap/cesium").PrimitiveCollection} primitiveCollection
914
+ */
915
+ removePrimitiveCollection(primitiveCollection) { // XXX add destroy as boolean?
916
+ this.removeVisualization(primitiveCollection);
917
+ this.getScene().primitives.remove(primitiveCollection);
918
+ }
919
+
920
+ /**
921
+ * Internal API used to register visualizations from layer implementations
922
+ * @param {import("@vcmap/cesium").ImageryLayer} imageryLayer
923
+ */
924
+ addImageryLayer(imageryLayer) {
925
+ if (this.validateVisualization(imageryLayer)) {
926
+ this.addVisualization(imageryLayer);
927
+ ensureInCollection(this.getScene().imageryLayers, imageryLayer, this.layerCollection);
928
+ }
929
+ }
930
+
931
+ /**
932
+ * Internal API used to unregister visualizations from layer implementations
933
+ * @param {import("@vcmap/cesium").ImageryLayer} imageryLayer
934
+ */
935
+ removeImageryLayer(imageryLayer) {
936
+ this.removeVisualization(imageryLayer);
937
+ this.getScene().imageryLayers.remove(imageryLayer);
938
+ }
939
+
940
+ /**
941
+ * Internal API used to register visualizations from layer implementations
942
+ * @param {import("@vcmap/cesium").CustomDataSource} dataSource
943
+ * @returns {Promise<void>}
944
+ */
945
+ async addDataSource(dataSource) {
946
+ if (this.validateVisualization(dataSource)) {
947
+ this.addVisualization(dataSource);
948
+ await ensureInDataSourceCollection(this.dataSourceDisplay.dataSources, dataSource, this.layerCollection);
949
+ }
950
+ }
951
+
952
+ /**
953
+ * Internal API used to unregister visualizations from layer implementations
954
+ * @param {import("@vcmap/cesium").CustomDataSource} dataSource
955
+ */
956
+ removeDataSource(dataSource) {
957
+ this.removeVisualization(dataSource);
958
+ this.dataSourceDisplay.dataSources.remove(dataSource);
959
+ }
960
+
961
+ /**
962
+ * set the cesium TerrainProvider
963
+ * @param {import("@vcmap/cesium").TerrainProvider} terrainProvider
964
+ * @api
965
+ */
966
+ setTerrainProvider(terrainProvider) {
967
+ if (this.terrainProvider !== terrainProvider) {
968
+ this._cesiumWidget.scene.terrainProvider = terrainProvider;
969
+ }
970
+ }
971
+
972
+ /**
973
+ * unsets the TerrainProvider (changes to the default TerrainProvider if the given terranProvider is currently active)
974
+ * @param {import("@vcmap/cesium").TerrainProvider} terrainProvider
975
+ * @api
976
+ */
977
+ unsetTerrainProvider(terrainProvider) {
978
+ if (this.terrainProvider === terrainProvider) {
979
+ this._terrainProvider = this.defaultTerrainProvider;
980
+ this._cesiumWidget.scene.terrainProvider = this.defaultTerrainProvider;
981
+ }
982
+ }
983
+
984
+ /**
985
+ * returns the cesium DataSourceDisplay Object
986
+ * @returns {import("@vcmap/cesium").DataSourceDisplay}
987
+ * @api stable
988
+ */
989
+ getDataSourceDisplay() {
990
+ return this.dataSourceDisplay;
991
+ }
992
+
993
+ /**
994
+ * returns the cesium Viewer Object
995
+ * @returns {import("@vcmap/cesium").Scene}
996
+ * @api stable
997
+ */
998
+ getScene() {
999
+ return this._cesiumWidget.scene;
1000
+ }
1001
+
1002
+ /**
1003
+ * @returns {import("@vcmap/cesium").CesiumWidget|*}
1004
+ * @deprecated 3.7
1005
+ */
1006
+ getViewer() {
1007
+ this.getLogger().deprecate('getViewer', 'use getCesiumWidget instead.');
1008
+ return this._cesiumWidget;
1009
+ }
1010
+
1011
+ /**
1012
+ * @param {import("ol/coordinate").Coordinate} coords in WGS84 degrees
1013
+ * @returns {boolean}
1014
+ * @api
1015
+ */
1016
+ pointIsVisible(coords) {
1017
+ const { camera } = this._cesiumWidget.scene;
1018
+
1019
+ const target = Cartesian3.fromDegrees(coords[0], coords[1], 0.0);
1020
+ const cullingVolume = camera.frustum.computeCullingVolume(camera.positionWC, camera.directionWC, camera.upWC);
1021
+ if (cullingVolume.computeVisibility(new BoundingSphere(target)) === Intersect.INSIDE) {
1022
+ return true;
1023
+ }
1024
+ return false;
1025
+ }
1026
+
1027
+ // TODO cesium map requestRender
1028
+ /**
1029
+ * sets the Cesium debug mode.
1030
+ * @api stable
1031
+ * @deprecated v4.1
1032
+ */
1033
+ setDebugMode() {
1034
+ this.getLogger().deprecate('setDebugMode', 'set the debug property directly');
1035
+ this.debug = true;
1036
+ }
1037
+
1038
+ /**
1039
+ * @private
1040
+ */
1041
+ _setDebug() {
1042
+ if (this._debug && this.initialized && !this._cesiumInspectorContainer) {
1043
+ this._cesiumInspectorContainer = document.createElement('div');
1044
+ this._cesiumInspectorContainer.className = 'vcm-cesium-inspector';
1045
+ this.mapElement.appendChild(this._cesiumInspectorContainer);
1046
+ this._cesiumInspector = new CesiumInspector(this._cesiumInspectorContainer, this.getScene());
1047
+ this._cesium3DTilesInspector = new Cesium3DTilesInspector(this._cesiumInspectorContainer, this.getScene());
1048
+ this._cesium3DTilesInspector.viewModel.picking = false;
1049
+ }
1050
+
1051
+ if (this._cesiumInspectorContainer) {
1052
+ this._cesiumInspectorContainer.style.display = this.active && this._debug ? '' : 'none';
1053
+ }
1054
+ setDebugOnVisualizations(this.getVisualizations(), this._debug);
1055
+ }
1056
+
1057
+ /**
1058
+ * is called when the cesium Terrainprovider changes. Sets the .terrainProvider and deactivates currently
1059
+ * active Terrain layer if necessary
1060
+ * @param {import("@vcmap/cesium").TerrainProvider} terrainProvider
1061
+ * @private
1062
+ */
1063
+ _terrainProviderChanged(terrainProvider) {
1064
+ if (this.terrainProvider !== terrainProvider) {
1065
+ const layer = this.layerCollection.getByKey(this.terrainProvider[vcsLayerName]);
1066
+ this._terrainProvider = terrainProvider;
1067
+ if (layer) {
1068
+ layer.deactivate();
1069
+ }
1070
+ }
1071
+ }
1072
+
1073
+ /**
1074
+ * returns true if the WEBGL Extension WEBGL_depth_texture is supported. (Is used for picking)
1075
+ * @returns {*}
1076
+ */
1077
+ pickPositionSupported() {
1078
+ if (!this.initialized) {
1079
+ return false;
1080
+ }
1081
+ return this._cesiumWidget.scene.pickPositionSupported;
1082
+ }
1083
+
1084
+ /**
1085
+ * returns true if the WEBGL Extension EXT_frag_depth is supported. (Is used for GroundPoloygons)
1086
+ * @returns {*}
1087
+ */
1088
+ isGroundPrimitiveSupported() {
1089
+ if (!this.initialized) {
1090
+ return false;
1091
+ }
1092
+ return this._cesiumWidget.scene.context.fragmentDepth;
1093
+ }
1094
+
1095
+ /**
1096
+ * @returns {CesiumMapOptions}
1097
+ * @api
1098
+ */
1099
+ getConfigObject() {
1100
+ const config = /** @type {CesiumMapOptions} */ (super.getConfigObject());
1101
+ const defaultOptions = CesiumMap.getDefaultOptions();
1102
+
1103
+ if (this.enableLightning !== defaultOptions.enableLightning) {
1104
+ config.enableLightning = this.enableLightning;
1105
+ }
1106
+
1107
+ if (this.tileCacheSize !== defaultOptions.tileCacheSize) {
1108
+ config.tileCacheSize = this.tileCacheSize;
1109
+ }
1110
+
1111
+ if (this.webGLaa !== defaultOptions.webGLaa) {
1112
+ config.webGLaa = this.webGLaa;
1113
+ }
1114
+
1115
+ if (this.globeColor.toCssHexString() !== defaultOptions.globeColor) {
1116
+ config.globeColor = this.globeColor.toCssHexString();
1117
+ }
1118
+
1119
+ if (this._cameraLimiter) {
1120
+ config.cameraLimiter = this._cameraLimiter.getConfigObject();
1121
+ } else if (this._cameraLimiterOptions && !this.initialized) {
1122
+ config.cameraLimiter = this._cameraLimiterOptions;
1123
+ }
1124
+
1125
+ return config;
1126
+ }
1127
+
1128
+ /**
1129
+ * @api
1130
+ */
1131
+ destroy() {
1132
+ if (this.dataSourceDisplay && !this.dataSourceDisplay.isDestroyed()) {
1133
+ this.dataSourceDisplay.destroy();
1134
+ }
1135
+ this._screenSpaceListeners.forEach((cb) => { cb(); });
1136
+ if (this.screenSpaceEventHandler) {
1137
+ this.screenSpaceEventHandler.destroy();
1138
+ this.screenSpaceEventHandler = null;
1139
+ }
1140
+ if (this._terrainProviderChangedListener) {
1141
+ this._terrainProviderChangedListener();
1142
+ this._terrainProviderChangedListener = null;
1143
+ }
1144
+ this._terrainProvider = null;
1145
+ this.defaultTerrainProvider = null;
1146
+
1147
+ if (this._clockTickListener) {
1148
+ this._clockTickListener();
1149
+ this._clockTickListener = null;
1150
+ }
1151
+
1152
+ if (this._clockSyncListener) {
1153
+ this._clockSyncListener();
1154
+ this._clockSyncListener = null;
1155
+ }
1156
+
1157
+ if (this._preUpdateListener) {
1158
+ this._preUpdateListener();
1159
+ this._preUpdateListener = null;
1160
+ }
1161
+
1162
+ if (this._cameraLimiter) {
1163
+ this._cameraLimiter = null;
1164
+ }
1165
+ if (this._removeClusterClockTickListener) {
1166
+ this._removeClusterClockTickListener();
1167
+ }
1168
+ if (this._clusterDataSourceDisplay) {
1169
+ this._clusterDataSourceDisplay.destroy();
1170
+ }
1171
+ if (this._cesiumWidget) {
1172
+ this._cesiumWidget.destroy();
1173
+ this._cesiumWidget = null;
1174
+ }
1175
+ if (this._cesium3DTilesInspector) {
1176
+ this._cesium3DTilesInspector.destroy();
1177
+ this._cesium3DTilesInspector = null;
1178
+ }
1179
+ if (this._cesiumInspector) {
1180
+ this._cesiumInspector.destroy();
1181
+ this._cesiumInspector = null;
1182
+ }
1183
+ if (this._cesiumInspectorContainer) {
1184
+ this._cesiumInspectorContainer.parentElement.removeChild(this._cesiumInspectorContainer);
1185
+ this._cesiumInspectorContainer = null;
1186
+ }
1187
+ super.destroy();
1188
+ }
1189
+ }
1190
+
1191
+ VcsClassRegistry.registerClass(CesiumMap.className, CesiumMap);
1192
+ export default CesiumMap;