@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
@@ -6,10 +6,9 @@ import {
6
6
  Cartesian2,
7
7
  LabelStyle,
8
8
  HorizontalOrigin,
9
- type BillboardGraphics,
10
- type LabelGraphics,
11
- type PolylineGeometry,
12
9
  type Scene,
10
+ Billboard,
11
+ Label,
13
12
  } from '@vcmap-cesium/engine';
14
13
  import { Icon, type Style } from 'ol/style.js';
15
14
  import type { Coordinate } from 'ol/coordinate.js';
@@ -18,33 +17,28 @@ import type { Feature } from 'ol/index.js';
18
17
  import type { Point } from 'ol/geom.js';
19
18
 
20
19
  import { parseNumber } from '@vcsuite/parsers';
21
- import {
22
- createLinePrimitive,
23
- getHeightInfo,
24
- } from './featureconverterHelper.js';
25
- import Projection from '../projection.js';
26
20
  import { createLineGeometries } from './lineStringToCesium.js';
27
21
  import { getCesiumColor } from '../../style/styleHelpers.js';
28
- import { getModelOptions, getPrimitiveOptions } from './pointHelpers.js';
22
+ import { getModelOrPointPrimitiveOptions } from './pointHelpers.js';
29
23
  import VectorProperties from '../../layer/vectorProperties.js';
30
- import type { VectorHeightInfo } from '../../layer/vectorLayer.js';
31
- import { AsyncCesiumVectorContext } from '../../layer/cesium/vectorContext.js';
32
24
  import type { ColorType } from '../../style/vectorStyleItem.js';
25
+ import { ConvertedItem } from './convert.js';
26
+ import {
27
+ isClampedHeightReference,
28
+ mercatorToWgs84TransformerForHeightInfo,
29
+ RelativeHeightReference,
30
+ VectorHeightInfo,
31
+ } from './vectorHeightInfo.js';
32
+ import { CesiumGeometryOption } from './vectorGeometryFactory.js';
33
33
 
34
- export function getCoordinates(geometries: Point[]): Coordinate[] {
35
- return geometries.map((point) => {
36
- return point.getCoordinates();
37
- });
38
- }
39
-
40
- export type BillboardOptions = BillboardGraphics.ConstructorOptions;
34
+ export type BillboardOptions = Billboard.ConstructorOptions;
41
35
 
