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