@vcmap/core 6.0.0-rc.4 → 6.0.0-rc.6

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 (209) hide show
  1. package/dist/cesium.d.ts +11 -0
  2. package/dist/index.d.ts +23 -16
  3. package/dist/index.js +21 -14
  4. package/dist/index.js.map +1 -1
  5. package/dist/ol.d.ts +15 -2
  6. package/dist/src/layer/cesium/clusterContext.d.ts +8 -14
  7. package/dist/src/layer/cesium/clusterContext.js +62 -41
  8. package/dist/src/layer/cesium/clusterContext.js.map +1 -1
  9. package/dist/src/layer/cesium/vectorCesiumImpl.d.ts +2 -3
  10. package/dist/src/layer/cesium/vectorCesiumImpl.js +16 -10
  11. package/dist/src/layer/cesium/vectorCesiumImpl.js.map +1 -1
  12. package/dist/src/layer/cesium/vectorContext.d.ts +10 -53
  13. package/dist/src/layer/cesium/vectorContext.js +88 -172
  14. package/dist/src/layer/cesium/vectorContext.js.map +1 -1
  15. package/dist/src/layer/geojsonHelpers.d.ts +1 -1
  16. package/dist/src/layer/geojsonHelpers.js +5 -10
  17. package/dist/src/layer/geojsonHelpers.js.map +1 -1
  18. package/dist/src/layer/oblique/obliqueHelpers.js +6 -6
  19. package/dist/src/layer/oblique/obliqueHelpers.js.map +1 -1
  20. package/dist/src/layer/vectorLayer.d.ts +0 -37
  21. package/dist/src/layer/vectorLayer.js.map +1 -1
  22. package/dist/src/layer/vectorProperties.d.ts +8 -3
  23. package/dist/src/layer/vectorProperties.js +30 -5
  24. package/dist/src/layer/vectorProperties.js.map +1 -1
  25. package/dist/src/map/baseOLMap.js +1 -1
  26. package/dist/src/map/baseOLMap.js.map +1 -1
  27. package/dist/src/map/obliqueMap.d.ts +3 -0
  28. package/dist/src/map/obliqueMap.js +27 -6
  29. package/dist/src/map/obliqueMap.js.map +1 -1
  30. package/dist/src/map/vcsMap.d.ts +8 -0
  31. package/dist/src/map/vcsMap.js +11 -0
  32. package/dist/src/map/vcsMap.js.map +1 -1
  33. package/dist/src/oblique/helpers.js +5 -5
  34. package/dist/src/oblique/helpers.js.map +1 -1
  35. package/dist/src/oblique/obliqueDataSet.js +4 -4
  36. package/dist/src/oblique/obliqueDataSet.js.map +1 -1
  37. package/dist/src/ol/geom/geometryCollection.js +19 -2
  38. package/dist/src/ol/geom/geometryCollection.js.map +1 -1
  39. package/dist/src/style/arcStyle.js +1 -0
  40. package/dist/src/style/arcStyle.js.map +1 -1
  41. package/dist/src/util/editor/createFeatureSession.d.ts +5 -1
  42. package/dist/src/util/editor/createFeatureSession.js +48 -4
  43. package/dist/src/util/editor/createFeatureSession.js.map +1 -1
  44. package/dist/src/util/editor/editFeaturesSession.d.ts +10 -4
  45. package/dist/src/util/editor/editFeaturesSession.js +74 -37
  46. package/dist/src/util/editor/editFeaturesSession.js.map +1 -1
  47. package/dist/src/util/editor/editGeometrySession.d.ts +5 -1
  48. package/dist/src/util/editor/editGeometrySession.js +77 -55
  49. package/dist/src/util/editor/editGeometrySession.js.map +1 -1
  50. package/dist/src/util/editor/editorHelpers.d.ts +12 -6
  51. package/dist/src/util/editor/editorHelpers.js +47 -20
  52. package/dist/src/util/editor/editorHelpers.js.map +1 -1
  53. package/dist/src/util/editor/editorSessionHelpers.d.ts +5 -0
  54. package/dist/src/util/editor/editorSessionHelpers.js +1 -0
  55. package/dist/src/util/editor/editorSessionHelpers.js.map +1 -1
  56. package/dist/src/util/editor/editorSymbols.d.ts +1 -1
  57. package/dist/src/util/editor/editorSymbols.js +1 -1
  58. package/dist/src/util/editor/editorSymbols.js.map +1 -1
  59. package/dist/src/util/editor/interactions/createBBoxInteraction.d.ts +1 -0
  60. package/dist/src/util/editor/interactions/createBBoxInteraction.js +20 -16
  61. package/dist/src/util/editor/interactions/createBBoxInteraction.js.map +1 -1
  62. package/dist/src/util/editor/interactions/createCircleInteraction.js +1 -1
  63. package/dist/src/util/editor/interactions/createCircleInteraction.js.map +1 -1
  64. package/dist/src/util/editor/interactions/createLineStringInteraction.js +3 -3
  65. package/dist/src/util/editor/interactions/createLineStringInteraction.js.map +1 -1
  66. package/dist/src/util/editor/interactions/createPointInteraction.js +1 -1
  67. package/dist/src/util/editor/interactions/createPointInteraction.js.map +1 -1
  68. package/dist/src/util/editor/interactions/createPolygonInteraction.d.ts +4 -0
  69. package/dist/src/util/editor/interactions/createPolygonInteraction.js +9 -3
  70. package/dist/src/util/editor/interactions/createPolygonInteraction.js.map +1 -1
  71. package/dist/src/util/editor/interactions/creationSnapping.d.ts +26 -0
  72. package/dist/src/util/editor/interactions/creationSnapping.js +139 -0
  73. package/dist/src/util/editor/interactions/creationSnapping.js.map +1 -0
  74. package/dist/src/util/editor/interactions/editGeometryMouseOverInteraction.js +3 -2
  75. package/dist/src/util/editor/interactions/editGeometryMouseOverInteraction.js.map +1 -1
  76. package/dist/src/util/editor/interactions/insertVertexInteraction.d.ts +3 -1
  77. package/dist/src/util/editor/interactions/insertVertexInteraction.js +14 -6
  78. package/dist/src/util/editor/interactions/insertVertexInteraction.js.map +1 -1
  79. package/dist/src/util/editor/interactions/layerSnapping.d.ts +19 -0
  80. package/dist/src/util/editor/interactions/layerSnapping.js +87 -0
  81. package/dist/src/util/editor/interactions/layerSnapping.js.map +1 -0
  82. package/dist/src/util/editor/interactions/translateVertexInteraction.js +2 -2
  83. package/dist/src/util/editor/interactions/translateVertexInteraction.js.map +1 -1
  84. package/dist/src/util/editor/interactions/translationSnapping.d.ts +25 -0
  85. package/dist/src/util/editor/interactions/translationSnapping.js +179 -0
  86. package/dist/src/util/editor/interactions/translationSnapping.js.map +1 -0
  87. package/dist/src/util/editor/snappingHelpers.d.ts +44 -0
  88. package/dist/src/util/editor/snappingHelpers.js +329 -0
  89. package/dist/src/util/editor/snappingHelpers.js.map +1 -0
  90. package/dist/src/util/editor/transformation/create2DHandlers.js +26 -26
  91. package/dist/src/util/editor/transformation/create2DHandlers.js.map +1 -1
  92. package/dist/src/util/editor/transformation/create3DHandlers.js +65 -14
  93. package/dist/src/util/editor/transformation/create3DHandlers.js.map +1 -1
  94. package/dist/src/util/editor/transformation/scaleInteraction.js +27 -5
  95. package/dist/src/util/editor/transformation/scaleInteraction.js.map +1 -1
  96. package/dist/src/util/editor/transformation/transformationHandler.js +56 -38
  97. package/dist/src/util/editor/transformation/transformationHandler.js.map +1 -1
  98. package/dist/src/util/editor/transformation/transformationTypes.d.ts +2 -0
  99. package/dist/src/util/editor/transformation/transformationTypes.js +4 -0
  100. package/dist/src/util/editor/transformation/transformationTypes.js.map +1 -1
  101. package/dist/src/util/featureconverter/arcToCesium.d.ts +5 -19
  102. package/dist/src/util/featureconverter/arcToCesium.js +15 -42
  103. package/dist/src/util/featureconverter/arcToCesium.js.map +1 -1
  104. package/dist/src/util/featureconverter/circleToCesium.d.ts +2 -27
  105. package/dist/src/util/featureconverter/circleToCesium.js +84 -63
  106. package/dist/src/util/featureconverter/circleToCesium.js.map +1 -1
  107. package/dist/src/util/featureconverter/clampedPrimitive.d.ts +2 -0
  108. package/dist/src/util/featureconverter/clampedPrimitive.js +29 -0
  109. package/dist/src/util/featureconverter/clampedPrimitive.js.map +1 -0
  110. package/dist/src/util/featureconverter/convert.d.ts +26 -7
  111. package/dist/src/util/featureconverter/convert.js +221 -44
  112. package/dist/src/util/featureconverter/convert.js.map +1 -1
  113. package/dist/src/util/featureconverter/extent3D.d.ts +4 -3
  114. package/dist/src/util/featureconverter/extent3D.js +4 -3
  115. package/dist/src/util/featureconverter/extent3D.js.map +1 -1
  116. package/dist/src/util/featureconverter/lineStringToCesium.d.ts +12 -27
  117. package/dist/src/util/featureconverter/lineStringToCesium.js +85 -107
  118. package/dist/src/util/featureconverter/lineStringToCesium.js.map +1 -1
  119. package/dist/src/util/featureconverter/pointHelpers.d.ts +8 -11
  120. package/dist/src/util/featureconverter/pointHelpers.js +134 -120
  121. package/dist/src/util/featureconverter/pointHelpers.js.map +1 -1
  122. package/dist/src/util/featureconverter/pointToCesium.d.ts +14 -17
  123. package/dist/src/util/featureconverter/pointToCesium.js +47 -96
  124. package/dist/src/util/featureconverter/pointToCesium.js.map +1 -1
  125. package/dist/src/util/featureconverter/polygonToCesium.d.ts +2 -26
  126. package/dist/src/util/featureconverter/polygonToCesium.js +62 -72
  127. package/dist/src/util/featureconverter/polygonToCesium.js.map +1 -1
  128. package/dist/src/util/featureconverter/storeyHelpers.d.ts +17 -0
  129. package/dist/src/util/featureconverter/storeyHelpers.js +78 -0
  130. package/dist/src/util/featureconverter/storeyHelpers.js.map +1 -0
  131. package/dist/src/util/featureconverter/vectorGeometryFactory.d.ts +54 -0
  132. package/dist/src/util/featureconverter/vectorGeometryFactory.js +278 -0
  133. package/dist/src/util/featureconverter/vectorGeometryFactory.js.map +1 -0
  134. package/dist/src/util/featureconverter/vectorHeightInfo.d.ts +86 -0
  135. package/dist/src/util/featureconverter/vectorHeightInfo.js +242 -0
  136. package/dist/src/util/featureconverter/vectorHeightInfo.js.map +1 -0
  137. package/dist/src/util/geometryHelpers.d.ts +22 -1
  138. package/dist/src/util/geometryHelpers.js +65 -2
  139. package/dist/src/util/geometryHelpers.js.map +1 -1
  140. package/dist/src/util/mapCollection.js +8 -0
  141. package/dist/src/util/mapCollection.js.map +1 -1
  142. package/dist/src/util/math.d.ts +6 -2
  143. package/dist/src/util/math.js +34 -12
  144. package/dist/src/util/math.js.map +1 -1
  145. package/dist/tests/unit/helpers/cesiumHelpers.js +3 -1
  146. package/dist/tests/unit/helpers/cesiumHelpers.js.map +1 -1
  147. package/dist/tests/unit/helpers/helpers.d.ts +2 -9
  148. package/dist/tests/unit/helpers/helpers.js +2 -8
  149. package/dist/tests/unit/helpers/helpers.js.map +1 -1
  150. package/index.ts +74 -35
  151. package/package.json +3 -3
  152. package/src/cesium/cesium.d.ts +11 -0
  153. package/src/layer/cesium/clusterContext.ts +82 -91
  154. package/src/layer/cesium/vectorCesiumImpl.ts +17 -11
  155. package/src/layer/cesium/vectorContext.ts +120 -348
  156. package/src/layer/geojsonHelpers.ts +9 -12
  157. package/src/layer/oblique/obliqueHelpers.ts +6 -6
  158. package/src/layer/vectorLayer.ts +0 -71
  159. package/src/layer/vectorProperties.ts +46 -9
  160. package/src/map/baseOLMap.ts +1 -1
  161. package/src/map/obliqueMap.ts +46 -6
  162. package/src/map/vcsMap.ts +20 -2
  163. package/src/oblique/helpers.ts +11 -5
  164. package/src/oblique/obliqueDataSet.ts +4 -4
  165. package/src/ol/geom/geometryCollection.js +21 -2
  166. package/src/ol/ol.d.ts +15 -2
  167. package/src/style/arcStyle.ts +1 -0
  168. package/src/util/editor/createFeatureSession.ts +64 -6
  169. package/src/util/editor/editFeaturesSession.ts +105 -39
  170. package/src/util/editor/editGeometrySession.ts +118 -75
  171. package/src/util/editor/editorHelpers.ts +78 -30
  172. package/src/util/editor/editorSessionHelpers.ts +7 -0
  173. package/src/util/editor/editorSymbols.ts +1 -1
  174. package/src/util/editor/interactions/createBBoxInteraction.ts +25 -16
  175. package/src/util/editor/interactions/createCircleInteraction.ts +1 -1
  176. package/src/util/editor/interactions/createLineStringInteraction.ts +9 -3
  177. package/src/util/editor/interactions/createPointInteraction.ts +1 -1
  178. package/src/util/editor/interactions/createPolygonInteraction.ts +16 -3
  179. package/src/util/editor/interactions/creationSnapping.ts +226 -0
  180. package/src/util/editor/interactions/editGeometryMouseOverInteraction.ts +3 -2
  181. package/src/util/editor/interactions/insertVertexInteraction.ts +27 -7
  182. package/src/util/editor/interactions/layerSnapping.ts +136 -0
  183. package/src/util/editor/interactions/translateVertexInteraction.ts +8 -2
  184. package/src/util/editor/interactions/translationSnapping.ts +302 -0
  185. package/src/util/editor/snappingHelpers.ts +490 -0
  186. package/src/util/editor/transformation/create2DHandlers.ts +38 -26
  187. package/src/util/editor/transformation/create3DHandlers.ts +84 -22
  188. package/src/util/editor/transformation/scaleInteraction.ts +28 -5
  189. package/src/util/editor/transformation/transformationHandler.ts +72 -41
  190. package/src/util/editor/transformation/transformationTypes.ts +5 -0
  191. package/src/util/featureconverter/arcToCesium.ts +25 -95
  192. package/src/util/featureconverter/circleToCesium.ts +127 -113
  193. package/src/util/featureconverter/clampedPrimitive.ts +70 -0
  194. package/src/util/featureconverter/convert.ts +446 -114
  195. package/src/util/featureconverter/extent3D.ts +13 -6
  196. package/src/util/featureconverter/lineStringToCesium.ts +132 -179
  197. package/src/util/featureconverter/pointHelpers.ts +271 -214
  198. package/src/util/featureconverter/pointToCesium.ts +111 -175
  199. package/src/util/featureconverter/polygonToCesium.ts +98 -117
  200. package/src/util/featureconverter/storeyHelpers.ts +104 -0
  201. package/src/util/featureconverter/vectorGeometryFactory.ts +601 -0
  202. package/src/util/featureconverter/vectorHeightInfo.ts +393 -0
  203. package/src/util/geometryHelpers.ts +79 -5
  204. package/src/util/mapCollection.ts +8 -0
  205. package/src/util/math.ts +59 -12
  206. package/dist/src/util/featureconverter/featureconverterHelper.d.ts +0 -35
  207. package/dist/src/util/featureconverter/featureconverterHelper.js +0 -404
  208. package/dist/src/util/featureconverter/featureconverterHelper.js.map +0 -1
  209. package/src/util/featureconverter/featureconverterHelper.ts +0 -672
