@vcmap/core 6.0.0-rc.9 → 6.0.1

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 (207) hide show
  1. package/README.md +4 -1
  2. package/dist/cesium.d.ts +117 -0
  3. package/dist/index.d.ts +14 -6
  4. package/dist/index.js +12 -4
  5. package/dist/index.js.map +1 -1
  6. package/dist/ol.d.ts +1 -0
  7. package/dist/src/cesium/cesium3DTileFeature.d.ts +2 -1
  8. package/dist/src/cesium/cesium3DTileFeature.js +13 -1
  9. package/dist/src/cesium/cesium3DTileFeature.js.map +1 -1
  10. package/dist/src/cesium/cesium3DTilePointFeature.js +2 -0
  11. package/dist/src/cesium/cesium3DTilePointFeature.js.map +1 -1
  12. package/dist/src/cesium/entity.js +3 -0
  13. package/dist/src/cesium/entity.js.map +1 -1
  14. package/dist/src/interaction/featureAtPixelInteraction.d.ts +4 -12
  15. package/dist/src/interaction/featureAtPixelInteraction.js +6 -27
  16. package/dist/src/interaction/featureAtPixelInteraction.js.map +1 -1
  17. package/dist/src/layer/cesium/openStreetMapCesiumImpl.js +2 -4
  18. package/dist/src/layer/cesium/openStreetMapCesiumImpl.js.map +1 -1
  19. package/dist/src/layer/cesium/rasterLayerCesiumImpl.d.ts +4 -0
  20. package/dist/src/layer/cesium/rasterLayerCesiumImpl.js +15 -0
  21. package/dist/src/layer/cesium/rasterLayerCesiumImpl.js.map +1 -1
  22. package/dist/src/layer/cesium/singleImageCesiumImpl.js +2 -6
  23. package/dist/src/layer/cesium/singleImageCesiumImpl.js.map +1 -1
  24. package/dist/src/layer/cesium/terrainCesiumImpl.js +3 -0
  25. package/dist/src/layer/cesium/terrainCesiumImpl.js.map +1 -1
  26. package/dist/src/layer/cesium/tmsCesiumImpl.js +1 -4
  27. package/dist/src/layer/cesium/tmsCesiumImpl.js.map +1 -1
  28. package/dist/src/layer/cesium/vcsTile/vcsChildTile.d.ts +12 -0
  29. package/dist/src/layer/cesium/vcsTile/vcsChildTile.js +18 -0
  30. package/dist/src/layer/cesium/vcsTile/vcsChildTile.js.map +1 -0
  31. package/dist/src/layer/cesium/vcsTile/vcsDebugTile.d.ts +21 -0
  32. package/dist/src/layer/cesium/vcsTile/vcsDebugTile.js +89 -0
  33. package/dist/src/layer/cesium/vcsTile/vcsDebugTile.js.map +1 -0
  34. package/dist/src/layer/cesium/vcsTile/vcsNoDataTile.d.ts +11 -0
  35. package/dist/src/layer/cesium/vcsTile/vcsNoDataTile.js +17 -0
  36. package/dist/src/layer/cesium/vcsTile/vcsNoDataTile.js.map +1 -0
  37. package/dist/src/layer/cesium/vcsTile/vcsQuadtreeTileProvider.d.ts +39 -0
  38. package/dist/src/layer/cesium/vcsTile/vcsQuadtreeTileProvider.js +192 -0
  39. package/dist/src/layer/cesium/vcsTile/vcsQuadtreeTileProvider.js.map +1 -0
  40. package/dist/src/layer/cesium/vcsTile/vcsTileHelpers.d.ts +52 -0
  41. package/dist/src/layer/cesium/vcsTile/vcsTileHelpers.js +73 -0
  42. package/dist/src/layer/cesium/vcsTile/vcsTileHelpers.js.map +1 -0
  43. package/dist/src/layer/cesium/vcsTile/vcsVectorTile.d.ts +23 -0
  44. package/dist/src/layer/cesium/vcsTile/vcsVectorTile.js +87 -0
  45. package/dist/src/layer/cesium/vcsTile/vcsVectorTile.js.map +1 -0
  46. package/dist/src/layer/cesium/vectorCesiumImpl.js +1 -1
  47. package/dist/src/layer/cesium/vectorCesiumImpl.js.map +1 -1
  48. package/dist/src/layer/cesium/vectorTileCesiumImpl.d.ts +19 -0
  49. package/dist/src/layer/cesium/vectorTileCesiumImpl.js +63 -0
  50. package/dist/src/layer/cesium/vectorTileCesiumImpl.js.map +1 -0
  51. package/dist/src/layer/cesium/wmsCesiumImpl.js +1 -4
  52. package/dist/src/layer/cesium/wmsCesiumImpl.js.map +1 -1
  53. package/dist/src/layer/cesium/wmtsCesiumImpl.js +1 -4
  54. package/dist/src/layer/cesium/wmtsCesiumImpl.js.map +1 -1
  55. package/dist/src/layer/layer.d.ts +5 -0
  56. package/dist/src/layer/layer.js +5 -0
  57. package/dist/src/layer/layer.js.map +1 -1
  58. package/dist/src/layer/openStreetMapLayer.d.ts +32 -2
  59. package/dist/src/layer/openStreetMapLayer.js +35 -1
  60. package/dist/src/layer/openStreetMapLayer.js.map +1 -1
  61. package/dist/src/layer/openlayers/openStreetMapOpenlayersImpl.js +2 -0
  62. package/dist/src/layer/openlayers/openStreetMapOpenlayersImpl.js.map +1 -1
  63. package/dist/src/layer/openlayers/rasterLayerOpenlayersImpl.d.ts +2 -0
  64. package/dist/src/layer/openlayers/rasterLayerOpenlayersImpl.js +4 -0
  65. package/dist/src/layer/openlayers/rasterLayerOpenlayersImpl.js.map +1 -1
  66. package/dist/src/layer/openlayers/singleImageOpenlayersImpl.js +2 -0
  67. package/dist/src/layer/openlayers/singleImageOpenlayersImpl.js.map +1 -1
  68. package/dist/src/layer/openlayers/tmsOpenlayersImpl.js +2 -0
  69. package/dist/src/layer/openlayers/tmsOpenlayersImpl.js.map +1 -1
  70. package/dist/src/layer/openlayers/vectorTileOpenlayersImpl.d.ts +1 -7
  71. package/dist/src/layer/openlayers/vectorTileOpenlayersImpl.js +3 -35
  72. package/dist/src/layer/openlayers/vectorTileOpenlayersImpl.js.map +1 -1
  73. package/dist/src/layer/openlayers/wmsOpenlayersImpl.js +4 -0
  74. package/dist/src/layer/openlayers/wmsOpenlayersImpl.js.map +1 -1
  75. package/dist/src/layer/openlayers/wmtsOpenlayersImpl.js +2 -0
  76. package/dist/src/layer/openlayers/wmtsOpenlayersImpl.js.map +1 -1
  77. package/dist/src/layer/pointCloudLayer.d.ts +0 -1
  78. package/dist/src/layer/pointCloudLayer.js +2 -3
  79. package/dist/src/layer/pointCloudLayer.js.map +1 -1
  80. package/dist/src/layer/rasterLayer.d.ts +44 -3
  81. package/dist/src/layer/rasterLayer.js +43 -0
  82. package/dist/src/layer/rasterLayer.js.map +1 -1
  83. package/dist/src/layer/tileProvider/mvtTileProvider.d.ts +0 -5
  84. package/dist/src/layer/tileProvider/mvtTileProvider.js +0 -12
  85. package/dist/src/layer/tileProvider/mvtTileProvider.js.map +1 -1
  86. package/dist/src/layer/tileProvider/staticFeatureTileProvider.d.ts +14 -0
  87. package/dist/src/layer/tileProvider/staticFeatureTileProvider.js +44 -0
  88. package/dist/src/layer/tileProvider/staticFeatureTileProvider.js.map +1 -0
  89. package/dist/src/layer/tileProvider/tileProvider.d.ts +8 -2
  90. package/dist/src/layer/tileProvider/tileProvider.js +17 -1
  91. package/dist/src/layer/tileProvider/tileProvider.js.map +1 -1
  92. package/dist/src/layer/vectorLayer.d.ts +1 -1
  93. package/dist/src/layer/vectorLayer.js.map +1 -1
  94. package/dist/src/layer/vectorTileLayer.d.ts +13 -3
  95. package/dist/src/layer/vectorTileLayer.js +43 -13
  96. package/dist/src/layer/vectorTileLayer.js.map +1 -1
  97. package/dist/src/map/cesiumMap.d.ts +8 -1
  98. package/dist/src/map/cesiumMap.js +17 -6
  99. package/dist/src/map/cesiumMap.js.map +1 -1
  100. package/dist/src/ol/feature.js +7 -0
  101. package/dist/src/ol/feature.js.map +1 -1
  102. package/dist/src/style/declarativeStyleItem.js +2 -68
  103. package/dist/src/style/declarativeStyleItem.js.map +1 -1
  104. package/dist/src/util/displayQuality/displayQuality.d.ts +1 -0
  105. package/dist/src/util/displayQuality/displayQuality.js +12 -1
  106. package/dist/src/util/displayQuality/displayQuality.js.map +1 -1
  107. package/dist/src/util/editor/createFeatureSession.d.ts +8 -4
  108. package/dist/src/util/editor/createFeatureSession.js +35 -11
  109. package/dist/src/util/editor/createFeatureSession.js.map +1 -1
  110. package/dist/src/util/editor/editGeometrySession.d.ts +2 -1
  111. package/dist/src/util/editor/editGeometrySession.js +33 -12
  112. package/dist/src/util/editor/editGeometrySession.js.map +1 -1
  113. package/dist/src/util/editor/editorHelpers.d.ts +1 -0
  114. package/dist/src/util/editor/editorHelpers.js +6 -0
  115. package/dist/src/util/editor/editorHelpers.js.map +1 -1
  116. package/dist/src/util/editor/editorSessionHelpers.d.ts +1 -6
  117. package/dist/src/util/editor/editorSessionHelpers.js +5 -16
  118. package/dist/src/util/editor/editorSessionHelpers.js.map +1 -1
  119. package/dist/src/util/editor/interactions/editGeometryMouseOverInteraction.js +3 -2
  120. package/dist/src/util/editor/interactions/editGeometryMouseOverInteraction.js.map +1 -1
  121. package/dist/src/util/editor/interactions/removeVertexInteraction.d.ts +1 -1
  122. package/dist/src/util/editor/interactions/removeVertexInteraction.js +2 -2
  123. package/dist/src/util/editor/interactions/removeVertexInteraction.js.map +1 -1
  124. package/dist/src/util/editor/interactions/segmentLengthInteraction.d.ts +16 -0
  125. package/dist/src/util/editor/interactions/segmentLengthInteraction.js +167 -0
  126. package/dist/src/util/editor/interactions/segmentLengthInteraction.js.map +1 -0
  127. package/dist/src/util/editor/interactions/translateVertexInteraction.js +2 -6
  128. package/dist/src/util/editor/interactions/translateVertexInteraction.js.map +1 -1
  129. package/dist/src/util/editor/interactions/translationSnapping.js +3 -2
  130. package/dist/src/util/editor/interactions/translationSnapping.js.map +1 -1
  131. package/dist/src/util/featureconverter/clampedPrimitive.d.ts +2 -2
  132. package/dist/src/util/featureconverter/clampedPrimitive.js +24 -2
  133. package/dist/src/util/featureconverter/clampedPrimitive.js.map +1 -1
  134. package/dist/src/util/featureconverter/convert.js +12 -3
  135. package/dist/src/util/featureconverter/convert.js.map +1 -1
  136. package/dist/src/util/geometryHelpers.d.ts +9 -1
  137. package/dist/src/util/geometryHelpers.js +54 -4
  138. package/dist/src/util/geometryHelpers.js.map +1 -1
  139. package/dist/src/util/math.d.ts +12 -0
  140. package/dist/src/util/math.js +21 -0
  141. package/dist/src/util/math.js.map +1 -1
  142. package/dist/src/util/projection.js +1 -1
  143. package/dist/src/util/projection.js.map +1 -1
  144. package/dist/src/vcsModule.d.ts +12 -12
  145. package/dist/src/vcsModule.js +8 -8
  146. package/dist/src/vcsModule.js.map +1 -1
  147. package/dist/tests/unit/helpers/cesiumHelpers.d.ts +2 -2
  148. package/dist/tests/unit/helpers/cesiumHelpers.js +2 -1
  149. package/dist/tests/unit/helpers/cesiumHelpers.js.map +1 -1
  150. package/index.ts +26 -2
  151. package/package.json +3 -3
  152. package/src/cesium/cesium.d.ts +117 -0
  153. package/src/cesium/cesium3DTileFeature.ts +20 -1
  154. package/src/cesium/cesium3DTilePointFeature.ts +3 -0
  155. package/src/cesium/entity.ts +7 -0
  156. package/src/interaction/featureAtPixelInteraction.ts +8 -39
  157. package/src/layer/cesium/openStreetMapCesiumImpl.ts +2 -4
  158. package/src/layer/cesium/rasterLayerCesiumImpl.ts +19 -0
  159. package/src/layer/cesium/singleImageCesiumImpl.ts +2 -6
  160. package/src/layer/cesium/terrainCesiumImpl.ts +3 -0
  161. package/src/layer/cesium/tmsCesiumImpl.ts +1 -4
  162. package/src/layer/cesium/vcsTile/vcsChildTile.ts +31 -0
  163. package/src/layer/cesium/vcsTile/vcsDebugTile.ts +154 -0
  164. package/src/layer/cesium/vcsTile/vcsNoDataTile.ts +30 -0
  165. package/src/layer/cesium/vcsTile/vcsQuadtreeTileProvider.ts +290 -0
  166. package/src/layer/cesium/vcsTile/vcsTileHelpers.ts +134 -0
  167. package/src/layer/cesium/vcsTile/vcsVectorTile.ts +149 -0
  168. package/src/layer/cesium/vectorCesiumImpl.ts +1 -1
  169. package/src/layer/cesium/vectorTileCesiumImpl.ts +91 -0
  170. package/src/layer/cesium/wmsCesiumImpl.ts +1 -4
  171. package/src/layer/cesium/wmtsCesiumImpl.ts +1 -4
  172. package/src/layer/layer.ts +5 -0
  173. package/src/layer/openStreetMapLayer.ts +64 -2
  174. package/src/layer/openlayers/openStreetMapOpenlayersImpl.ts +2 -0
  175. package/src/layer/openlayers/rasterLayerOpenlayersImpl.ts +6 -0
  176. package/src/layer/openlayers/singleImageOpenlayersImpl.ts +2 -0
  177. package/src/layer/openlayers/tmsOpenlayersImpl.ts +2 -0
  178. package/src/layer/openlayers/vectorTileOpenlayersImpl.ts +3 -37
  179. package/src/layer/openlayers/wmsOpenlayersImpl.ts +4 -0
  180. package/src/layer/openlayers/wmtsOpenlayersImpl.ts +2 -0
  181. package/src/layer/pointCloudLayer.ts +2 -3
  182. package/src/layer/rasterLayer.ts +81 -2
  183. package/src/layer/tileProvider/mvtTileProvider.ts +0 -18
  184. package/src/layer/tileProvider/staticFeatureTileProvider.ts +61 -0
  185. package/src/layer/tileProvider/tileProvider.ts +27 -2
  186. package/src/layer/vectorLayer.ts +1 -1
  187. package/src/layer/vectorTileLayer.ts +72 -17
  188. package/src/map/cesiumMap.ts +28 -6
  189. package/src/ol/feature.ts +10 -0
  190. package/src/ol/ol.d.ts +1 -0
  191. package/src/style/declarativeStyleItem.ts +2 -72
  192. package/src/util/displayQuality/displayQuality.ts +13 -1
  193. package/src/util/editor/createFeatureSession.ts +51 -13
  194. package/src/util/editor/editGeometrySession.ts +41 -10
  195. package/src/util/editor/editorHelpers.ts +13 -0
  196. package/src/util/editor/editorSessionHelpers.ts +6 -20
  197. package/src/util/editor/interactions/editGeometryMouseOverInteraction.ts +4 -4
  198. package/src/util/editor/interactions/removeVertexInteraction.ts +3 -4
  199. package/src/util/editor/interactions/segmentLengthInteraction.ts +227 -0
  200. package/src/util/editor/interactions/translateVertexInteraction.ts +3 -10
  201. package/src/util/editor/interactions/translationSnapping.ts +4 -4
  202. package/src/util/featureconverter/clampedPrimitive.ts +53 -5
  203. package/src/util/featureconverter/convert.ts +18 -2
  204. package/src/util/geometryHelpers.ts +63 -4
  205. package/src/util/math.ts +28 -0
  206. package/src/util/projection.ts +1 -1
  207. package/src/vcsModule.ts +20 -20
