@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
@@ -19,27 +19,31 @@ import {
19
19
  ModelAnimationLoop,
20
20
  PerInstanceColorAppearance,
21
21
  Primitive,
22
- sampleTerrainMostDetailed,
23
22
  type Scene,
24
23
  SphereGeometry,
25
24
  SphereOutlineGeometry,
26
25
  Transforms,
27
26
  } from '@vcmap-cesium/engine';
28
27
  import type { Feature } from 'ol/index.js';
29
- import type { Coordinate } from 'ol/coordinate.js';
30
28
  import { RegularShape, type Style } from 'ol/style.js';
31
29
  import { asColorLike } from 'ol/colorlike.js';
30
+ import { Coordinate } from 'ol/coordinate.js';
32
31
  import { createSync } from '../../layer/vectorSymbols.js';
33
32
  import VectorProperties, {
34
33
  PrimitiveOptionsType,
35
- VectorPropertiesModelOptions,
36
34
  vectorPropertiesOfType,
37
- VectorPropertiesPrimitive,
38
35
  VectorPropertiesPrimitiveOptions,
39
36
  } from '../../layer/vectorProperties.js';
40
37
  import { getCesiumColor } from '../../style/styleHelpers.js';
41
38
  import ModelFill from '../../style/modelFill.js';
42
39
  import { ColorType } from '../../style/vectorStyleItem.js';
40
+ import { wgs84ToCartographic } from '../math.js';
41
+ import { ConvertedItem } from './convert.js';
42
+ import {
43
+ isRelativeHeightReference,
44
+ RelativeHeightReference,
45
+ VectorHeightInfo,
46
+ } from './vectorHeightInfo.js';
43
47
 
44
48
  function makeOffsetAutoScalePrimitive(
45
49
  primitive: Primitive | Model,
@@ -91,47 +95,75 @@ function makeScaledAutoScalePrimitive(
91
95
  });
92
96
  }
93
97
 