@@ -1,43 +1,28 @@
1
1
  import {
2
- PrimitiveCollection,
2
+ type Billboard,
3
3
  BillboardCollection,
4
- LabelCollection,
5
- Matrix4,
6
4
  Cartesian3,
7
- Math as CesiumMath,
8
- Model,
9
- type Primitive,
10
- type GroundPrimitive,
11
- type GroundPolylinePrimitive,
12
- type ClassificationPrimitive,
13
- type Billboard,
14
5
  type Entity,
15
6
  type Label,
16
- type EntityCollection,
17
- SplitDirection,
7
+ LabelCollection,
8
+ Math as CesiumMath,
9
+ Matrix4,
10
+ Model,
11
+ Primitive,
12
+ PrimitiveCollection,
18
13
  Scene,
14
+ SplitDirection,
19
15
  } from '@vcmap-cesium/engine';
20
- import { Style } from 'ol/style.js';
21
- import { StyleFunction } from 'ol/style/Style.js';
16
+ import { StyleLike } from 'ol/style/Style.js';
22
17
  import type { Feature } from 'ol/index.js';
18
+
23
19
  import Viewpoint from '../../util/viewpoint.js';
24
20
  import type CesiumMap from '../../map/cesiumMap.js';
25
21
  import VectorProperties from '../vectorProperties.js';
