@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,672 +0,0 @@
1
- import { getBottomLeft } from 'ol/extent.js';
2
- import type { Feature } from 'ol/index.js';
3
- import type { SimpleGeometry } from 'ol/geom.js';
4
- import type { Style, Fill } from 'ol/style.js';
5
- import type { Coordinate } from 'ol/coordinate.js';
6
- import {
7
- Cartesian3,
8
- HeightReference,
9
- ColorGeometryInstanceAttribute,
10
- GeometryInstance,
11
- Material,
12
- SceneTransforms,
13
- MaterialAppearance,
14
- ClassificationType,
15
- PerInstanceColorAppearance,
16
- GroundPrimitive,
17
- GroundPolylinePrimitive,
18
- ClassificationPrimitive,
19
- ShadowMode,
20
- Primitive,
21
- Color,
22
- PolylineMaterialAppearance,
23
- type Scene,
24
- type PolylineGeometry,
25
- type GroundPolylineGeometry,
26
- type CircleOutlineGeometry,
27
- type WallOutlineGeometry,
28
- type PolygonOutlineGeometry,
29
- type PolygonGeometry,
30
- type CircleGeometry,
31
- type WallGeometry,
32
- } from '@vcmap-cesium/engine';
33
- import { getCesiumColor } from '../../style/styleHelpers.js';
34
- import { createSync } from '../../layer/vectorSymbols.js';
35
- import type VectorProperties from '../../layer/vectorProperties.js';
36
- import type {
37
- VectorGeometryFactoryType,
38
- VectorHeightInfo,
39
- } from '../../layer/vectorLayer.js';
40
- import type { AsyncCesiumVectorContext } from '../../layer/cesium/vectorContext.js';
41
- import { ColorType } from '../../style/vectorStyleItem.js';
42
-
43
- export function getMaterialAppearance(
44
- scene: Scene,
45
- fill: Fill,
46
- feature: Feature,
47
- ): MaterialAppearance {
48
- const options: ConstructorParameters<typeof MaterialAppearance>[0] = {
49
- flat: true,
50
- renderState: {
51
- depthTest: {
52
- enabled: true,
53
- },
54
- },
55
- };
56
- const fillColor = fill.getColor();
57
- if (fillColor instanceof CanvasPattern) {
58
- const canvas = document.createElement('canvas');
59
- const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
60
- ctx.fillStyle = fillColor;
61
- ctx.fillRect(0, 0, 300, 300);
62
- options.material = Material.fromType('Wallpaper', {
63
- image: canvas,
64
- anchor: SceneTransforms.wgs84ToDrawingBufferCoordinates(
65
- scene,
66
- Cartesian3.fromDegreesArray(
67
- getBottomLeft(feature.getGeometry()!.getExtent()),
68
- )[0],
69
- ),
70
- });
71
- } else {
72
- const color = getCesiumColor(fillColor as string, [0, 0, 0, 1]);
73
- options.material = Material.fromType('Color', {
74
- color,
75
- });
76
- options.translucent = color.alpha !== 1;
77
- }
78
- return new MaterialAppearance(options);
79
- }
80
-
81
- export function createClassificationPrimitive(
82
- options: Partial<ConstructorParameters<typeof ClassificationPrimitive>[0]>,
83
- geometries: (PolygonGeometry | CircleGeometry | WallGeometry)[],
84
- color: Color,
85
- classificationType: ClassificationType,
86
- ): ClassificationPrimitive {
87
- const instances = geometries.map(
88
- (geometry) =>
89
- new GeometryInstance({
90
- geometry,
91
- attributes: {
92
- color: ColorGeometryInstanceAttribute.fromColor(color),
93
- },
94
- }),
95
- );
96
-
97
- const appearance = new PerInstanceColorAppearance({
98
- flat: false,
99
- renderState: {
100
- depthTest: {
101
- enabled: true,
102
- },
103
- lineWidth: 1,
104
- },
105
- translucent: color.alpha !== 1,
106
- });
107
-
108
- const classificationPrimitiveOptions = {
109
- ...options,
110
- geometryInstances: instances,
111
- appearance,
112
- shadows: ShadowMode.ENABLED,
113
- classificationType,
114
- };
115
- return new ClassificationPrimitive(classificationPrimitiveOptions);
116
- }
117
-
118
- export function createPrimitive(
119
- scene: Scene,
120
- vectorProperties: VectorProperties,
121
- allowPicking: boolean,
122
- feature: Feature,
123
- geometries: (PolygonGeometry | CircleGeometry | WallGeometry)[],
124
- style: Style,
125
- groundPrimitive: boolean,
126
- ): Primitive | GroundPrimitive | ClassificationPrimitive | null {
127
- const classificationType = vectorProperties.getClassificationType(feature);
128
- const options: Partial<ConstructorParameters<typeof Primitive>[0]> & {
129
- classificationType?: ClassificationType;
130
- } = {
131
- shadows: ShadowMode.ENABLED,
132
- allowPicking,
133
- asynchronous: !feature[createSync],
134
- };
135
- let primitive;
136
- if (classificationType !== undefined && !groundPrimitive) {
137
- if (!ClassificationPrimitive.isSupported(scene)) {
138
- return null;
139
- }
140
- const color = getCesiumColor(
141
- style.getFill()!.getColor() as ColorType, // XXX PatternDescriptor
142
- [0, 0, 0, 1],
143
- );
144
- primitive = createClassificationPrimitive(
145
- options,
146
- geometries,
147
- color,
148
- classificationType,
149
- );
150
- } else {
151
- const instances = geometries.map(
152
- (geometry) =>
153
- new GeometryInstance({
154
- geometry,
155
- }),
156
- );
157
- options.geometryInstances = instances;
158
- const appearance = getMaterialAppearance(scene, style.getFill()!, feature);
159
- options.appearance = appearance;
160
- if (groundPrimitive) {
161
- if (!GroundPrimitive.isSupported(scene)) {
162
- return null;
163
- }
164
- options.classificationType =
165
- classificationType || ClassificationType.TERRAIN;
166
- primitive = new GroundPrimitive(options);
167
- } else {
168
- primitive = new Primitive(options);
169
- }
170
- }
171
- return primitive;
172
- }
173
-
174
- export function createOutlinePrimitive(
175
- _scene: Scene,
176
- _vectorProperties: VectorProperties,
177
- allowPicking: boolean,
178
- feature: Feature,
179
- geometries: (PolygonGeometry | CircleGeometry | WallGeometry)[],
180
- style: Style,
181
- ): Primitive {
182
- const color = getCesiumColor(style.getStroke()!.getColor(), [0, 0, 0, 1]);
183
- const instances = geometries.map(
184
- (geometry) =>
185
- new GeometryInstance({
186
- geometry,
187
- attributes: {
188
- color: ColorGeometryInstanceAttribute.fromColor(color),
189
- },
190
- }),
191
- );
192
- const appearance = new PerInstanceColorAppearance({
193
- flat: true,
194
- renderState: {
195
- depthTest: {
196
- enabled: true,
197
- },
198
- lineWidth: 1,
199
- },
200
- translucent: color.alpha !== 1,
201
- });
202
- const options = {
203
- geometryInstances: instances,
204
- appearance,
205
- shadows: ShadowMode.ENABLED,
206
- allowPicking,
207
- asynchronous: !feature[createSync],
208
- };
209
- const primitive = new Primitive(options);
210
- return primitive;
211
- }
212
-
213
- export function createLinePrimitive(
214
- scene: Scene,
215
- vectorProperties: VectorProperties,
216
- allowPicking: boolean,
217
- feature: Feature,
218
- geometries: (PolylineGeometry | GroundPolylineGeometry)[],
219
- style: Style,
220
- groundPrimitive: boolean,
221
- ): Primitive | GroundPolylinePrimitive | null {
222
- const classificationType = vectorProperties.getClassificationType(feature);
223
- const instances = geometries.map(
224
- (geometry) =>
225
- new GeometryInstance({
226
- geometry,
227
- }),
228
- );
229
-
230
- const color = getCesiumColor(style.getStroke()!.getColor(), [0, 0, 0, 1]);
231
- let material;
232
- if (style.getStroke()?.getLineDash()) {
233
- material = Material.fromType('Stripe', {
234
- horizontal: false,
235
- repeat: 500,
236
- evenColor: color,
237
- oddColor: new Color(0, 0, 0, 0), // transparent
238
- });
239
- } else {
240
- material = Material.fromType('Color', { color });
241
- }
242
-
243
- const appearance = new PolylineMaterialAppearance({
244
- renderState: {
245
- depthTest: {
246
- enabled: true,
247
- },
248
- lineWidth: 1,
249
- },
250
- translucent: color.alpha !== 1,
251
- material,
252
- });
253
-
254
- const options: Partial<ConstructorParameters<typeof Primitive>[0]> & {
255
- classificationType?: ClassificationType;
256
- } = {
257
- geometryInstances: instances,
258
- appearance,
259
- shadows: ShadowMode.ENABLED,
260
- allowPicking,
261
- asynchronous: !feature[createSync],
262
- };
263
- let primitive;
264
- if (groundPrimitive) {
265
- if (!GroundPolylinePrimitive.isSupported(scene)) {
266
- return null;
267
- }
268
- options.classificationType =
269
- classificationType || ClassificationType.TERRAIN;
270
- primitive = new GroundPolylinePrimitive(options);
271
- } else {
272
- primitive = new Primitive(options);
273
- }
274
- return primitive;
275
- }
276
-
277
- /**
278
- * returns groundlevel or extracts the minimum height from the coordinates, returns 0 if no z coordinates are set
279
- * @param groundLevel
280
- * @param coordinates
281
- */
282
- export function getMinHeightOrGroundLevel(
283
- groundLevel: number | null | undefined,
284
- coordinates?: Coordinate[],
285
- ): number {
286
- if (groundLevel != null && Number.isFinite(Number(groundLevel))) {
287
- return groundLevel;
288
- }
289
- if (coordinates) {
290
- let minimumHeight = Infinity;
291
- for (let i = 0; i < coordinates.length; i++) {
292
- minimumHeight =
293
- coordinates[i][2] < minimumHeight ? coordinates[i][2] : minimumHeight;
294
- }
295
- if (Number.isFinite(minimumHeight)) {
296
- return minimumHeight;
297
- }
298
- }
299
- return 0;
300
- }
301
-
302
- /**
303
- * @param extrudedHeight should be a number > 0
304
- * @param storeyHeights
305
- * @param storeyNumber
306
- */
307
- export function getStoreyHeights(
308
- extrudedHeight: number,
309
- storeyHeights: number[],
310
- storeyNumber: number,
311
- ): number[] {
312
- const positiveExtrudedHeight = Math.abs(extrudedHeight);
313
- const fittedStoreyHeights = [];
314
- if (storeyHeights.length) {
315
- let height = 0;
316
- for (let i = 0; i < storeyHeights.length; i++) {
317
- height += storeyHeights[i];
318
- if (height < positiveExtrudedHeight) {
319
- fittedStoreyHeights.push(storeyHeights[i]);
320
- } else {
321
- fittedStoreyHeights.push(
322
- storeyHeights[i] - (height - positiveExtrudedHeight),
323
- );
324
- return fittedStoreyHeights;
325
- }
326
- }
327
- const lastStoreyHeight = storeyHeights[storeyHeights.length - 1];
328
- while (height < positiveExtrudedHeight) {
329
- height += lastStoreyHeight;
330
- if (height < positiveExtrudedHeight) {
331
- fittedStoreyHeights.push(lastStoreyHeight);
332
- } else {
333
- fittedStoreyHeights.push(
334
- lastStoreyHeight - (height - positiveExtrudedHeight),
335
- );
336
- return fittedStoreyHeights;
337
- }
338
- }
339
- } else if (storeyNumber) {
340
- return new Array(storeyNumber).fill(
341
- positiveExtrudedHeight / storeyNumber,
342
- ) as number[];
343
- }
344
- // case no predefined storeyHeights
345
- return [positiveExtrudedHeight];
346
- }
347
-
348
- export function validateStoreys(
349
- storeys: number,
350
- storeyHeights: number[],
351
- ): void {
352
- if (storeys && storeyHeights.length) {
353
- const missingStoreyHeights = storeys - storeyHeights.length;
354
- if (missingStoreyHeights > 0) {
355
- storeyHeights.push(
356
- ...(new Array(missingStoreyHeights).fill(
357
- storeyHeights[storeyHeights.length - 1],
358
- ) as number[]),
359
- );
360
- } else if (missingStoreyHeights < 0) {
361
- storeyHeights.splice(storeyHeights.length + missingStoreyHeights);
362
- }
363
- if (storeys > 100) {
364
- storeyHeights.splice(100);
365
- }
366
- } else {
367
- storeyHeights.splice(0);
368
- }
369
- }
370
-
371
- export function getHeightAboveGround(
372
- feature: Feature,
373
- heightReference: HeightReference,
374
- vectorProperties: VectorProperties,
375
- ): number {
376
- if (heightReference === HeightReference.RELATIVE_TO_GROUND) {
377
- return vectorProperties.getHeightAboveGround(feature);
378
- }
379
- return 0;
380
- }
381
-
382
- export function getHeightInfo(
383
- feature: Feature,
384
- vectorProperties: VectorProperties,
385
- coordinates: Coordinate[],
386
- ): VectorHeightInfo {
387
- const extrudedHeight = vectorProperties.getExtrudedHeight(feature);
388
-
389
- let storeysAboveGround = vectorProperties.getStoreysAboveGround(feature);
390
- let storeysBelowGround = vectorProperties.getStoreysBelowGround(feature);
391
- let storeyHeightsAboveGround =
392
- vectorProperties.getStoreyHeightsAboveGround(feature);
393
- let storeyHeightsBelowGround =
394
- vectorProperties.getStoreyHeightsBelowGround(feature);
395
- if (extrudedHeight) {
396
- // current Case only extrudedHeight
397
- if (extrudedHeight > 0) {
398
- storeyHeightsAboveGround = getStoreyHeights(
399
- extrudedHeight,
400
- storeyHeightsAboveGround,
401
- storeysAboveGround,
402
- );
403
- storeysAboveGround = storeyHeightsAboveGround.length;
404
- storeyHeightsBelowGround = [];
405
- storeysBelowGround = 0;
406
- } else if (extrudedHeight < 0) {
407
- storeyHeightsBelowGround = getStoreyHeights(
408
- extrudedHeight,
409
- storeyHeightsBelowGround,
410
- storeysBelowGround,
411
- );
412
- storeysBelowGround = storeyHeightsBelowGround.length;
413
- storeyHeightsAboveGround = [];
414
- storeysAboveGround = 0;
415
- }
416
- }
417
-
418
- validateStoreys(storeysAboveGround, storeyHeightsAboveGround);
419
- validateStoreys(storeysBelowGround, storeyHeightsBelowGround);
420
-
421
- const skirt = vectorProperties.getSkirt(feature);
422
- const olcsGroundLevel = vectorProperties.getGroundLevel(feature);
423
-
424
- const heightReference = vectorProperties.getAltitudeMode(feature);
425
- const heightAboveGroundAdjustment = getHeightAboveGround(
426
- feature,
427
- heightReference,
428
- vectorProperties,
429
- );
430
-
431
- const groundLevel =
432
- getMinHeightOrGroundLevel(olcsGroundLevel, coordinates) +
433
- heightAboveGroundAdjustment;
434
- const hasZCoordinate = !!coordinates.find((value) => value[2]);
435
-
436
- const extruded = !!(
437
- storeyHeightsAboveGround.length ||
438
- storeyHeightsBelowGround.length ||
439
- skirt
440
- );
441
- const perPositionHeight =
442
- hasZCoordinate &&
443
- olcsGroundLevel == null &&
444
- (!extruded ||
445
- (extruded &&
446
- storeyHeightsAboveGround.length + storeyHeightsBelowGround.length ===
447
- 1));
448
-
449
- return {
450
- extruded,
451
- storeyHeightsAboveGround,
452
- storeyHeightsBelowGround,
453
- skirt,
454
- groundLevel,
455
- perPositionHeight,
456
- heightReference,
457
- heightAboveGroundAdjustment,
458
- };
459
- }
460
-
461
- type StoreyOptions = { currentHeight: number; extrudedHeight: number };
462
-
463
- export function getStoreyOptions(
464
- storeyHeights: number[],
465
- initialHeight: number,
466
- down?: boolean,
467
- result?: StoreyOptions[],
468
- ): StoreyOptions[] {
469
- const direction = down ? -1 : 1;
470
- let currentHeight = initialHeight;
471
- const storeys = storeyHeights.length;
472
- const options = new Array(storeys);
473
- for (let i = 0; i < storeys; i++) {
474
- const extrudedHeight = currentHeight + direction * storeyHeights[i];
475
- options[i] = {
476
- currentHeight,
477
- extrudedHeight,
478
- };
479
- currentHeight = extrudedHeight;
480
- }
481
-
482
- if (result) {
483
- result.push(...(options as StoreyOptions[]));
484
- return result;
485
- }
486
- return options as StoreyOptions[];
487
- }
488
-
489
- export function addPrimitivesToContext(
490
- feature: Feature,
491
- style: Style,
492
- geometries: SimpleGeometry[],
493
- vectorProperties: VectorProperties,
494
- scene: Scene,
495
- geometryFactory: VectorGeometryFactoryType,
496
- context: AsyncCesiumVectorContext,
497
- ): void {
498
- // no geometries, so early escape
499
- if (!geometries.length) {
500
- return;
501
- }
502
-
503
- const fillGeometries: (PolygonGeometry | CircleGeometry | WallGeometry)[] =
504
- [];
505
- const outlineGeometries: (
506
- | CircleOutlineGeometry
507
- | WallOutlineGeometry
508
- | PolygonOutlineGeometry
509
- )[] = [];
510
- const lineGeometries: (PolylineGeometry | GroundPolylineGeometry)[] = [];
511
-
512
- const heightInfo = getHeightInfo(
513
- feature,
514
- vectorProperties,
515
- geometryFactory.getCoordinates(geometries),
516
- );
517
-
518
- const hasFill = !!style.getFill();
519
- const hasStroke = !!style.getStroke();
520
-
521
- let groundPrimitive = false;
522
-
523
- geometries.forEach((geometry) => {
524
- const geometryOptions = geometryFactory.getGeometryOptions(
525
- geometry,
526
- heightInfo.heightAboveGroundAdjustment,
527
- heightInfo.perPositionHeight,
528
- heightInfo.groundLevel,
529
- );
530
- const storeyOptions = getStoreyOptions(
531
- heightInfo.storeyHeightsAboveGround,
532
- heightInfo.groundLevel,
533
- );
534
- getStoreyOptions(
535
- heightInfo.storeyHeightsBelowGround,
536
- heightInfo.groundLevel,
537
- true,
538
- storeyOptions,
539
- );
540
-
541
- if (hasFill) {
542
- storeyOptions.forEach((options) => {
543
- fillGeometries.push(
544
- ...geometryFactory.createSolidGeometries(
545
- geometryOptions,
546
- options.currentHeight,
547
- heightInfo.perPositionHeight,
548
- options.extrudedHeight,
549
- ),
550
- );
551
- });
552
- }
553
- if (hasStroke) {
554
- storeyOptions.forEach((options) => {
555
- outlineGeometries.push(
556
- ...geometryFactory.createOutlineGeometries(
557
- geometryOptions,
558
- options.currentHeight,
559
- heightInfo.perPositionHeight,
560
- options.extrudedHeight,
561
- ),
562
- );
563
- });
564
- }
565
- if (heightInfo.skirt) {
566
- const currentHeight =
567
- heightInfo.groundLevel -
568
- heightInfo.storeyHeightsBelowGround.reduce((a, b) => a + b, 0);
569
- const extrudedHeight = currentHeight - heightInfo.skirt;
570
- const skirtPositionHeight = heightInfo.storeyHeightsBelowGround.length
571
- ? false
572
- : heightInfo.perPositionHeight;
573
- if (hasFill) {
574
- fillGeometries.push(
575
- ...geometryFactory.createSolidGeometries(
576
- geometryOptions,
577
- currentHeight,
578
- skirtPositionHeight,
579
- extrudedHeight,
580
- ),
581
- );
582
- }
583
- if (hasStroke) {
584
- outlineGeometries.push(
585
- ...geometryFactory.createOutlineGeometries(
586
- geometryOptions,
587
- currentHeight,
588
- skirtPositionHeight,
589
- extrudedHeight,
590
- ),
591
- );
592
- }
593
- }
594
-
595
- if (!heightInfo.extruded) {
596
- if (heightInfo.heightReference === HeightReference.CLAMP_TO_GROUND) {
597
- groundPrimitive = true;
598
- }
599
- if (hasFill) {
600
- fillGeometries.push(
601
- ...geometryFactory.createFillGeometries(
602
- geometryOptions,
603
- heightInfo.groundLevel,
604
- heightInfo.perPositionHeight,
605
- ),
606
- );
607
- }
608
- if (hasStroke) {
609
- if (heightInfo.heightReference === HeightReference.CLAMP_TO_GROUND) {
610
- lineGeometries.push(
611
- ...geometryFactory.createGroundLineGeometries(
612
- geometryOptions,
613
- style,
614
- ),
615
- );
616
- } else {
617
- lineGeometries.push(
618
- ...geometryFactory.createLineGeometries(geometryOptions, style),
619
- );
620
- }
621
- }
622
- }
623
- });
624
-
625
- const allowPicking = vectorProperties.getAllowPicking(feature);
626
- const primitives = [];
627
- if (lineGeometries.length) {
628
- const linePrimitive = createLinePrimitive(
629
- scene,
630
- vectorProperties,
631
- allowPicking,
632
- feature,
633
- lineGeometries,
634
- style,
635
- groundPrimitive,
636
- );
637
- if (linePrimitive) {
638
- primitives.push(linePrimitive);
639
- }
640
- }
641
-
642
- if (fillGeometries.length) {
643
- const fillPrimitive = createPrimitive(
644
- scene,
645
- vectorProperties,
646
- allowPicking,
647
- feature,
648
- fillGeometries,
649
- style,
650
- groundPrimitive,
651
- );
652
- if (fillPrimitive) {
653
- primitives.push(fillPrimitive);
654
- }
655
- }
656
-
657
- if (outlineGeometries.length) {
658
- const outlinePrimitive = createOutlinePrimitive(
659
- scene,
660
- vectorProperties,
661
- allowPicking,
662
- feature,
663
- outlineGeometries,
664
- style,
665
- );
666
- if (outlinePrimitive) {
667
- primitives.push(outlinePrimitive);
668
- }
669
- }
670
-
671
- context.addPrimitives(primitives, feature, allowPicking);
672
- }