42
36
  export function getBillboardOptions(
43
37
  feature: Feature,
44
38
  style: Style,
45
39
  heightReference: HeightReference,
46
40
  vectorProperties: VectorProperties,
47
- ): BillboardOptions | null {
41
+ ): Partial<BillboardOptions> | null {
48
42
  const imageStyle = style.getImage();
49
43
  if (imageStyle) {
50
44
  // ImageStyles should always have an opacity value between 0 and 1, default white Color
@@ -74,10 +68,7 @@ export function getBillboardOptions(
74
68
  if (!image) {
75
69
  image = imageStyle.getImage(1);
76
70
  }
77
- const options: BillboardOptions = {
78
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
79
- // @ts-ignore
80
- image,
71
+ const options: Partial<BillboardOptions> = {
81
72
  color,
82
73
  scale: imageStyle.getScaleArray()[0],
83
74
  heightReference,
@@ -85,9 +76,12 @@ export function getBillboardOptions(
85
76
  id: feature.getId(),
86
77
  };
87
78
 
79
+ // @ts-expect-error: cesium types are wrong here
80
+ options.image = image;
81
+
88
82
  options.eyeOffset = vectorProperties.getEyeOffset(feature);
89
83
  options.scaleByDistance = vectorProperties.getScaleByDistance(feature);
90
- if (heightReference === HeightReference.CLAMP_TO_GROUND) {
84
+ if (isClampedHeightReference(heightReference)) {
91
85
  options.disableDepthTestDistance = Number.POSITIVE_INFINITY;
92
86
  }
93
87
 
@@ -96,7 +90,7 @@ export function getBillboardOptions(
96
90
  return null;
97
91
  }
98
92
 
99
- export type LabelOptions = LabelGraphics.ConstructorOptions;
93
+ export type LabelOptions = Label.ConstructorOptions;
100
94
  /**
101
95
  * extracts cesium label options from a feature and style
102
96
  * @param feature
@@ -110,11 +104,11 @@ export function getLabelOptions(
110
104
  style: Style,
111
105
  heightReference: HeightReference,
112
106
  vectorProperties: VectorProperties,
113
- ): LabelOptions | null {
107
+ ): Partial<LabelOptions> | null {
114
108
  const textStyle = style.getText();
115
109
  const text = textStyle ? textStyle.getText() : null;
116
110
  if (text && textStyle) {
117
- const options: LabelOptions = {};
111
+ const options: Partial<LabelOptions> = {};
118
112
 
119
113
  options.text = text as string;
120
114
 
@@ -189,7 +183,7 @@ export function getLabelOptions(
189
183
  options.eyeOffset = vectorProperties.getEyeOffset(feature);
190
184
  options.scaleByDistance = vectorProperties.getScaleByDistance(feature);
191
185
 
192
- if (heightReference === HeightReference.CLAMP_TO_GROUND) {
186
+ if (isClampedHeightReference(heightReference)) {
193
187
  options.disableDepthTestDistance = Number.POSITIVE_INFINITY;
194
188
  }
195
189
  return options;
@@ -211,193 +205,135 @@ export function validatePoint(point: Point): boolean {
211
205
  return false;
212
206
  }
213
207
 
214
- /**
215
- * returns positions (cartesian3) and WGS84 coordinates
216
- * @param coordinates
217
- * @param heightInfo
218
- */
219
- export function getCartesian3AndWGS84FromCoordinates(
220
- coordinates: Coordinate[],
221
- heightInfo: VectorHeightInfo,
222
- ): { positions: Cartesian3[]; wgs84Positions: Coordinate[] } {
223
- const wgs84Positions = new Array(coordinates.length);
224
- const positions = new Array(coordinates.length);
225
- const heightValue =
226
- heightInfo.groundLevel +
208
+ export function getLineGeometries(
209
+ heightInfo: VectorHeightInfo<RelativeHeightReference | HeightReference.NONE>,
210
+ position: Cartesian3,
211
+ wgs84Coords: Coordinate,
212
+ style: Style,
213
+ ): CesiumGeometryOption<'line'>[] {
214
+ const heightValueCorrection =
215
+ heightInfo.skirt +
216
+ heightInfo.storeyHeightsBelowGround.reduce(
217
+ (sum, currentValue) => sum + currentValue,
218
+ 0,
219
+ ) +
227
220
  heightInfo.storeyHeightsAboveGround.reduce(
228
221
  (sum, currentValue) => sum + currentValue,
229
222
  0,
230
223
  );
231
- coordinates.forEach((coord, index) => {
232
- wgs84Positions[index] = Projection.mercatorToWgs84(coord, true);
233
- positions[index] = Cartesian3.fromDegrees(coord[0], coord[1], heightValue);
234
- });
235
- return {
236
- positions,
237
- wgs84Positions,
238
- };
224
+
225
+ const secondPoint = Cartesian3.fromDegrees(
226
+ wgs84Coords[0],
227
+ wgs84Coords[1],
228
+ wgs84Coords[2] - heightValueCorrection,
229
+ );
230
+ const linePositions = [position, secondPoint];
231
+ return createLineGeometries({ positions: linePositions }, heightInfo, style);
239
232
  }
240
233
 
241
- export function getLineGeometries(
242
- wgs84Positions: Coordinate[],
234
+ /**
235
+ * Sets the correct height on the wgs84Coords depending on the height info
236
+ * @param geometry
237
+ * @param heightInfo
238
+ */
239
+ export function getWgs84CoordinatesForPoint(
240
+ geometry: Point,
243
241
  heightInfo: VectorHeightInfo,
244
- positions: Cartesian3[],
245
- style: Style,
246
- ): PolylineGeometry[] {
247
- const lineGeometries = [];
248
- const heightValueCorrection =
249
- heightInfo.skirt +
250
- heightInfo.storeyHeightsBelowGround.reduce(
242
+ ): Coordinate {
243
+ const transformer = mercatorToWgs84TransformerForHeightInfo(heightInfo);
244
+ const wgs84Coords = transformer(geometry.getCoordinates());
245
+ if (!isClampedHeightReference(heightInfo.heightReference)) {
246
+ // points get rendered at the top of the extrusion. we must add this to the Z value
247
+ const extrusionHeight = (
248
+ heightInfo as VectorHeightInfo<
249
+ RelativeHeightReference | HeightReference.NONE
250
+ >
251
+ ).storeyHeightsAboveGround.reduce(
251
252
  (sum, currentValue) => sum + currentValue,
252
253
  0,
253
254
  );
254
- for (let i = 0; i < wgs84Positions.length; i++) {
255
- const pointPosition = wgs84Positions[i];
256
- let heightValue =
257
- pointPosition[2] != null ? pointPosition[2] : heightInfo.groundLevel;
258
- heightValue -= heightValueCorrection;
259
- const secondPoint = Cartesian3.fromDegrees(
260
- pointPosition[0],
261
- pointPosition[1],
262
- heightValue,
263
- );
264
- const linePositions = [positions[i], secondPoint];
265
- lineGeometries.push(
266
- ...createLineGeometries({ positions: linePositions }, style),
267
- );
255
+
256
+ if (extrusionHeight) {
257
+ wgs84Coords[2] += extrusionHeight;
258
+ }
268
259
  }
269
- return lineGeometries;
260
+
261
+ return wgs84Coords;
270
262
  }
271
263
 
272
- export default async function pointToCesium(
264
+ export async function getPointPrimitives(
273
265
  feature: Feature,
266
+ geometry: Point,
274
267
  style: Style,
275
- geometries: Point[],
276
268
  vectorProperties: VectorProperties,
277
269
  scene: Scene,
278
- context: AsyncCesiumVectorContext,
279
- ): Promise<void> {
280
- if (!style.getImage() && !style.getText()?.getText()) {
281
- return;
282
- }
283
- const validGeometries = geometries.filter((point) => validatePoint(point));
284
-
285
- // no geometries, so early escape
286
- if (!validGeometries.length) {
287
- return;
288
- }
289
-
290
- const coordinates = getCoordinates(validGeometries);
291
- const heightInfo = getHeightInfo(feature, vectorProperties, coordinates);
292
- let { heightReference } = heightInfo;
293
- const allowPicking = vectorProperties.getAllowPicking(feature);
294
-
295
- const { positions, wgs84Positions } = getCartesian3AndWGS84FromCoordinates(
296
- coordinates,
297
- heightInfo,
270
+ heightInfo: VectorHeightInfo,
271
+ ): Promise<(CesiumGeometryOption | ConvertedItem)[]> {
272
+ const wgs84Coords = getWgs84CoordinatesForPoint(geometry, heightInfo);
273
+ const position = Cartesian3.fromDegrees(
274
+ wgs84Coords[0],
275
+ wgs84Coords[1],
276
+ wgs84Coords[2],
298
277
  );
299
-
300
- let modelOrPrimitiveOptions = null;
301
- if (feature.get('olcs_modelUrl')) {
302
- modelOrPrimitiveOptions = await getModelOptions(
303
- feature,
304
- wgs84Positions,
305
- positions,
306
- vectorProperties,
307
- scene,
308
- style,
309
- );
310
- } else if (feature.get('olcs_primitiveOptions')) {
311
- modelOrPrimitiveOptions = await getPrimitiveOptions(
278
+ const pointPrimitives: (CesiumGeometryOption | ConvertedItem)[] =
279
+ await getModelOrPointPrimitiveOptions(
312
280
  feature,
313
281
  style,
314
- wgs84Positions,
315
- positions,
282
+ position,
283
+ wgs84Coords,
316
284
  vectorProperties,
285
+ heightInfo,
317
286
  scene,
318
287
  );
319
- } else {
320
- modelOrPrimitiveOptions =
321
- (await getModelOptions(
322
- feature,
323
- wgs84Positions,
324
- positions,
325
- vectorProperties,
326
- scene,
327
- style,
328
- )) ??
329
- (await getPrimitiveOptions(
330
- feature,
331
- style,
332
- wgs84Positions,
333
- positions,
334
- vectorProperties,
335
- scene,
336
- ));
337
- }
338
288
 
339
- if (heightInfo.extruded && style.getStroke()) {
340
- const lineGeometries = getLineGeometries(
341
- wgs84Positions,
342
- heightInfo,
343
- positions,
344
- style,
345
- );
346
- if (lineGeometries.length) {
347
- heightReference = HeightReference.NONE;
348
- const linePrimitive = createLinePrimitive(
349
- scene,
350
- vectorProperties,
351
- allowPicking,
352
- feature,
353
- lineGeometries,
354
- style,
355
- false,
356
- );
357
- if (linePrimitive) {
358
- context.addPrimitives([linePrimitive], feature, allowPicking);
359
- }
360
- }
361
- }
362
- if (modelOrPrimitiveOptions) {
363
- if (modelOrPrimitiveOptions.options.autoScale) {
364
- context.addScaledPrimitives(
365
- modelOrPrimitiveOptions.primitives,
366
- feature,
367
- allowPicking,
368
- );
369
- } else {
370
- context.addPrimitives(
371
- modelOrPrimitiveOptions.primitives,
372
- feature,
373
- allowPicking,
374
- );
375
- }
376
- } else {
289
+ if (pointPrimitives.length === 0) {
377
290
  const bbOptions = getBillboardOptions(
378
291
  feature,
379
292
  style,
380
- heightReference,
293
+ heightInfo.heightReference,
381
294
  vectorProperties,
382
295
  );
383
296
  if (bbOptions) {
384
- const bbOptionsperPosition = positions.map((position) => {
385
- return { ...bbOptions, position };
297
+ pointPrimitives.push({
298
+ type: 'billboard',
299
+ item: { ...bbOptions, position },
386
300
  });
387
- context.addBillboards(bbOptionsperPosition, feature, allowPicking);
388
301
  }
389
302
 
390
303
  const labelOptions = getLabelOptions(
391
304
  feature,
392
305
  style,
393
- heightReference,
306
+ heightInfo.heightReference,
394
307
  vectorProperties,
395
308
  );
396
309
  if (labelOptions) {
397
- const labelOptionsPerPosition = positions.map((position) => {
398
- return { ...labelOptions, position };
310
+ pointPrimitives.push({
311
+ type: 'label',
312
+ item: { ...labelOptions, position },
399
313
  });
400
- context.addLabels(labelOptionsPerPosition, feature, allowPicking);
401
314
  }
402
315
  }
316
+
317
+ if (
318
+ !isClampedHeightReference(heightInfo.heightReference) &&
319
+ (
320
+ heightInfo as VectorHeightInfo<
321
+ RelativeHeightReference | HeightReference.NONE
322
+ >
323
+ ).extruded &&
324
+ style.getStroke()
325
+ ) {
326
+ pointPrimitives.push(
327
+ ...getLineGeometries(
328
+ heightInfo as VectorHeightInfo<
329
+ RelativeHeightReference | HeightReference.NONE
330
+ >,
331
+ position,
332
+ wgs84Coords,
333
+ style,
334
+ ),
335
+ );
336
+ }
337
+
338
+ return pointPrimitives;
403
339
  }
@@ -6,34 +6,27 @@ import {
6
6
  GroundPolylineGeometry,
7
7
  PolygonHierarchy,
8
8
  PolylineGeometry,
9
- type Scene,
10
9
  } from '@vcmap-cesium/engine';
11
10
  import type { Style } from 'ol/style.js';
12
11
  import type { Polygon } from 'ol/geom.js';
13
- import type { Coordinate } from 'ol/coordinate.js';
14
- import type { Feature } from 'ol/index.js';
15
12
  import { parseNumber } from '@vcsuite/parsers';
16
- import { addPrimitivesToContext } from './featureconverterHelper.js';
17
- import Projection from '../projection.js';
18
- import { getFlatCoordinatesFromSimpleGeometry } from '../geometryHelpers.js';
19
- import type { VectorGeometryFactoryType } from '../../layer/vectorLayer.js';
20
- import type VectorProperties from '../../layer/vectorProperties.js';
21
- import type { AsyncCesiumVectorContext } from '../../layer/cesium/vectorContext.js';
22
-
23
- export type PolygonGeometryOptions = ConstructorParameters<
24
- typeof PolygonGeometry
25
- >[0];
26
-
27
- export type PolylineGeometryOptions = ConstructorParameters<
28
- typeof PolylineGeometry
29
- >[0];
13
+ import {
14
+ mercatorToCartesianTransformerForHeightInfo,
15
+ VectorHeightInfo,
16
+ } from './vectorHeightInfo.js';
17
+ import {
18
+ CesiumGeometryOption,
19
+ PolygonGeometryOptions,
20
+ PolylineGeometryOptions,
21
+ VectorGeometryFactory,
22
+ } from './vectorGeometryFactory.js';
30
23
 
31
- export function createSolidGeometries(
24
+ function createPolygonGeometry(
32
25
  options: PolygonGeometryOptions,
33
26
  height: number,
34
27
  perPositionHeight: boolean,
35
28
  extrudedHeight?: number,
36
- ): PolygonGeometry[] {
29
+ ): PolygonGeometry {
37
30
  const polygonOptions: PolygonGeometryOptions = {
38
31
  ...options,
39
32
  perPositionHeight,
@@ -42,35 +35,69 @@ export function createSolidGeometries(
42
35
  if (!perPositionHeight) {
43
36
  polygonOptions.height = height;
44
37
  }
45
- return [new PolygonGeometry(polygonOptions)];
38
+
39
+ return new PolygonGeometry(polygonOptions);
40
+ }
41
+
42
+ function createSolidGeometries(
43
+ options: PolygonGeometryOptions,
44
+ heightInfo: VectorHeightInfo,
45
+ height: number,
46
+ perPositionHeight: boolean,
47
+ extrudedHeight?: number,
48
+ ): CesiumGeometryOption<'solid'>[] {
49
+ return [
50
+ {
51
+ type: 'solid',
52
+ geometry: createPolygonGeometry(
53
+ options,
54
+ height,
55
+ perPositionHeight,
56
+ extrudedHeight,
57
+ ),
58
+ heightInfo,
59
+ },
60
+ ];
46
61
  }
47
62
 
48
- export function createOutlineGeometries(
63
+ function createOutlineGeometries(
49
64
  options: PolygonGeometryOptions,
65
+ heightInfo: VectorHeightInfo,
50
66
  height: number,
51
67
  perPositionHeight: boolean,
52
68
  extrudedHeight?: number,
53
- ): PolygonOutlineGeometry[] {
69
+ ): CesiumGeometryOption<'outline'>[] {
54
70
  return [
55
- new PolygonOutlineGeometry({
56
- ...options,
57
- height: perPositionHeight ? undefined : height,
58
- extrudedHeight,
59
- perPositionHeight,
60
- vertexFormat: PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
61
- }),
71
+ {
72
+ type: 'outline',
73
+ geometry: new PolygonOutlineGeometry({
74
+ ...options,
75
+ height: perPositionHeight ? undefined : height,
76
+ extrudedHeight,
77
+ perPositionHeight,
78
+ vertexFormat: PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
79
+ }),
80
+ heightInfo,
81
+ },
62
82
  ];
63
83
  }
64
84
 
65
- export function createFillGeometries(
85
+ function createFillGeometries(
66
86
  options: PolygonGeometryOptions,
87
+ heightInfo: VectorHeightInfo,
67
88
  height: number,
68
89
  perPositionHeight: boolean,
69
- ): PolygonGeometry[] {
70
- return createSolidGeometries(options, height, perPositionHeight, undefined);
90
+ ): CesiumGeometryOption<'fill'>[] {
91
+ return [
92
+ {
93
+ type: 'fill',
94
+ geometry: createPolygonGeometry(options, height, perPositionHeight),
95
+ heightInfo,
96
+ },
97
+ ];
71
98
  }
72
99
 
73
- export function getLineGeometryOptions(
100
+ function getLineGeometryOptions(
74
101
  options: PolygonGeometryOptions,
75
102
  style: Style,
76
103
  ): PolylineGeometryOptions[] {
@@ -91,47 +118,43 @@ export function getLineGeometryOptions(
91
118
  return geometryOptions;
92
119
  }
93
120
 
94
- export function createGroundLineGeometries(
121
+ function createGroundLineGeometries(
95
122
  options: PolygonGeometryOptions,
123
+ heightInfo: VectorHeightInfo,
96
124
  style: Style,
97
- ): GroundPolylineGeometry[] {
98
- return getLineGeometryOptions(options, style).map((option) => {
99
- return new GroundPolylineGeometry(option);
100
- });
125
+ ): CesiumGeometryOption<'groundLine'>[] {
126
+ return getLineGeometryOptions(options, style).map((option) => ({
127
+ type: 'groundLine',
128
+ geometry: new GroundPolylineGeometry(option),
129
+ heightInfo,
130
+ }));
101
131
  }
102
- export function createLineGeometries(
132
+
133
+ function createLineGeometries(
103
134
  options: PolygonGeometryOptions,
135
+ heightInfo: VectorHeightInfo,
104
136
  style: Style,
105
- ): PolylineGeometry[] {
106
- return getLineGeometryOptions(options, style).map((option) => {
107
- return new PolylineGeometry(option);
108
- });
137
+ ): CesiumGeometryOption<'line'>[] {
138
+ return getLineGeometryOptions(options, style).map((option) => ({
139
+ type: 'line',
140
+ geometry: new PolylineGeometry(option),
141
+ heightInfo,
142
+ }));
109
143
  }
110
144
 
111
- export function getGeometryOptions(
145
+ function getGeometryOptions(
112
146
  geometry: Polygon,
113
- positionHeightAdjustment: number,
114
- perPositionHeight: boolean,
115
- groundLevelOrMinHeight: number,
147
+ heightInfo: VectorHeightInfo,
116
148
  ): PolygonGeometryOptions {
117
149
  let hieraryPositions;
118
150
  const holes = [];
119
151
  const rings = geometry.getLinearRings();
152
+
153
+ const coordinateTransformer =
154
+ mercatorToCartesianTransformerForHeightInfo(heightInfo);
120
155
  for (let i = 0; i < rings.length; i++) {
121
156
  const coords = rings[i].getCoordinates();
122
- const positions = coords.map((coord) => {
123
- const wgs84Coords = Projection.mercatorToWgs84(coord);
124
- if (!perPositionHeight && groundLevelOrMinHeight) {
125
- wgs84Coords[2] = groundLevelOrMinHeight;
126
- } else if (wgs84Coords[2] != null) {
127
- wgs84Coords[2] += positionHeightAdjustment;
128
- }
129
- return Cartesian3.fromDegrees(
130
- wgs84Coords[0],
131
- wgs84Coords[1],
132
- wgs84Coords[2],
133
- );
134
- });
157
+ const positions = coords.map(coordinateTransformer);
135
158
  // make sure the last and first vertex is identical.
136
159
  if (!Cartesian3.equals(positions[0], positions[positions.length - 1])) {
137
160
  positions.push(positions[0]);
@@ -147,31 +170,6 @@ export function getGeometryOptions(
147
170
  };
148
171
  }
149
172
 
150
- export function getCoordinates(geometries: Polygon[]): Coordinate[] {
151
- const coordinates: Coordinate[] = [];
152
- geometries.forEach((polygon) => {
153
- coordinates.push(...getFlatCoordinatesFromSimpleGeometry(polygon));
154
- });
155
- return coordinates;
156
- }
157
-
158
- let geometryFactory: VectorGeometryFactoryType | null = null;
159
-
160
- function getGeometryFactory(): VectorGeometryFactoryType {
161
- if (!geometryFactory) {
162
- geometryFactory = {
163
- getCoordinates,
164
- getGeometryOptions,
165
- createSolidGeometries,
166
- createOutlineGeometries,
167
- createFillGeometries,
168
- createGroundLineGeometries,
169
- createLineGeometries,
170
- };
171
- }
172
- return geometryFactory;
173
- }
174
-
175
173
  /**
176
174
  * TODO maybe add validation Functions to OpenlayersMap
177
175
  * validates if a polygon is renderable
@@ -204,37 +202,20 @@ export function validatePolygon(polygon: Polygon): boolean {
204
202
  return false;
205
203
  }
206
204
 
207
- /**
208
- * converts a polygon to a a cesium primitive, with optional labels
209
- * @param feature
210
- * @param style
211
- * @param geometries
212
- * @param vectorProperties
213
- * @param scene
214
- * @param context
215
- */
216
- export default function polygonToCesium(
217
- feature: Feature,
218
- style: Style,
219
- geometries: Polygon[],
220
- vectorProperties: VectorProperties,
221
- scene: Scene,
222
- context: AsyncCesiumVectorContext,
223
- ): void {
224
- if (!style.getFill() && !style.getStroke()) {
225
- return;
205
+ let geometryFactory: VectorGeometryFactory<'polygon'> | undefined;
206
+
207
+ export function getPolygonGeometryFactory(): VectorGeometryFactory<'polygon'> {
208
+ if (!geometryFactory) {
209
+ geometryFactory = {
210
+ type: 'polygon',
211
+ getGeometryOptions,
212
+ createSolidGeometries,
213
+ createOutlineGeometries,
214
+ createFillGeometries,
215
+ createGroundLineGeometries,
216
+ createLineGeometries,
217
+ validateGeometry: validatePolygon,
218
+ };
226
219
  }
227
- const polygonGeometryFactory = getGeometryFactory();
228
- const validGeometries = geometries.filter((polygon) =>
229
- validatePolygon(polygon),
230
- );
231
- addPrimitivesToContext(
232
- feature,
233
- style,
234
- validGeometries,
235
- vectorProperties,
236
- scene,
237
- polygonGeometryFactory,
238
- context,
239
- );
220
+ return geometryFactory;
240
221
  }