26
- import convert from '../../util/featureconverter/convert.js';
27
-
28
- type PrimitiveType =
29
- | Primitive
30
- | GroundPrimitive
31
- | GroundPolylinePrimitive
32
- | ClassificationPrimitive
33
- | Model;
34
-
35
- export type VectorContextFeatureCache = {
36
- primitives?: PrimitiveType[];
37
- scaledPrimitives?: PrimitiveType[];
38
- billboards?: (Billboard | Entity)[];
39
- labels?: (Label | Entity)[];
40
- };
22
+ import convert, {
23
+ ConvertedItem,
24
+ PrimitiveType,
25
+ } from '../../util/featureconverter/convert.js';
41
26
 
42
27
  export function setReferenceForPicking(
43
28
  feature: Feature,
@@ -46,71 +31,6 @@ export function setReferenceForPicking(
46
31
  primitive.olFeature = feature;
47
32
  }
48
33
 
49
- export function removeArrayFromCollection(
50
- collection:
51
- | PrimitiveCollection
52
- | BillboardCollection
53
- | LabelCollection
54
- | EntityCollection,
55
- array?: (PrimitiveType | Billboard | Label | Entity)[],
56
- ): void {
57
- if (array) {
58
- array.forEach((primitive) => {
59
- collection.remove(primitive);
60
- });
61
- }
62
- }
63
-
64
- export function removeFeatureFromMap(
65
- feature: Feature,
66
- featuresMap: Map<Feature, (PrimitiveType | Billboard | Label | Entity)[]>,
67
- primitiveCollection:
68
- | PrimitiveCollection
69
- | BillboardCollection
70
- | LabelCollection
71
- | EntityCollection,
72
- ): boolean {
73
- removeArrayFromCollection(primitiveCollection, featuresMap.get(feature));
74
- return featuresMap.delete(feature);
75
- }
76
-
77
- export function addPrimitiveToContext(
78
- primitives: (PrimitiveType | Entity.ConstructorOptions)[],
79
- feature: Feature,
80
- allowPicking: boolean,
81
- primitiveCollection:
82
- | BillboardCollection
83
- | LabelCollection
84
- | PrimitiveCollection
85
- | EntityCollection,
86
- featureMap: Map<Feature, (Billboard | Label | PrimitiveType | Entity)[]>,
87
- splitDirection?: SplitDirection,
88
- ): void {
89
- if (primitives.length) {
90
- const cesiumPrimitives = primitives.map((primitiveOptions) => {
91
- const primitive = primitiveCollection.add(primitiveOptions) as
92
- | Billboard
93
- | Label
94
- | PrimitiveType
95
- | Entity
96
- | Model;
97
- if (allowPicking) {
98
- setReferenceForPicking(feature, primitive);
99
- }
100
- if (splitDirection && primitive instanceof Model) {
101
- // Cesium currently only supports splitDirection on Model primitives
102
- primitive.splitDirection = splitDirection;
103
- }
104
- return primitive;
105
- });
106
- if (!featureMap.has(feature)) {
107
- featureMap.set(feature, cesiumPrimitives);
108
- } else {
109
- featureMap.get(feature)!.push(...cesiumPrimitives);
110
- }
111
- }
112
- }
113
-
114
34
  /**
115
35
  * Sets splitDirection on primitives. Currently only Model primitives support splitting.
116
36
  */
@@ -175,133 +95,19 @@ export function setupScalingPrimitiveCollection(
175
95
  });