94
- async function placePrimitiveOnTerrain(
98
+ const scratchUpdateHeightCartesian = new Cartesian3();
99
+
100
+ function makeClampedPrimitive(
95
101
  primitive: Primitive | Model,
96
- position: Cartesian3,
102
+ scale: Cartesian3,
103
+ headingPitchRoll: HeadingPitchRoll,
104
+ heightReference: HeightReference,
97
105
  scene: Scene,
106
+ wgs84Coords: Coordinate,
98
107
  offset?: Cartesian3,
99
- ): Promise<void> {
100
- await sampleTerrainMostDetailed(scene.globe.terrainProvider, [
101
- Cartographic.fromCartesian(position),
102
- ])
103
- .then(([cartoWithNewHeight]) => {
104
- if (!primitive.isDestroyed()) {
105
- const { modelMatrix } = primitive;
106
- const newPosition = Cartographic.toCartesian(
107
- cartoWithNewHeight,
108
- undefined,
109
- position,
110
- );
111
- if (offset) {
112
- Cartesian3.add(newPosition, offset, newPosition);
113
- }
114
- primitive.modelMatrix = Matrix4.setTranslation(
115
- modelMatrix,
116
- newPosition,
117
- modelMatrix,
118
- );
119
- }
120
- })
121
- .catch(() => {});
108
+ ): void {
109
+ const originCartographic = wgs84ToCartographic(wgs84Coords);
110
+ const updatePrimitiveHeight = (clampedPosition: Cartographic): void => {
111
+ clampedPosition.height += wgs84Coords[2];
112
+ Cartographic.toCartesian(
113
+ clampedPosition,
114
+ undefined,
115
+ scratchUpdateHeightCartesian,
116
+ );
117
+
118
+ const geometryModelMatrix = Matrix4.fromScale(scale);
119
+ if (offset) {
120
+ Matrix4.setTranslation(
121
+ geometryModelMatrix,
122
+ Cartesian3.multiplyComponents(offset, scale, new Cartesian3()),
123
+ geometryModelMatrix,
124
+ );
125
+ }
126
+ const transform = Transforms.headingPitchRollToFixedFrame(
127
+ scratchUpdateHeightCartesian,
128
+ headingPitchRoll,
129
+ );
130
+
131
+ primitive.modelMatrix = Matrix4.multiply(
132
+ transform,
133
+ geometryModelMatrix,
134
+ new Matrix4(),
135
+ );
136
+ };
137
+
138
+ const callbackHandler = scene.updateHeight(
139
+ originCartographic,
140
+ updatePrimitiveHeight,
141
+ heightReference,
142
+ );
143
+
144
+ const height = scene.getHeight(originCartographic, heightReference);
145
+ if (height) {
146
+ const updatedHeightCarto = originCartographic.clone();
147
+ updatedHeightCarto.height = height;
148
+ updatePrimitiveHeight(updatedHeightCarto);
149
+ }
150
+
151
+ const destroy = primitive.destroy.bind(primitive);
152
+ primitive.destroy = (): void => {
153
+ callbackHandler();
154
+ destroy();
155
+ };
122
156
  }
123
157
 
124
158
  export async function getModelOptions(
125
159
  feature: Feature,
126
- wgs84Positions: Coordinate[],
127
- positions: Cartesian3[],
160
+ position: Cartesian3,
161
+ wgs84Coords: Coordinate,
128
162
  vectorProperties: VectorProperties,
129
163
  scene: Scene,
164
+ heightInfo: VectorHeightInfo,
130
165
  style?: Style,
131
- ): Promise<null | {
132
- primitives: Model[];
133
- options: VectorPropertiesModelOptions;
134
- }> {
166
+ ): Promise<null | ConvertedItem<'primitive'>> {
135
167
  const options = vectorProperties.getModel(feature);
136
168
  if (!options) {
137
169
  return null;
@@ -152,57 +184,59 @@ export async function getModelOptions(
152
184
  }
153
185
  }
154
186
 
155
- const primitives = await Promise.all(
156
- positions.map(async (position, index) => {
157
- const modelMatrix = Matrix4.multiply(
158
- Transforms.headingPitchRollToFixedFrame(position, headingPitchRoll),
159
- Matrix4.fromScale(scale),
160
- new Matrix4(),
161
- );
187
+ const modelMatrix = Matrix4.multiply(
188
+ Transforms.headingPitchRollToFixedFrame(position, headingPitchRoll),
189
+ Matrix4.fromScale(scale),
190
+ new Matrix4(),
191
+ );
162
192
 
163
- const additionalModelOptions = vectorProperties.getModelOptions(feature);
164
- const heightReference = vectorProperties.getAltitudeMode(feature);
165
- const model = await Model.fromGltfAsync({
166
- asynchronous: !feature[createSync],
167
- url: options.url,
168
- modelMatrix,
169
- allowPicking,
170
- color,
171
- ...additionalModelOptions,
172
- });
173
-
174
- if (
175
- wgs84Positions[index][2] == null ||
176
- heightReference === HeightReference.CLAMP_TO_GROUND
177
- ) {
178
- await placePrimitiveOnTerrain(model, position, scene);
179
- }
193
+ const additionalModelOptions = vectorProperties.getModelOptions(feature);
194
+ const model = await Model.fromGltfAsync({
195
+ asynchronous: !feature[createSync],
196
+ url: options.url,
197
+ modelMatrix,
198
+ allowPicking,
199
+ color,
200
+ ...additionalModelOptions,
201
+ });
180
202
 
181
- const activateAnimations = (): void => {
182
- model.activeAnimations.addAll({
183
- loop: ModelAnimationLoop.REPEAT,
184
- });
185
- };
186
-
187
- if (model.ready) {
188
- activateAnimations();
189
- } else {
190
- const listener = model.readyEvent.addEventListener(() => {
191
- listener();
192
- activateAnimations();
193
- });
194
- }
203
+ const activateAnimations = (): void => {
204
+ model.activeAnimations.addAll({
205
+ loop: ModelAnimationLoop.REPEAT,
206
+ });
207
+ };
195
208
 
196
- if (options.autoScale && !Cartesian3.ONE.equals(scale)) {
197
- makeScaledAutoScalePrimitive(model, scale);
198
- }
199
- return model;
200
- }),
201
- );
209
+ if (model.ready) {
210
+ activateAnimations();
211
+ } else {
212
+ const listener = model.readyEvent.addEventListener(() => {
213
+ listener();
214
+ activateAnimations();
215
+ });
216
+ }
217
+
218
+ if (options.autoScale && !Cartesian3.ONE.equals(scale)) {
219
+ makeScaledAutoScalePrimitive(model, scale);
220
+ }
221
+ if (
222
+ isRelativeHeightReference(heightInfo.heightReference) &&
223
+ (heightInfo as VectorHeightInfo<RelativeHeightReference>).groundLevel ==
224
+ null
225
+ ) {
226
+ makeClampedPrimitive(
227
+ model,
228
+ scale,
229
+ headingPitchRoll,
230
+ heightInfo.heightReference,
231
+ scene,
232
+ wgs84Coords,
233
+ );
234
+ }
202
235
 
203
236
  return {
204
- primitives,
205
- options,
237
+ type: 'primitive',
238
+ item: model,
239
+ autoScale: options.autoScale,
206
240
  };
207
241
  }
208
242
 
@@ -263,20 +297,18 @@ function getGeometryInstanceFromOptions(
263
297
  return null;
264
298
  }
265
299
 
266
- export async function getPrimitiveOptions(
300
+ export function getPrimitiveOptions(
267
301
  feature: Feature,
268
302
  style: Style,
269
- wgs84Positions: Coordinate[],
270
- positions: Cartesian3[],
303
+ position: Cartesian3,
304
+ wgs84Coords: Coordinate,
271
305
  vectorProperties: VectorProperties,
272
306
  scene: Scene,
273
- ): Promise<null | {
274
- primitives: Primitive[];
275
- options: VectorPropertiesPrimitive;
276
- }> {
307
+ heightInfo: VectorHeightInfo,
308
+ ): ConvertedItem<'primitive'>[] {
277
309
  const options = vectorProperties.getPrimitive(feature);
278
310
  if (!options) {
279
- return null;
311
+ return [];
280
312
  }
281
313
 
282
314
  const imageStyle = style.getImage();
@@ -292,7 +324,7 @@ export async function getPrimitiveOptions(
292
324
  }
293
325
 
294
326
  if (!fill && !stroke) {
295
- return null;
327
+ return [];
296
328
  }
297
329
  let fillColor: Color | undefined;
298
330
  if (fill) {
@@ -313,134 +345,159 @@ export async function getPrimitiveOptions(
313
345
  options.roll,
314
346
  );
315
347
  const allowPicking = vectorProperties.getAllowPicking(feature);
316
- const heightReference = vectorProperties.getAltitudeMode(feature);
317
-
318
- const primitives = await Promise.all(
319
- positions.map(async (position, index) => {
320
- const geometryModelMatrix = Matrix4.fromScale(scale);
321
- let offset: Cartesian3 | undefined;
322
- if (options.primitiveOptions.offset?.length === 3) {
323
- offset = Cartesian3.fromArray(options.primitiveOptions.offset);
324
- Matrix4.setTranslation(
325
- geometryModelMatrix,
326
- Cartesian3.multiplyComponents(offset, scale, new Cartesian3()),
327
- geometryModelMatrix,
328
- );
348
+
349
+ const geometryModelMatrix = Matrix4.fromScale(scale);
350
+ let offset: Cartesian3 | undefined;
351
+ if (options.primitiveOptions.offset?.length === 3) {
352
+ offset = Cartesian3.fromArray(options.primitiveOptions.offset);
353
+ Matrix4.setTranslation(
354
+ geometryModelMatrix,
355
+ Cartesian3.multiplyComponents(offset, scale, new Cartesian3()),
356
+ geometryModelMatrix,
357
+ );
358
+ }
359
+ const transform = Transforms.headingPitchRollToFixedFrame(
360
+ position,
361
+ headingPitchRoll,
362
+ );
363
+ const modelMatrix = Matrix4.multiply(
364
+ transform,
365
+ geometryModelMatrix,
366
+ new Matrix4(),
367
+ );
368
+
369
+ let depthFail;
370
+ if (options.primitiveOptions.depthFailColor) {
371
+ const depthFailColor = getCesiumColor(
372
+ options.primitiveOptions.depthFailColor,
373
+ [255, 255, 255, 0.4],
374
+ );
375
+ depthFail = new MaterialAppearance({
376
+ translucent: depthFailColor.alpha < 1,
377
+ material: Material.fromType('Color', {
378
+ color: depthFailColor,
379
+ }),
380
+ });
381
+ }
382
+
383
+ const createPrimitive = (
384
+ translucent: boolean,
385
+ geometryInstances: (GeometryInstance | null)[],
386
+ depthFailAppearance?: MaterialAppearance,
387
+ ): Primitive => {
388
+ const primitive = new Primitive({
389
+ asynchronous: !feature[createSync],
390
+ geometryInstances: geometryInstances.filter(
391
+ (g) => g,
392
+ ) as GeometryInstance[],
393
+ modelMatrix,
394
+ appearance: new PerInstanceColorAppearance({
395
+ translucent,
396
+ flat: true,
397
+ }),
398
+ depthFailAppearance,
399
+ allowPicking,
400
+ ...options.primitiveOptions.additionalOptions,
401
+ });
402
+
403
+ if (options.autoScale) {
404
+ if (offset) {
405
+ makeOffsetAutoScalePrimitive(primitive, transform, scale, offset);
406
+ } else if (!Cartesian3.ONE.equals(scale)) {
407
+ makeScaledAutoScalePrimitive(primitive, scale);
329
408
  }
330
- const transform = Transforms.headingPitchRollToFixedFrame(
331
- position,
409
+ }
410
+
411
+ if (
412
+ isRelativeHeightReference(heightInfo.heightReference) &&
413
+ (heightInfo as VectorHeightInfo<RelativeHeightReference>).groundLevel ==
414
+ null
415
+ ) {
416
+ makeClampedPrimitive(
417
+ primitive,
418
+ scale,
332
419
  headingPitchRoll,
420
+ heightInfo.heightReference,
421
+ scene,
422
+ wgs84Coords,
423
+ offset,
333
424
  );
334
- const modelMatrix = Matrix4.multiply(
335
- transform,
336
- geometryModelMatrix,
337
- new Matrix4(),
338
- );
425
+ }
426
+ return primitive;
427
+ };
339
428
 
340
- let depthFail;
341
- if (options.primitiveOptions.depthFailColor) {
342
- const depthFailColor = getCesiumColor(
343
- options.primitiveOptions.depthFailColor,
344
- [255, 255, 255, 0.4],
345
- );
346
- depthFail = new MaterialAppearance({
347
- translucent: depthFailColor.alpha < 1,
348
- material: Material.fromType('Color', {
349
- color: depthFailColor,
350
- }),
351
- });
352
- }
429
+ const fillAndOutline = [];
430
+ if (fillColor) {
431
+ fillAndOutline.push(
432
+ createPrimitive(
433
+ fillColor.alpha < 1 || !!depthFail,
434
+ [getGeometryInstanceFromOptions(options.primitiveOptions, fillColor)],
435
+ depthFail,
436
+ ),
437
+ );
438
+ } else if (depthFail) {
439
+ const transparent = Color.TRANSPARENT;
440
+ fillAndOutline.push(
441
+ createPrimitive(
442
+ true,
443
+ [getGeometryInstanceFromOptions(options.primitiveOptions, transparent)],
444
+ depthFail,
445
+ ),
446
+ );
447
+ }
448
+ if (strokeColor) {
449
+ fillAndOutline.push(
450
+ createPrimitive(strokeColor.alpha < 1 || !!depthFail, [
451
+ getGeometryInstanceFromOptions(
452
+ options.primitiveOptions,
453
+ strokeColor,
454
+ true,
455
+ ),
456
+ ]),
457
+ );
458
+ }
353
459
 
354
- const createPrimitive = async (
355
- translucent: boolean,
356
- geometryInstances: (GeometryInstance | null)[],
357
- depthFailAppearance?: MaterialAppearance,
358
- ): Promise<Primitive> => {
359
- const primitive = new Primitive({
360
- asynchronous: !feature[createSync],
361
- geometryInstances: geometryInstances.filter(
362
- (g) => g,
363
- ) as GeometryInstance[],
364
- modelMatrix,
365
- appearance: new PerInstanceColorAppearance({
366
- translucent,
367
- flat: true,
368
- }),
369
- depthFailAppearance,
370
- allowPicking,
371
- ...options.primitiveOptions.additionalOptions,
372
- });
373
-
374
- if (
375
- wgs84Positions[index][2] == null ||
376
- heightReference === HeightReference.CLAMP_TO_GROUND
377
- ) {
378
- await placePrimitiveOnTerrain(primitive, position, scene, offset);
379
- Transforms.headingPitchRollToFixedFrame(
380
- position,
381
- headingPitchRoll,
382
- undefined,
383
- undefined,
384
- transform,
385
- ); // update transform for usage in offset auto scale
386
- }
387
-
388
- if (options.autoScale) {
389
- if (offset) {
390
- makeOffsetAutoScalePrimitive(primitive, transform, scale, offset);
391
- } else if (!Cartesian3.ONE.equals(scale)) {
392
- makeScaledAutoScalePrimitive(primitive, scale);
393
- }
394
- }
395
- return primitive;
396
- };
397
-
398
- const fillAndOutline = [];
399
- if (fillColor) {
400
- fillAndOutline.push(
401
- createPrimitive(
402
- fillColor.alpha < 1 || !!depthFail,
403
- [
404
- getGeometryInstanceFromOptions(
405
- options.primitiveOptions,
406
- fillColor,
407
- ),
408
- ],
409
- depthFail,
410
- ),
411
- );
412
- } else if (depthFail) {
413
- const transparent = Color.TRANSPARENT;
414
- fillAndOutline.push(
415
- createPrimitive(
416
- true,
417
- [
418
- getGeometryInstanceFromOptions(
419
- options.primitiveOptions,
420
- transparent,
421
- ),
422
- ],
423
- depthFail,
424
- ),
425
- );
426
- }
427
- if (strokeColor) {
428
- fillAndOutline.push(
429
- createPrimitive(strokeColor.alpha < 1 || !!depthFail, [
430
- getGeometryInstanceFromOptions(
431
- options.primitiveOptions,
432
- strokeColor,
433
- true,
434
- ),
435
- ]),
436
- );
437
- }
438
- return Promise.all(fillAndOutline);
439
- }),
440
- );
460
+ return fillAndOutline.map((item) => ({
461
+ type: 'primitive',
462
+ item,
463
+ autoScale: options.autoScale,
464
+ }));
465
+ }
441
466
 
442
- return {
443
- primitives: primitives.flatMap((p) => p),
444
- options,
445
- };
467
+ export async function getModelOrPointPrimitiveOptions(
468
+ feature: Feature,
469
+ style: Style,
470
+ position: Cartesian3,
471
+ wgs84Coords: Coordinate,
472
+ vectorProperties: VectorProperties,
473
+ heightInfo: VectorHeightInfo,
474
+ scene: Scene,
475
+ ): Promise<ConvertedItem<'primitive'>[]> {
476
+ const renderAs = vectorProperties.renderAs(feature);
477
+ if (renderAs === 'model') {
478
+ const modelOptions = await getModelOptions(
479
+ feature,
480
+ position,
481
+ wgs84Coords,
482
+ vectorProperties,
483
+ scene,
484
+ heightInfo,
485
+ style,
486
+ );
487
+
488
+ return modelOptions ? [modelOptions] : [];
489
+ }
490
+
491
+ if (renderAs === 'primitive') {
492
+ return getPrimitiveOptions(
493
+ feature,
494
+ style,
495
+ position,
496
+ wgs84Coords,
497
+ vectorProperties,
498
+ scene,
499
+ heightInfo,
500
+ );
501
+ }
502
+ return [];
446
503
  }