@@ -5,7 +5,6 @@ import {
5
5
  Cesium3DTileFeature,
6
6
  Cesium3DTilePointFeature,
7
7
  Entity,
8
- CesiumWidget,
9
8
  } from '@vcmap-cesium/engine';
10
9
  import type { Feature } from 'ol/index.js';
11
10
  import type { Layer as OLLayer } from 'ol/layer.js';
@@ -30,9 +29,10 @@ import type CesiumMap from '../map/cesiumMap.js';
30
29
  * @group Interaction
31
30
  */
32
31
  class FeatureAtPixelInteraction extends AbstractInteraction {
33
- private _pickPosition = EventType.CLICK;
34
-
35
- private _pickPositionMask = -1;
32
+ /**
33
+ * event type for which to pick the position of the scene. this will create a second render.
34
+ */
35
+ pickPosition = EventType.CLICK;
36
36
 
37
37
  /**
38
38
  * whether to pick translucent depth or not, defaults to true
@@ -60,30 +60,8 @@ class FeatureAtPixelInteraction extends AbstractInteraction {
60
60
  this.setActive();
61
61
  }
62
62
 
63
- /**
64
- * Bitmask of {@link EventType} for which events to pick the position
65
- */
66
- get pickPosition(): EventType {
67
- return this._pickPosition;
68
- }
69
-
70
- set pickPosition(position: EventType) {
71
- this._pickPosition = position & this._pickPositionMask;
72
- }
73
-
74
- /**
75
- * Bitmask of for which to never pick positions.
76
- */
77
- get excludedPickPositionEvents(): number {
78
- return ~this._pickPositionMask;
79
- }
80
-
81
- set excludedPickPositionEvents(position: number) {
82
- this._pickPositionMask = ~position;
83
- }
84
-
85
63
  async pipe(event: InteractionEvent): Promise<InteractionEvent> {
86
- if (event.type & EventType.DRAG && !(this._pickPosition & EventType.DRAG)) {
64
+ if (event.type & EventType.DRAG && !(this.pickPosition & EventType.DRAG)) {
87
65
  if (this._draggingFeature) {
88
66
  event.feature = this._draggingFeature;
89
67
  }
@@ -209,6 +187,7 @@ class FeatureAtPixelInteraction extends AbstractInteraction {
209
187
  scratchCartesian = new Cartesian3();
210
188
  return Promise.resolve(event);
211
189
  }
190
+
212
191
  if (this.pullPickedPosition && event.ray) {
213
192
  scratchPullCartesian = Cartesian3.multiplyByScalar(
214
193
  event.ray.direction,
@@ -227,6 +206,7 @@ class FeatureAtPixelInteraction extends AbstractInteraction {
227
206
  scene.globe.ellipsoid,
228
207
  scratchCartographic,
229
208
  );
209
+
230
210
  event.position = Projection.wgs84ToMercator(
231
211
  [
232
212
  CesiumMath.toDegrees(scratchCartographic.longitude),
@@ -277,19 +257,8 @@ class FeatureAtPixelInteraction extends AbstractInteraction {
277
257
  }
278
258
 
279
259
  if (scene.pickPositionSupported) {
280
- if (
281
- object.primitive &&
282
- this.pickTranslucent &&
283
- !(
284
- object.primitive.pointCloudShading &&
285
- object.primitive.pointCloudShading.attenuation
286
- )
287
- ) {
288
- // XXX should this always be on, also for non vector?
260
+ if (object.primitive && this.pickTranslucent) {
289
261
  scene.pickTranslucentDepth = true;
290
- scene.render(
291
- (cesiumMap.getCesiumWidget() as CesiumWidget).clock.currentTime,
292
- );
293
262
  event.exactPosition = true;
294
263
  }
295
264
  scratchCartesian = scene.pickPosition(
@@ -13,13 +13,11 @@ class OpenStreetMapCesiumImpl extends RasterLayerCesiumImpl {
13
13
  }
14
14
 
15
15
  getCesiumLayer(): Promise<CesiumImageryLayer> {
16
+ const layerOptions = this.getCesiumLayerOptions();
16
17
  return Promise.resolve(
17
18
  new CesiumImageryLayer(
18
19
  new OpenStreetMapImageryProvider({ maximumLevel: this.maxLevel }),
19
- {
20
- alpha: this.opacity,
21
- splitDirection: this.splitDirection,
22
- },
20
+ layerOptions,
23
21
  ),
24
22
  );
25
23
  }
@@ -25,20 +25,29 @@ class RasterLayerCesiumImpl
25
25
 
26
26
  maxLevel: number;
27
27
 
28
+ minRenderingLevel: number | undefined;
29
+
30
+ maxRenderingLevel: number | undefined;
31
+
28
32
  extent: Extent | undefined;
29
33
 
30
34
  opacity: number;
31
35
 
32
36
  tilingSchema: TilingScheme;
33
37
 
38
+ imageryLayerOptions: ImageryLayer.ConstructorOptions | undefined;
39
+
34
40
  constructor(map: CesiumMap, options: RasterLayerImplementationOptions) {
35
41
  super(map, options);
36
42
  this.splitDirection = options.splitDirection;
37
43
  this.minLevel = options.minLevel;
38
44
  this.maxLevel = options.maxLevel;
45
+ this.minRenderingLevel = options.minRenderingLevel;
46
+ this.maxRenderingLevel = options.maxRenderingLevel;
39
47
  this.extent = options.extent;
40
48
  this.opacity = options.opacity;
41
49
  this.tilingSchema = options.tilingSchema;
50
+ this.imageryLayerOptions = options.imageryLayerOptions;
42
51
  }
43
52
 
44
53
  async initialize(): Promise<void> {
@@ -62,6 +71,16 @@ class RasterLayerCesiumImpl
62
71
  }
63
72
  }
64
73
 
74
+ getCesiumLayerOptions(): ImageryLayer.ConstructorOptions {
75
+ return {
76
+ ...this.imageryLayerOptions,
77
+ alpha: this.opacity,
78
+ splitDirection: this.splitDirection,
79
+ minimumTerrainLevel: this.minRenderingLevel,
80
+ maximumTerrainLevel: this.maxRenderingLevel,
81
+ };
82
+ }
83
+
65
84
  // eslint-disable-next-line class-methods-use-this
66
85
  getCesiumLayer(): Promise<ImageryLayer> {
67
86
  throw new Error('implementation error');
@@ -43,12 +43,8 @@ class SingleImageCesiumImpl extends RasterLayerCesiumImpl {
43
43
  getResourceOrUrl(this.url!, this.headers),
44
44
  options,
45
45
  );
46
- const layerOptions = {
47
- rectangle: options.rectangle,
48
- alpha: this.opacity,
49
- defaultAlpha: 1.0,
50
- splitDirection: this.splitDirection,
51
- };
46
+ const layerOptions = this.getCesiumLayerOptions();
47
+ layerOptions.rectangle = options.rectangle;
52
48
  return new ImageryLayer(imageryProvider, layerOptions);
53
49
  }
54
50
  }
@@ -56,6 +56,9 @@ class TerrainCesiumImpl extends LayerImplementation<CesiumMap> {
56
56
  }
57
57
 
58
58
  destroy(): void {
59
+ if (this.terrainProvider) {
60
+ this.map.unsetTerrainProvider(this.terrainProvider);
61
+ }
59
62
  this.terrainProvider = undefined;
60
63
  super.destroy();
61
64
  }
@@ -52,11 +52,8 @@ class TmsCesiumImpl extends RasterLayerCesiumImpl {
52
52
  getResourceOrUrl(this.url!, this.headers),
53
53
  options,
54
54
  );
55
- const layerOptions = {
56
- alpha: this.opacity,
57
- splitDirection: this.splitDirection,
58
- };
59
55
 
56
+ const layerOptions = this.getCesiumLayerOptions();
60
57
  return new CesiumImageryLayer(imageryProvider, layerOptions);
61
58
  }
62
59
  }
@@ -0,0 +1,31 @@
1
+ import { QuadtreeTile, TileBoundingRegion } from '@vcmap-cesium/engine';
2
+ import {
3
+ getTileBoundingRegion,
4
+ VcsTile,
5
+ VcsTileState,
6
+ VcsTileType,
7
+ } from './vcsTileHelpers.js';
8
+ import type CesiumMap from '../../../map/cesiumMap.js';
9
+
10
+ export default class VcsChildTile implements VcsTile {
11
+ state = VcsTileState.LOADING;
12
+
13
+ type = VcsTileType.CHILD;
14
+
15
+ tileBoundingRegion: TileBoundingRegion;
16
+
17
+ private _tile: QuadtreeTile<VcsTile>;
18
+
19
+ constructor(tile: QuadtreeTile<VcsTile>, map: CesiumMap) {
20
+ this.tileBoundingRegion = getTileBoundingRegion(tile, map);
21
+ this.state = VcsTileState.READY;
22
+ this._tile = tile;
23
+ }
24
+
25
+ get show(): boolean {
26
+ return this._tile.parent?.data?.show ?? false;
27
+ }
28
+
29
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/no-empty-function
30
+ set show(_show: boolean) {}
31
+ }
@@ -0,0 +1,154 @@
1
+ import {
2
+ PrimitiveCollection,
3
+ QuadtreeTile,
4
+ SplitDirection,
5
+ TileBoundingRegion,
6
+ } from '@vcmap-cesium/engine';
7
+ import { getLogger } from '@vcsuite/logger';
8
+ import { Feature } from 'ol';
9
+ import { Point } from 'ol/geom.js';
10
+ import { getCenter } from 'ol/extent.js';
11
+ import { fromExtent } from 'ol/geom/Polygon.js';
12
+ import { Style, Text as OLText } from 'ol/style.js';
13
+ import { StyleLike } from 'ol/style/Style.js';
14
+ import VectorContext from '../vectorContext.js';
15
+ import { vcsLayerName } from '../../layerSymbols.js';
16
+ import {
17
+ getTileBoundingRegion,
18
+ getTileHash,
19
+ getTileWgs84Extent,
20
+ VcsTile,
21
+ VcsTileOptions,
22
+ VcsTileState,
23
+ VcsTileType,
24
+ } from './vcsTileHelpers.js';
25
+ import Projection, {
26
+ mercatorProjection,
27
+ wgs84Projection,
28
+ } from '../../../util/projection.js';
29
+ import { createSync } from '../../vectorSymbols.js';
30
+ import VectorProperties from '../../vectorProperties.js';
31
+ import CesiumMap from '../../../map/cesiumMap.js';
32
+ import { TileProvider } from '../../../../index.js';
33
+
34
+ let vectorProperties: VectorProperties | undefined;
35
+ function getDebugVectorProperties(): VectorProperties {
36
+ if (!vectorProperties) {
37
+ vectorProperties = new VectorProperties({});
38
+ }
39
+ return vectorProperties;
40
+ }
41
+
42
+ export default class VcsDebugTile implements VcsTile {
43
+ state = VcsTileState.LOADING;
44
+
45
+ type = VcsTileType.DEBUG;
46
+
47
+ tileBoundingRegion: TileBoundingRegion;
48
+
49
+ private _tile: QuadtreeTile<VcsTile>;
50
+
51
+ private _vectorContext: VectorContext;
52
+
53
+ private _rootCollection = new PrimitiveCollection();
54
+
55
+ private _extentFeature: Feature | undefined;
56
+
57
+ private _map: CesiumMap;
58
+
59
+ private _tileProvider: TileProvider;
60
+
61
+ private _style: StyleLike;
62
+
63
+ private _layerPrimitiveCollection: PrimitiveCollection;
64
+
65
+ constructor(tile: QuadtreeTile<VcsTile>, options: VcsTileOptions) {
66
+ this._tile = tile;
67
+ this._map = options.map;
68
+ this._tileProvider = options.tileProvider;
69
+ this._style = options.style;
70
+ this._layerPrimitiveCollection = options.primitiveCollection;
71
+
72
+ this._vectorContext = new VectorContext(
73
+ this._map,
74
+ this._rootCollection,
75
+ SplitDirection.NONE,
76
+ );
77
+ this._rootCollection[vcsLayerName] = options.name;
78
+ this._rootCollection.show = false;
79
+ this._layerPrimitiveCollection.add(this._rootCollection);
80
+
81
+ this.tileBoundingRegion = getTileBoundingRegion(tile, this._map);
82
+ this._load().catch(() => {
83
+ this.state = VcsTileState.FAILED;
84
+ });
85
+ }
86
+
87
+ private async _load(): Promise<void> {
88
+ this.state = VcsTileState.LOADING;
89
+ const scene = this._map.getScene()!;
90
+ this.state = VcsTileState.PROCESSING;
91
+
92
+ const tileExtent = getTileWgs84Extent(
93
+ this._tile,
94
+ this._tileProvider.tilingScheme,
95
+ );
96
+
97
+ const label = new Feature({
98
+ geometry: new Point(Projection.wgs84ToMercator(getCenter(tileExtent))),
99
+ olcs_altitudeMode: 'relativeToGround',
100
+ olcs_heightAboveGround: 5,
101
+ });
102
+
103
+ label.setStyle(
104
+ new Style({
105
+ text: new OLText({
106
+ text: `${this._tile.level}/${this._tile.x}/${this._tile.y}`,
107
+ }),
108
+ }),
109
+ );
110
+
111
+ this._extentFeature = new Feature({
112
+ geometry: fromExtent(tileExtent).transform(
113
+ wgs84Projection.proj,
114
+ mercatorProjection.proj,
115
+ ),
116
+ });
117
+ this._extentFeature[createSync] = true;
118
+
119
+ const features: Feature[] = [this._extentFeature, label];
120
+
121
+ await Promise.all(
122
+ features.map((f) => {
123
+ return this._vectorContext.addFeature(
124
+ f,
125
+ f.getStyle() ?? this._style,
126
+ getDebugVectorProperties(),
127
+ scene,
128
+ );
129
+ }),
130
+ );
131
+ this.state = VcsTileState.READY;
132
+ }
133
+
134
+ get show(): boolean {
135
+ return this._rootCollection.show;
136
+ }
137
+
138
+ set show(show: boolean) {
139
+ this._rootCollection.show = show;
140
+ }
141
+
142
+ freeResources(): void {
143
+ getLogger('VcsDebugTile').log(
144
+ `freeing resources: ${getTileHash(this._tile)}`,
145
+ );
146
+ this.destroy();
147
+ }
148
+
149
+ destroy(): void {
150
+ this._vectorContext.destroy();
151
+ this._layerPrimitiveCollection.remove(this._rootCollection);
152
+ this._tile.data = undefined;
153
+ }
154
+ }
@@ -0,0 +1,30 @@
1
+ import { QuadtreeTile, TileBoundingRegion } from '@vcmap-cesium/engine';
2
+ import type CesiumMap from '../../../map/cesiumMap.js';
3
+ import {
4
+ getTileBoundingRegion,
5
+ VcsTile,
6
+ VcsTileState,
7
+ VcsTileType,
8
+ } from './vcsTileHelpers.js';
9
+
10
+ export default class VcsNoDataTile implements VcsTile {
11
+ state = VcsTileState.LOADING;
12
+
13
+ type = VcsTileType.NO_DATA;
14
+
15
+ tileBoundingRegion: TileBoundingRegion;
16
+
17
+ constructor(tile: QuadtreeTile<VcsTile>, map: CesiumMap) {
18
+ this.tileBoundingRegion = getTileBoundingRegion(tile, map);
19
+
20
+ this.state = VcsTileState.READY;
21
+ }
22
+
23
+ // eslint-disable-next-line class-methods-use-this
24
+ get show(): boolean {
25
+ return false;
26
+ }
27
+
28
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/no-empty-function
29
+ set show(_show: boolean) {}
30
+ }
@@ -0,0 +1,290 @@
1
+ import {
2
+ Cartesian3,
3
+ Event as CesiumEvent,
4
+ FrameState,
5
+ Intersect,
6
+ Math as CesiumMath,
7
+ PrimitiveCollection,
8
+ QuadtreePrimitive,
9
+ QuadtreeTile,
10
+ QuadtreeTileLoadState,
11
+ QuadtreeTileProvider,
12
+ QuadtreeTileProviderInterface,
13
+ SplitDirection,
14
+ TilingScheme,
15
+ Visibility,
16
+ } from '@vcmap-cesium/engine';
17
+ import { intersects, Extent as OLExtent } from 'ol/extent.js';
18
+ import { parseBoolean } from '@vcsuite/parsers';
19
+ import { wgs84Projection } from '../../../util/projection.js';
20
+ import {
21
+ getDataTiles,
22
+ getTileHash,
23
+ getTileWgs84Extent,
24
+ VcsTile,
25
+ VcsTileOptions,
26
+ VcsTileState,
27
+ VcsTileType,
28
+ } from './vcsTileHelpers.js';
29
+ import VcsVectorTile from './vcsVectorTile.js';
30
+ import VcsNoDataTile from './vcsNoDataTile.js';
31
+ import VcsDebugTile from './vcsDebugTile.js';
32
+ import VcsChildTile from './vcsChildTile.js';
33
+ import { VectorTileImplementationOptions } from '../../vectorTileLayer.js';
34
+ import CesiumMap from '../../../map/cesiumMap.js';
35
+ import StyleItem from '../../../style/styleItem.js';
36
+
37
+ const tileDirectionScratch = new Cartesian3();
38
+
39
+ export default class VcsQuadtreeTileProvider
40
+ implements QuadtreeTileProviderInterface
41
+ {
42
+ // eslint-disable-next-line class-methods-use-this
43
+ get className(): string {
44
+ return 'VcsQuadtreeTileProvider';
45
+ }
46
+
47
+ quadtree: QuadtreePrimitive | undefined;
48
+
49
+ readonly tilingScheme: TilingScheme;
50
+
51
+ readonly errorEvent = new CesiumEvent();
52
+
53
+ private _destroyed = false;
54
+
55
+ private _levelZeroMaximumError: number;
56
+
57
+ private _tileOptions: VcsTileOptions;
58
+
59
+ private _showingTiles = new Set<string>();
60
+
61
+ private _dataLevels: Set<number>;
62
+
63
+ private _dataRange: [number, number];
64
+
65
+ private _extentWgs84: OLExtent | undefined;
66
+
67
+ private _debug = false;
68
+
69
+ constructor(
70
+ map: CesiumMap,
71
+ primitiveCollection: PrimitiveCollection,
72
+ layerOptions: VectorTileImplementationOptions,
73
+ ) {
74
+ this._tileOptions = {
75
+ map,
76
+ primitiveCollection,
77
+ style: layerOptions.style.style,
78
+ name: layerOptions.name,
79
+ tileProvider: layerOptions.tileProvider,
80
+ vectorProperties: layerOptions.vectorProperties,
81
+ splitDirection: layerOptions.splitDirection,
82
+ };
83
+
84
+ this._debug = parseBoolean(layerOptions.debug, false);
85
+
86
+ this.tilingScheme = layerOptions.tileProvider.tilingScheme;
87
+ this._levelZeroMaximumError =
88
+ QuadtreeTileProvider.computeDefaultLevelZeroMaximumGeometricError(
89
+ this.tilingScheme,
90
+ );
91
+
92
+ const { dataLevels, dataRange } = getDataTiles(
93
+ layerOptions.minLevel,
94
+ layerOptions.maxLevel,
95
+ layerOptions.tileProvider,
96
+ );
97
+ this._dataLevels = dataLevels;
98
+ this._dataRange = dataRange;
99
+ const vcsExtent = layerOptions.extent;
100
+
101
+ if (vcsExtent?.isValid()) {
102
+ this._extentWgs84 =
103
+ vcsExtent?.getCoordinatesInProjection(wgs84Projection);
104
+ }
105
+ }
106
+
107
+ private _withinDataRange(tile: QuadtreeTile): boolean {
108
+ if (tile.level >= this._dataRange[0] && tile.level <= this._dataRange[1]) {
109
+ if (this._extentWgs84) {
110
+ const tileExtent = getTileWgs84Extent(tile, this.tilingScheme);
111
+ return intersects(tileExtent, this._extentWgs84);
112
+ }
113
+ return true;
114
+ }
115
+
116
+ return false;
117
+ }
118
+
119
+ private _initializeTile(tile: QuadtreeTile<VcsTile>): void {
120
+ if (tile.state === QuadtreeTileLoadState.START) {
121
+ if (!tile.data) {
122
+ if (this._withinDataRange(tile)) {
123
+ if (this._dataLevels.has(tile.level)) {
124
+ tile.data = this._debug
125
+ ? new VcsDebugTile(tile, this._tileOptions)
126
+ : new VcsVectorTile(tile, this._tileOptions);
127
+ } else {
128
+ tile.data = new VcsChildTile(tile, this._tileOptions.map);
129
+ }
130
+ } else {
131
+ tile.data = new VcsNoDataTile(tile, this._tileOptions.map);
132
+ }
133
+ }
134
+
135
+ tile.state = QuadtreeTileLoadState.LOADING;
136
+ }
137
+ }
138
+
139
+ updateStyle(style: StyleItem): void {
140
+ this._tileOptions.style = style.style;
141
+ }
142
+
143
+ updateSplitDirection(direction: SplitDirection): void {
144
+ this._tileOptions.splitDirection = direction;
145
+ }
146
+
147
+ update(frameState: FrameState): void {
148
+ this.quadtree?.beginFrame(frameState);
149
+ this.quadtree?.render(frameState);
150
+ this.quadtree?.endFrame(frameState);
151
+ }
152
+
153
+ endUpdate(_frameState: FrameState): void {
154
+ this.quadtree?.forEachLoadedTile((t: QuadtreeTile<VcsTile>) => {
155
+ if (t.data) {
156
+ t.data.show = this._showingTiles.has(getTileHash(t));
157
+ }
158
+ });
159
+ this._showingTiles.clear();
160
+ }
161
+
162
+ getLevelMaximumGeometricError(level: number): number {
163
+ return this._levelZeroMaximumError / (1 << level);
164
+ }
165
+
166
+ loadTile(_frameState: FrameState, tile: QuadtreeTile<VcsTile>): void {
167
+ this._initializeTile(tile);
168
+
169
+ if (tile.data?.state === VcsTileState.READY) {
170
+ tile.renderable = true;
171
+ tile.state = QuadtreeTileLoadState.DONE;
172
+ } else if (tile.data?.state === VcsTileState.FAILED) {
173
+ tile.state = QuadtreeTileLoadState.FAILED;
174
+ }
175
+ }
176
+
177
+ computeTileLoadPriority(
178
+ tile: QuadtreeTile<VcsTile>,
179
+ frameState: FrameState,
180
+ ): number {
181
+ const vcsTile = tile.data;
182
+ if (vcsTile === undefined) {
183
+ return 0.0;
184
+ }
185
+
186
+ const obb = vcsTile.tileBoundingRegion.boundingVolume;
187
+ if (obb === undefined) {
188
+ return 0.0;
189
+ }
190
+
191
+ const cameraPosition = frameState.camera.positionWC;
192
+ const cameraDirection = frameState.camera.directionWC;
193
+ const tileDirection = Cartesian3.subtract(
194
+ obb.center,
195
+ cameraPosition,
196
+ tileDirectionScratch,
197
+ );
198
+ const magnitude = Cartesian3.magnitude(tileDirection);
199
+ if (magnitude < CesiumMath.EPSILON5) {
200
+ return 0.0;
201
+ }
202
+ Cartesian3.divideByScalar(tileDirection, magnitude, tileDirection);
203
+ return (
204
+ (1.0 - Cartesian3.dot(tileDirection, cameraDirection)) *
205
+ // eslint-disable-next-line no-underscore-dangle
206
+ (tile._distance ?? this.computeDistanceToTile(tile, frameState))
207
+ );
208
+ }
209
+
210
+ computeTileVisibility(
211
+ tile: QuadtreeTile<VcsTile>,
212
+ frameState: FrameState,
213
+ ): Visibility {
214
+ const distance = this.computeDistanceToTile(tile, frameState);
215
+ // eslint-disable-next-line no-underscore-dangle
216
+ tile._distance = distance;
217
+
218
+ if (frameState.fog) {
219
+ if (CesiumMath.fog(distance, frameState.fog.density) >= 1.0) {
220
+ // Tile is completely in fog so return that it is not visible.
221
+ return Visibility.NONE;
222
+ }
223
+ }
224
+
225
+ let visibility = Visibility.NONE;
226
+ const boundingVolume = tile.data?.tileBoundingRegion.boundingVolume;
227
+ if (boundingVolume) {
228
+ const intersection =
229
+ frameState.cullingVolume.computeVisibility(boundingVolume);
230
+
231
+ if (intersection === Intersect.OUTSIDE) {
232
+ visibility = Visibility.NONE;
233
+ } else if (intersection === Intersect.INTERSECTING) {
234
+ visibility = Visibility.PARTIAL;
235
+ } else if (intersection === Intersect.INSIDE) {
236
+ visibility = Visibility.FULL;
237
+ }
238
+ }
239
+
240
+ return visibility;
241
+ }
242
+
243
+ // eslint-disable-next-line class-methods-use-this
244
+ showTileThisFrame(tile: QuadtreeTile<VcsTile>): void {
245
+ let tileToShow: QuadtreeTile<VcsTile> | undefined = tile;
246
+ while (tileToShow?.data?.type === VcsTileType.CHILD) {
247
+ tileToShow = tileToShow.parent;
248
+ }
249
+
250
+ if (tileToShow?.data) {
251
+ this._showingTiles.add(getTileHash(tileToShow));
252
+ }
253
+ }
254
+
255
+ computeDistanceToTile(
256
+ tile: QuadtreeTile<VcsTile>,
257
+ frameState: FrameState,
258
+ ): number {
259
+ this._initializeTile(tile);
260
+
261
+ return (
262
+ tile.data?.tileBoundingRegion.distanceToCamera(frameState) ?? 9999999999.0
263
+ );
264
+ }
265
+
266
+ canRefine(tile: QuadtreeTile): boolean {
267
+ return tile.level < this._dataRange[1];
268
+ }
269
+
270
+ isDestroyed(): boolean {
271
+ return this._destroyed;
272
+ }
273
+
274
+ // eslint-disable-next-line class-methods-use-this
275
+ cancelReprojections(): void {}
276
+
277
+ // eslint-disable-next-line class-methods-use-this
278
+ initialize(_f: FrameState): void {}
279
+
280
+ // eslint-disable-next-line class-methods-use-this
281
+ beginUpdate(_frameState: FrameState): void {}
282
+
283
+ // eslint-disable-next-line class-methods-use-this
284
+ updateForPick(_frameState: FrameState): void {}
285
+
286
+ destroy(): void {
287
+ this._destroyed = true;
288
+ this._showingTiles.clear();
289
+ }
290
+ }