176
96
  }
177
97
 
178
- export interface AsyncCesiumVectorContext {
179
- addPrimitives(
180
- primitives: PrimitiveType[],
181
- feature: Feature,
182
- allowPicking: boolean,
183
- ): void;
184
- addScaledPrimitives(
185
- primitives: PrimitiveType[],
186
- feature: Feature,
187
- allowPicking: boolean,
188
- ): void;
189
- addBillboards(
190
- billboardOptions: object[],
98
+ export interface CesiumVectorContext {
99
+ addFeature(
191
100
  feature: Feature,
192
- allowPicking: boolean,
193
- ): void;
194
- addLabels(
195
- labelOptions: object[],
196
- feature: Feature,
197
- allowPicking: boolean,
198
- ): void;
199
- }
200
-
201
- export interface CesiumVectorContext extends AsyncCesiumVectorContext {
101
+ style: StyleLike,
102
+ vectorProperties: VectorProperties,
103
+ scene: Scene,
104
+ ): Promise<void>;
202
105
  removeFeature(feature: Feature): void;
203
- createFeatureCache(feature: Feature): VectorContextFeatureCache;
204
- clearFeatureCache(cache: VectorContextFeatureCache): void;
205
106
  updateSplitDirection(splitDirection: SplitDirection): void;
206
107
  clear(): void;
207
108
  }
208
109
 
209
- function createAsyncFeatureConvert(
210
- feature: Feature,
211
- style: Style | StyleFunction,
212
- vectorProperties: VectorProperties,
213
- context: CesiumVectorContext,
214
- scene: Scene,
215
- ): () => void {
216
- let isDestroyed = false;
217
- const primitivesArray: {
218
- primitives: PrimitiveType[];
219
- allowPicking: boolean;
220
- }[] = [];
221
- const scaledPrimitives: {
222
- primitives: PrimitiveType[];
223
- allowPicking: boolean;
224
- }[] = [];
225
- const billboards: { billboardOptions: object[]; allowPicking: boolean }[] =
226
- [];
227
- const labels: { labelOptions: object[]; allowPicking: boolean }[] = [];
228
-
229
- const asyncContext: AsyncCesiumVectorContext = {
230
- addPrimitives(
231
- primitives: PrimitiveType[],
232
- _feature: Feature,
233
- allowPicking: boolean,
234
- ): void {
235
- primitivesArray.push({ primitives, allowPicking });
236
- },
237
- addScaledPrimitives(
238
- primitives: PrimitiveType[],
239
- _feature: Feature,
240
- allowPicking: boolean,
241
- ): void {
242
- scaledPrimitives.push({ primitives, allowPicking });
243
- },
244
- addBillboards(
245
- billboardOptions: object[],
246
- _feature: Feature,
247
- allowPicking: boolean,
248
- ): void {
249
- billboards.push({ billboardOptions, allowPicking });
250
- },
251
- addLabels(
252
- labelOptions: object[],
253
- _feature: Feature,
254
- allowPicking: boolean,
255
- ): void {
256
- labels.push({ labelOptions, allowPicking });
257
- },
258
- };
259
-
260
- convert(feature, style, vectorProperties, asyncContext, scene)
261
- .then(() => {
262
- if (!isDestroyed) {
263
- primitivesArray.forEach(({ primitives, allowPicking }) => {
264
- context.addPrimitives(primitives, feature, allowPicking);
265
- });
266
- scaledPrimitives.forEach(({ primitives, allowPicking }) => {
267
- context.addScaledPrimitives(primitives, feature, allowPicking);
268
- });
269
- billboards.forEach(({ billboardOptions, allowPicking }) => {
270
- context.addBillboards(billboardOptions, feature, allowPicking);
271
- });
272
- labels.forEach(({ labelOptions, allowPicking }) => {
273
- context.addLabels(labelOptions, feature, allowPicking);
274
- });
275
- } else {
276
- primitivesArray.forEach(({ primitives }) => {
277
- primitives.forEach((p) => {
278
- p.destroy();
279
- });
280
- });
281
- scaledPrimitives.forEach(({ primitives }) => {
282
- primitives.forEach((p) => {
283
- p.destroy();
284
- });
285
- });
286
- }
287
- })
288
- .catch((err) => {
289
- console.error('feature conversion failed');
290
- console.error(err);
291
- })
292
- .finally(() => {
293
- primitivesArray.splice(0);
294
- scaledPrimitives.splice(0);
295
- billboards.splice(0);
296
- labels.splice(0);
297
- });
298
-
299
- return () => {
300
- isDestroyed = true;
301
- };
302
- }
303
-
304
- class VectorContext implements CesiumVectorContext {
110
+ export default class VectorContext implements CesiumVectorContext {
305
111
  primitives = new PrimitiveCollection();
306
112
 
307
113
  scaledPrimitives = new PrimitiveCollection();
@@ -310,15 +116,9 @@ class VectorContext implements CesiumVectorContext {
310
116
 
311
117
  labels: LabelCollection;
312
118
 
313
- featureToPrimitiveMap: Map<Feature, PrimitiveType[]> = new Map();
119
+ private _featureItems = new Map<Feature, (() => void)[]>();
314
120
 
315
- featureToScaledPrimitiveMap: Map<Feature, PrimitiveType[]> = new Map();
316
-
317
- featureToBillboardMap: Map<Feature, Array<Billboard>> = new Map();
318
-
319
- featureToLabelMap: Map<Feature, Array<Label>> = new Map();
320
-
321
- _features: Map<Feature, () => void> = new Map();
121
+ private _convertingFeatures: Map<Feature, () => void> = new Map();
322
122
 
323
123
  splitDirection: SplitDirection;
324
124
 
@@ -335,7 +135,7 @@ class VectorContext implements CesiumVectorContext {
335
135
  rootCollection: PrimitiveCollection,
336
136
  splitDirection: SplitDirection,
337
137
  ) {
338
- const scene = map.getScene();
138
+ const scene = map.getScene()!;
339
139
  this.billboards = new BillboardCollection({ scene });
340
140
  this.labels = new LabelCollection({ scene });
341
141
  this.splitDirection = splitDirection;
@@ -354,150 +154,127 @@ class VectorContext implements CesiumVectorContext {
354
154
  );
355
155
  }
356
156
 
357
- addPrimitives(
358
- primitives: PrimitiveType[],
157
+ private _addConvertedItems(
359
158
  feature: Feature,
360
- allowPicking = false,
159
+ allowPicking: boolean,
160
+ items: ConvertedItem[],
361
161
  ): void {
362
- addPrimitiveToContext(
363
- primitives,
364
- feature,
365
- allowPicking,
366
- this.primitives,
367
- this.featureToPrimitiveMap,
368
- this.splitDirection,
369
- );
370
- }
162
+ const removeItems = items
163
+ .map((item) => {
164
+ let instance: PrimitiveType | Label | Billboard | undefined;
165
+ let removeItem: (() => void) | undefined;
166
+ if (item.type === 'primitive') {
167
+ if (item.autoScale) {
168
+ instance = this.scaledPrimitives.add(item.item) as PrimitiveType;
169
+ if (instance) {
170
+ removeItem = (): void => {
171
+ this._scaledDirty.value =
172
+ this.scaledPrimitives.remove(instance);
173
+ };
174
+ this._scaledDirty.value = true;
175
+ }
176
+ } else {
177
+ instance = this.primitives.add(item.item) as PrimitiveType;
178
+ if (instance) {
179
+ removeItem = (): void => {
180
+ this.primitives.remove(instance);
181
+ };
182
+ }
183
+ }
184
+ } else if (item.type === 'billboard') {
185
+ instance = this.billboards.add(item.item);
186
+ if (instance) {
187
+ removeItem = (): void => {
188
+ this.billboards.remove(instance as Billboard);
189
+ };
190
+ }
191
+ } else if (item.type === 'label') {
192
+ instance = this.labels.add(item.item);
193
+ if (instance) {
194
+ removeItem = (): void => {
195
+ this.labels.remove(instance as Label);
196
+ };
197
+ }
198
+ }
371
199
 
372
- addScaledPrimitives(
373
- primitives: PrimitiveType[],
374
- feature: Feature,
375
- allowPicking = false,
376
- ): void {
377
- addPrimitiveToContext(
378
- primitives,
379
- feature,
380
- allowPicking,
381
- this.scaledPrimitives,
382
- this.featureToScaledPrimitiveMap,
383
- this.splitDirection,
384
- );
385
- this._scaledDirty.value = true;
386
- }
200
+ if (instance) {
201
+ if (allowPicking) {
202
+ setReferenceForPicking(feature, instance);
203
+ }
387
204
 
388
- addBillboards(
389
- billboardOptions: object[],
390
- feature: Feature,
391
- allowPicking = false,
392
- ): void {
393
- addPrimitiveToContext(
394
- billboardOptions,
395
- feature,
396
- allowPicking,
397
- this.billboards,
398
- this.featureToBillboardMap,
399
- this.splitDirection,
400
- );
205
+ if (this.splitDirection && instance instanceof Model) {
206
+ // Cesium currently only supports splitDirection on Model primitives // XXX this is no longer TRUE
207
+ instance.splitDirection = this.splitDirection;
208
+ }
209
+ }
210
+ return removeItem;
211
+ })
212
+ .filter((i): i is () => void => i != null);
213
+
214
+ this._featureItems.set(feature, removeItems);
401
215
  }
402
216
 
403
- addLabels(
404
- labelOptions: object[],
217
+ async addFeature(
405
218
  feature: Feature,
406
- allowPicking = false,
407
- ): void {
408
- addPrimitiveToContext(
409
- labelOptions,
410
- feature,
411
- allowPicking,
412
- this.labels,
413
- this.featureToLabelMap,
414
- this.splitDirection,
415
- );
416
- }
219
+ style: StyleLike,
220
+ vectorProperties: VectorProperties,
221
+ scene: Scene,
222
+ ): Promise<void> {
223
+ this._convertingFeatures.get(feature)?.();
224
+ let deleted = false;
225
+ this._convertingFeatures.set(feature, () => {
226
+ deleted = true;
227
+ });
417
228
 
418
- /**
419
- * @param feature
420
- */
421
- removeFeature(feature: Feature): void {
422
- this._features.get(feature)?.();
423
- this._features.delete(feature);
424
- removeFeatureFromMap(feature, this.featureToPrimitiveMap, this.primitives);
425
- this._scaledDirty.value = removeFeatureFromMap(
229
+ const convertedItems = await convert(
426
230
  feature,
427
- this.featureToScaledPrimitiveMap,
428
- this.scaledPrimitives,
231
+ style,
232
+ vectorProperties,
233
+ scene,
429
234
  );
430
- removeFeatureFromMap(feature, this.featureToBillboardMap, this.billboards);
431
- removeFeatureFromMap(feature, this.featureToLabelMap, this.labels);
432
- }
433
235
 
434
- /**
435
- * Caches the current cesium resources for a feature, removing them from the feature map
436
- * @param feature
437
- */
438
- createFeatureCache(feature: Feature): VectorContextFeatureCache {
439
- const cache: VectorContextFeatureCache = {};
440
- cache.primitives = this.featureToPrimitiveMap.get(feature);
441
- this.featureToPrimitiveMap.delete(feature);
442
- cache.scaledPrimitives = this.featureToScaledPrimitiveMap.get(feature);
443
- this.featureToScaledPrimitiveMap.delete(feature);
444
- cache.billboards = this.featureToBillboardMap.get(feature);
445
- this.featureToBillboardMap.delete(feature);
446
- cache.labels = this.featureToLabelMap.get(feature);
447
- this.featureToLabelMap.delete(feature);
448
- return cache;
236
+ this._featureItems.get(feature)?.forEach((removeItem) => removeItem());
237
+ this._featureItems.delete(feature);
238
+
239
+ if (deleted) {
240
+ convertedItems.forEach((item) => {
241
+ if (item.type === 'primitive') {
242
+ item.item.destroy();
243
+ }
244
+ });
245
+ } else {
246
+ this._addConvertedItems(
247
+ feature,
248
+ vectorProperties.getAllowPicking(feature),
249
+ convertedItems,
250
+ );
251
+ }
449
252
  }
450
253
 
451
- /**
452
- * @param cache
453
- */
454
- clearFeatureCache(cache: VectorContextFeatureCache): void {
455
- removeArrayFromCollection(this.primitives, cache.primitives);
456
- removeArrayFromCollection(this.scaledPrimitives, cache.scaledPrimitives);
457
- removeArrayFromCollection(this.billboards, cache.billboards);
458
- removeArrayFromCollection(this.labels, cache.labels);
254
+ removeFeature(feature: Feature): void {
255
+ this._convertingFeatures.get(feature)?.();
256
+ this._convertingFeatures.delete(feature);
257
+ this._featureItems.get(feature)?.forEach((removeItem) => removeItem());
258
+ this._featureItems.delete(feature);
459
259
  }
460
260
 
461
- /**
462
- * Updates splitDirection on primitives. Currently only Model primitives support splitting.
463
- * @param splitDirection
464
- */
465
261
  updateSplitDirection(splitDirection: SplitDirection): void {
466
262
  this.splitDirection = splitDirection;
467
263
  setSplitDirectionOnPrimitives(splitDirection, this.primitives);
468
264
  setSplitDirectionOnPrimitives(splitDirection, this.scaledPrimitives);
469
265
  }
470
266
 
471
- /**
472
- * Clears all collections and maps
473
- */
474
267
  clear(): void {
475
268
  this.primitives.removeAll();
269
+ this._scaledDirty.value = this.scaledPrimitives.length > 0;
476
270
  this.scaledPrimitives.removeAll();
477
271
  this.billboards.removeAll();
478
272
  this.labels.removeAll();
479
- this.featureToBillboardMap.clear();
480
- this.featureToLabelMap.clear();
481
- this.featureToPrimitiveMap.clear();
482
- this._scaledDirty.value = this.featureToScaledPrimitiveMap.size > 0;
483
- this.featureToScaledPrimitiveMap.clear();
484
- this._features.forEach((destroy) => {
273
+ this._featureItems.clear();
274
+ this._convertingFeatures.forEach((destroy) => {
485
275
  destroy();
486
276
  });
487
- this._features.clear();
488
- }
489
-
490
- convertFeature(
491
- feature: Feature,
492
- style: Style | StyleFunction,
493
- vectorProperties: VectorProperties,
494
- scene: Scene,
495
- ): void {
496
- this._features.get(feature)?.();
497
- this._features.set(
498
- feature,
499
- createAsyncFeatureConvert(feature, style, vectorProperties, this, scene),
500
- );
277
+ this._convertingFeatures.clear();
501
278
  }
502
279
 
503
280
  /**
@@ -513,16 +290,11 @@ class VectorContext implements CesiumVectorContext {
513
290
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
514
291
  // @ts-ignore
515
292
  this._rootCollection = null;
516
- this.featureToBillboardMap.clear();
517
- this.featureToLabelMap.clear();
518
- this.featureToPrimitiveMap.clear();
519
- this._features.forEach((destroy) => {
293
+ this._convertingFeatures.forEach((destroy) => {
520
294
  destroy();
521
295
  });
522
- this._features.clear();
523
- this.featureToScaledPrimitiveMap.clear();
296
+ this._convertingFeatures.clear();
297
+ this._featureItems.clear();
524
298
  this._postRenderListener();
525
299
  }
526
300
  }
527
-
528
- export default VectorContext;
@@ -248,16 +248,10 @@ function readFeature(
248
248
 
249
249
  if (featureObj.radius && geometry instanceof Point) {
250
250
  const coordinates = geometry.getCoordinates();
251
- if (coordinates.length === 2) {
252
- coordinates.push(0);
253
- }
254
- geometry = new Circle(coordinates, featureObj.radius, 'XYZ');
251
+ geometry = new Circle(coordinates, featureObj.radius);
255
252
  }
256
253
  if (radius && geometry instanceof Point) {
257
254
  const coordinates = geometry.getCoordinates();
258
- if (coordinates.length === 2) {
259
- coordinates.push(0);
260
- }
261
255
  geometry = circleFromCenterRadius(coordinates, radius);
262
256
  }
263
257
  if (String(options.formatOptions?.featureProjection) === 'EPSG:3857') {
@@ -467,23 +461,26 @@ export function writeGeoJSONFeature(
467
461
  /**
468
462
  * Writes all the features of the current layer to GeojsonLayer
469
463
  */
470
- export function writeGeoJSON(
464
+ export function writeGeoJSON<O extends GeoJSONwriteOptions>(
471
465
  data: GeoJSONData,
472
- options: GeoJSONwriteOptions = {},
473
- ): string | FeatureCollection {
466
+ options?: O,
467
+ ): O['asObject'] extends true ? FeatureCollection : string {
474
468
  // how to handel embedded icons when they are not set on the vcsMeta but options is true?
475
469
  const vcsMeta = data.vcsMeta || { version: vcsMetaVersion };
476
470
  vcsMeta.version = vcsMetaVersion;
477
471
  const featureObjs = data.features.map((feature) =>
478
472
  writeGeoJSONFeature(feature, options, vcsMeta.embeddedIcons),
479
473
  );
474
+
480
475
  const obj: FeatureCollection = {
481
476
  type: 'FeatureCollection',
482
477
  features: featureObjs,
483
478
  vcsMeta,
484
479
  };
485
480
 
486
- return options.asObject
481
+ const returnValue = options?.asObject
487
482
  ? obj
488
- : JSON.stringify(obj, undefined, options.prettyPrint ? 2 : undefined);
483
+ : JSON.stringify(obj, undefined, options?.prettyPrint ? 2 : undefined);
484
+
485
+ return returnValue as O['asObject'] extends true ? FeatureCollection : string;
489
486
  }
@@ -7,7 +7,7 @@ import type { Geometry } from 'ol/geom.js';
7
7
  import type { Feature } from 'ol/index.js';
8
8
 
9
9
  import { Cartographic, sampleTerrainMostDetailed } from '@vcmap-cesium/engine';
10
- import { cartesian2DDistance } from '../../util/math.js';
10
+ import { cartesian2DDistanceSquared } from '../../util/math.js';
11
11
  import Projection, {
12
12
  mercatorProjection,
13
13
  wgs84Projection,
@@ -25,7 +25,7 @@ import { transformFromImage } from '../../oblique/helpers.js';
25
25
  import type ObliqueImage from '../../oblique/obliqueImage.js';
26
26
 
27
27
  export function getLongestSide(coordinates: Coordinate[]): number {
28
- let side = 0;
28
+ let sideSquared = 0;
29
29
  for (let i = 0; i < coordinates.length; i++) {
30
30
  let j = i + 1;
31
31
  if (j >= coordinates.length) {
@@ -33,12 +33,12 @@ export function getLongestSide(coordinates: Coordinate[]): number {
33
33
  }
34
34
  const point1 = coordinates[i];
35
35
  const point2 = coordinates[j];
36
- const currentSide = cartesian2DDistance(point1, point2);
37
- if (currentSide > side) {
38
- side = currentSide;
36
+ const currentSideSquared = cartesian2DDistanceSquared(point1, point2);
37
+ if (currentSideSquared > sideSquared) {
38
+ sideSquared = currentSideSquared;
39
39
  }
40
40
  }
41
- return side;
41
+ return Math.sqrt(sideSquared);
42
42
  }
43
43
 
44
44
  export function getResolutionOptions(