@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,6 +1,6 @@
1
1
  import { check, ofEnum } from '@vcsuite/check';
2
2
  import { Feature } from 'ol';
3
- import type { Geometry } from 'ol/geom.js';
3
+ import type { Geometry, LineString, Polygon } from 'ol/geom.js';
4
4
  import { unByKey } from 'ol/Observable.js';
5
5
  import VcsEvent from '../../vcsEvent.js';
6
6
  import {
@@ -10,6 +10,7 @@ import {
10
10
  GeometryType,
11
11
  SessionType,
12
12
  setupInteractionChain,
13
+ setupScratchLayer,
13
14
  } from './editorSessionHelpers.js';
14
15
  import CreateLineStringInteraction from './interactions/createLineStringInteraction.js';
15
16
  import CreateCircleInteraction from './interactions/createCircleInteraction.js';
@@ -23,6 +24,10 @@ import geometryIsValid from './validateGeoemetry.js';
23
24
  import ObliqueMap from '../../map/obliqueMap.js';
24
25
  import { cursorMap } from './interactions/editGeometryMouseOverInteraction.js';
25
26
  import { AltitudeModeType } from '../../layer/vectorProperties.js';
27
+ import CreationSnapping from './interactions/creationSnapping.js';
28
+ import { syncScratchLayerVectorProperties } from './editorHelpers.js';
29
+ import LayerSnapping from './interactions/layerSnapping.js';
30
+ import { SnapType, snapTypes } from './snappingHelpers.js';
26
31
 
27
32
  export type CreateFeatureSession<T extends GeometryType> =
28
33
  EditorSession<SessionType.CREATE> & {
@@ -30,6 +35,7 @@ export type CreateFeatureSession<T extends GeometryType> =
30
35
  featureAltitudeMode: AltitudeModeType | undefined;
31
36
  featureCreated: VcsEvent<Feature<GeometryToType<T>>>;
32
37
  creationFinished: VcsEvent<Feature<GeometryToType<T>> | null>;
38
+ snapToLayers: VectorLayer[];
33
39
  finish(): void;
34
40
  };
35
41
 
@@ -91,6 +97,8 @@ export interface CreateInteraction<T extends Geometry> {
91
97
  * @param layer
92
98
  * @param geometryType
93
99
  * @param initialAltitudeMode - whether to use the layers altitude mode or set this on the feature
100
+ * @param [initialSnapToLayers=[layer]] - the layers to initially snap to. defaults to the provided layer
101
+ * @param [snapTo] - what to snap to, by default all snaps are active
94
102
  * @group Editor
95
103
  */
96
104
  function startCreateFeatureSession<T extends GeometryType>(
@@ -98,6 +106,8 @@ function startCreateFeatureSession<T extends GeometryType>(
98
106
  layer: VectorLayer,
99
107
  geometryType: T,
100
108
  initialAltitudeMode?: AltitudeModeType,
109
+ initialSnapToLayers: VectorLayer[] = [layer],
110
+ snapTo: SnapType[] = [...snapTypes],
101
111
  ): CreateFeatureSession<T> {
102
112
  check(app, VcsApp);
103
113
  check(layer, VectorLayer);
@@ -108,6 +118,7 @@ function startCreateFeatureSession<T extends GeometryType>(
108
118
  removed: interactionRemoved,
109
119
  destroy: destroyInteractionChain,
110
120
  } = setupInteractionChain(app.maps.eventHandler);
121
+ const scratchLayer = setupScratchLayer(app.layers);
111
122
 
112
123
  const featureCreated = new VcsEvent<Feature<GeometryToType<T>>>();
113
124
  const creationFinished = new VcsEvent<Feature<GeometryToType<T>> | null>();
@@ -116,6 +127,9 @@ function startCreateFeatureSession<T extends GeometryType>(
116
127
 
117
128
  let currentInteraction: InteractionOfGeometryType<T> | null = null;
118
129
  let currentFeature: Feature<GeometryToType<T>> | null = null;
130
+ let snappingInteraction: CreationSnapping | null = null;
131
+ let layerSnappingInteraction: LayerSnapping | null = null;
132
+ let snapToLayers: VectorLayer[] = initialSnapToLayers?.slice() ?? [];
119
133
 
120
134
  /**
121
135
  * Ture if the currently active map is an ObliqueMap. set in setupActiveMap
@@ -131,16 +145,19 @@ function startCreateFeatureSession<T extends GeometryType>(
131
145
  const altitudeModeInUse =
132
146
  layer.vectorProperties.getAltitudeMode(altitudeModeFeature);
133
147
 
148
+ scratchLayer.vectorProperties.altitudeMode = altitudeModeInUse;
134
149
  pickingBehavior.setForAltitudeMode(altitudeModeInUse);
135
150
  };
136
151
 
137
- const vectorPropertiesListener =
138
- layer.vectorProperties.propertyChanged.addEventListener((properties) => {
139
- if (properties.includes('altitudeMode') && !featureAltitudeMode) {
152
+ const vectorPropertiesListener = syncScratchLayerVectorProperties(
153
+ scratchLayer,
154
+ layer,
155
+ () => {
156
+ if (!featureAltitudeMode) {
140
157
  altitudeModeChanged();
141
158
  }
142
- });
143
-
159
+ },
160
+ );
144
161
  altitudeModeChanged();
145
162
 
146
163
  let currentFeatureListener = (): void => {};
@@ -152,6 +169,16 @@ function startCreateFeatureSession<T extends GeometryType>(
152
169
  currentInteraction.destroy();
153
170
  currentInteraction = null;
154
171
  }
172
+ if (snappingInteraction) {
173
+ interactionChain.removeInteraction(snappingInteraction);
174
+ snappingInteraction.destroy();
175
+ snappingInteraction = null;
176
+ }
177
+ if (layerSnappingInteraction) {
178
+ interactionChain.removeInteraction(layerSnappingInteraction);
179
+ layerSnappingInteraction.destroy();
180
+ layerSnappingInteraction = null;
181
+ }
155
182
  interactionListeners.forEach((cb) => {
156
183
  cb();
157
184
  });
@@ -161,6 +188,18 @@ function startCreateFeatureSession<T extends GeometryType>(
161
188
  const createInteraction = (): void => {
162
189
  destroyCurrentInteraction();
163
190
  currentInteraction = createInteractionForGeometryType(geometryType);
191
+ layerSnappingInteraction = new LayerSnapping(
192
+ snapToLayers,
193
+ scratchLayer,
194
+ (f) => currentFeature !== f,
195
+ snapTo,
196
+ );
197
+ if (
198
+ geometryType === GeometryType.Polygon ||
199
+ geometryType === GeometryType.LineString
200
+ ) {
201
+ snappingInteraction = new CreationSnapping(scratchLayer, snapTo);
202
+ }
164
203
 
165
204
  interactionListeners = [
166
205
  currentInteraction.created.addEventListener((geometry) => {
@@ -187,6 +226,9 @@ function startCreateFeatureSession<T extends GeometryType>(
187
226
  };
188
227
  layer.addFeatures([currentFeature]);
189
228
  featureCreated.raiseEvent(currentFeature);
229
+ if (snappingInteraction) {
230
+ snappingInteraction.setGeometry(geometry as LineString | Polygon);
231
+ }
190
232
  }),
191
233
  currentInteraction.finished.addEventListener((geometry) => {
192
234
  if (isOblique) {
@@ -214,6 +256,10 @@ function startCreateFeatureSession<T extends GeometryType>(
214
256
  }
215
257
  }),
216
258
  ];
259
+ interactionChain.addInteraction(layerSnappingInteraction);
260
+ if (snappingInteraction) {
261
+ interactionChain.addInteraction(snappingInteraction);
262
+ }
217
263
  interactionChain.addInteraction(currentInteraction);
218
264
  };
219
265
  createInteraction();
@@ -252,6 +298,9 @@ function startCreateFeatureSession<T extends GeometryType>(
252
298
 
253
299
  const stop = (): void => {
254
300
  isStopped = true; // setting stopped true immediately, to prevent the recreation of the interaction chain on finished
301
+ app.layers.remove(scratchLayer);
302
+ scratchLayer.destroy();
303
+
255
304
  if (app.maps.target) {
256
305
  app.maps.target.style.cursor = cursorMap.auto;
257
306
  }
@@ -292,6 +341,15 @@ function startCreateFeatureSession<T extends GeometryType>(
292
341
  }
293
342
  }
294
343
  },
344
+ get snapToLayers(): VectorLayer[] {
345
+ return snapToLayers.slice();
346
+ },
347
+ set snapToLayers(layers: VectorLayer[]) {
348
+ snapToLayers = layers.slice();
349
+ if (layerSnappingInteraction) {
350
+ layerSnappingInteraction.layers = snapToLayers;
351
+ }
352
+ },
295
353
  featureCreated,
296
354
  creationFinished,
297
355
  stopped,
@@ -8,6 +8,7 @@ import type { Feature } from 'ol/index.js';
8
8
  import type { EventsKey } from 'ol/events.js';
9
9
  import { unByKey } from 'ol/Observable.js';
10
10
  import { getLogger } from '@vcsuite/logger';
11
+ import { Math as CesiumMath } from '@vcmap-cesium/engine';
11
12
 
12
13
  import VcsEvent from '../../vcsEvent.js';
13
14
  import {
@@ -18,6 +19,7 @@ import {
18
19
  } from './editorSessionHelpers.js';
19
20
  import createTransformationHandler from './transformation/transformationHandler.js';
20
21
  import {
22
+ AxisAndPlanes,
21
23
  TransformationHandler,
22
24
  TransformationMode,
23
25
  } from './transformation/transformationTypes.js';
@@ -28,7 +30,7 @@ import ScaleInteraction from './transformation/scaleInteraction.js';
28
30
  import { createSync, obliqueGeometry } from '../../layer/vectorSymbols.js';
29
31
  import ExtrudeInteraction from './transformation/extrudeInteraction.js';
30
32
  import ObliqueMap from '../../map/obliqueMap.js';
31
- import { ensureFeatureAbsolute, geometryChangeKeys } from './editorHelpers.js';
33
+ import { geometryChangeKeys } from './editorHelpers.js';
32
34
  import CesiumMap from '../../map/cesiumMap.js';
33
35
  import EnsureHandlerSelectionInteraction from './interactions/ensureHandlerSelectionInteraction.js';
34
36
  import EditFeaturesMouseOverInteraction from './interactions/editFeaturesMouseOverInteraction.js';
@@ -112,12 +114,18 @@ function clearCreateSync(
112
114
  export type EditFeaturesSession = EditorSession<SessionType.EDIT_FEATURES> & {
113
115
  readonly mode: TransformationMode;
114
116
  /**
115
- * Function for rotating features. Takes angle in radians as parameter.
117
+ * Function for rotating features. Takes angle in radians as parameter. you can provide an axis to rotate around for features & primitives
116
118
  * @param angle - in radians
119
+ * @param axis - optional axis. only has effect when rotating a single model or primitive
117
120
  */
118
- rotate(angle: number): void;
121
+ rotate(angle: number, axis?: AxisAndPlanes): void;
119
122
  translate(dx: number, dy: number, dz: number): void;
120
- scale(sx: number, sy: number): void;
123
+ /**
124
+ * @param sx
125
+ * @param sy
126
+ * @param sz - optional sz. only has effect when rotating a single model or primitive
127
+ */
128
+ scale(sx: number, sy: number, sz?: number): void;
121
129
  setMode(mode: TransformationMode): void;
122
130
  modeChanged: VcsEvent<TransformationMode>;
123
131
  setFeatures(features: Feature[]): void;
@@ -204,16 +212,22 @@ function startEditFeaturesSession(
204
212
  let destroyTransformation = (): void => {};
205
213
  let transformationHandler: TransformationHandler | undefined;
206
214
  const translate = (dx: number, dy: number, dz: number): void => {
207
- transformationHandler?.translate?.(dx, dy, dz);
215
+ transformationHandler?.translate?.(dx, dy, dz); // XXX should we changes this in 2D to change the layout to XY?
208
216
  currentFeatures.forEach((f) => {
209
217
  const geometry = f[obliqueGeometry] ?? f.getGeometry(); // XXX wont work in oblqiue
210
218
  geometry!.applyTransform(
211
- (input: number[], output: number[] | undefined): number[] => {
219
+ (
220
+ input: number[],
221
+ output: number[] | undefined,
222
+ stride = 2,
223
+ ): number[] => {
212
224
  const inputLength = input.length;
213
- for (let i = 0; i < inputLength; i += 3) {
225
+ for (let i = 0; i < inputLength; i += stride) {
214
226
  output![i] = input[i] + dx;
215
227
  output![i + 1] = input[i + 1] + dy;
216
- output![i + 2] = input[i + 2] + dz;
228
+ if (stride > 2) {
229
+ output![i + 2] = input[i + 2] + dz;
230
+ }
217
231
  }
218
232
  return output!;
219
233
  },
@@ -221,39 +235,92 @@ function startEditFeaturesSession(
221
235
  });
222
236
  };
223
237
 
224
- const rotate = (angle: number): void => {
225
- let center = transformationHandler?.center;
226
- if (!center) {
227
- const extent = createEmptyExtent();
238
+ const rotate = (
239
+ angle: number,
240
+ axis: AxisAndPlanes = AxisAndPlanes.Z,
241
+ ): void => {
242
+ if (
243
+ currentFeatures.length === 1 &&
244
+ currentFeatures[0].getGeometry()?.getType() === 'Point' &&
245
+ layer.vectorProperties.renderAs(currentFeatures[0]) !== 'geometry'
246
+ ) {
247
+ if (axis === AxisAndPlanes.Z) {
248
+ const currentRotation = layer.vectorProperties.getModelHeading(
249
+ currentFeatures[0],
250
+ );
251
+ currentFeatures[0].set(
252
+ 'olcs_modelHeading',
253
+ currentRotation - CesiumMath.toDegrees(angle),
254
+ );
255
+ } else if (axis === AxisAndPlanes.X) {
256
+ const currentRotation = layer.vectorProperties.getModelPitch(
257
+ currentFeatures[0],
258
+ );
259
+ currentFeatures[0].set(
260
+ 'olcs_modelPitch',
261
+ currentRotation - CesiumMath.toDegrees(angle),
262
+ );
263
+ } else if (axis === AxisAndPlanes.Y) {
264
+ const currentRotation = layer.vectorProperties.getModelRoll(
265
+ currentFeatures[0],
266
+ );
267
+ currentFeatures[0].set(
268
+ 'olcs_modelRoll',
269
+ currentRotation - CesiumMath.toDegrees(angle),
270
+ );
271
+ }
272
+ } else {
273
+ let center = transformationHandler?.center;
274
+ if (!center) {
275
+ const extent = createEmptyExtent();
276
+ currentFeatures.forEach((f) => {
277
+ extendExtent(extent, f.getGeometry()!.getExtent()); // XXX wont work in oblqiue
278
+ });
279
+ if (!isEmpty(extent)) {
280
+ center = getCenter(extent);
281
+ }
282
+ }
228
283
  currentFeatures.forEach((f) => {
229
- extendExtent(extent, f.getGeometry()!.getExtent()); // XXX wont work in oblqiue
284
+ const geometry = f[obliqueGeometry] ?? f.getGeometry(); // XXX wont work in oblqiue
285
+ geometry!.rotate(angle, center!);
230
286
  });
231
- if (!isEmpty(extent)) {
232
- center = getCenter(extent);
233
- }
234
287
  }
235
- currentFeatures.forEach((f) => {
236
- const geometry = f[obliqueGeometry] ?? f.getGeometry(); // XXX wont work in oblqiue
237
- geometry!.rotate(angle, center!);
238
- });
239
288
  };
240
289
 
241
- const scale = (sx: number, sy: number): void => {
242
- let center = transformationHandler?.center;
243
- if (!center) {
244
- // XXX copy paste
245
- const extent = createEmptyExtent();
290
+ const scale = (sx: number, sy: number, sz?: number): void => {
291
+ if (
292
+ currentFeatures.length === 1 &&
293
+ currentFeatures[0].getGeometry()?.getType() === 'Point' &&
294
+ layer.vectorProperties.renderAs(currentFeatures[0]) !== 'geometry'
295
+ ) {
296
+ const feature = currentFeatures[0];
297
+ const scaleX = layer.vectorProperties.getModelScaleX(feature);
298
+ const scaleY = layer.vectorProperties.getModelScaleY(feature);
299
+ const scaleZ = layer.vectorProperties.getModelScaleZ(feature);
300
+ currentFeatures[0].set('olcs_modelScaleX', scaleX * sx);
301
+ currentFeatures[0].set('olcs_modelScaleY', scaleY * sy);
302
+ let usedSz = sz;
303
+ if (usedSz == null) {
304
+ usedSz = sx === sy ? sx : 1;
305
+ }
306
+ currentFeatures[0].set('olcs_modelScaleZ', scaleZ * usedSz);
307
+ } else {
308
+ let center = transformationHandler?.center;
309
+ if (!center) {
310
+ // XXX copy paste
311
+ const extent = createEmptyExtent();
312
+ currentFeatures.forEach((f) => {
313
+ extendExtent(extent, f.getGeometry()!.getExtent());
314
+ });
315
+ if (!isEmpty(extent)) {
316
+ center = getCenter(extent);
317
+ }
318
+ }
246
319
  currentFeatures.forEach((f) => {
247
- extendExtent(extent, f.getGeometry()!.getExtent());
320
+ const geometry = f[obliqueGeometry] ?? f.getGeometry();
321
+ geometry!.scale(sx, sy, center);
248
322
  });
249
- if (!isEmpty(extent)) {
250
- center = getCenter(extent);
251
- }
252
323
  }
253
- currentFeatures.forEach((f) => {
254
- const geometry = f[obliqueGeometry] ?? f.getGeometry();
255
- geometry!.scale(sx, sy, center);
256
- });
257
324
  };
258
325
 
259
326
  const createTransformations = (): void => {
@@ -281,8 +348,6 @@ function startEditFeaturesSession(
281
348
  interaction = new ExtrudeInteraction(transformationHandler);
282
349
  interaction.extruded.addEventListener((dz) => {
283
350
  currentFeatures.forEach((f) => {
284
- // eslint-disable-next-line no-void
285
- void ensureFeatureAbsolute(f, layer, app.maps.activeMap as CesiumMap);
286
351
  let extrudedHeight =
287
352
  (f.get('olcs_extrudedHeight') as number | undefined) ?? 0;
288
353
  extrudedHeight += dz;
@@ -291,13 +356,13 @@ function startEditFeaturesSession(
291
356
  });
292
357
  } else if (mode === TransformationMode.ROTATE) {
293
358
  interaction = new RotateInteraction(transformationHandler);
294
- interaction.rotated.addEventListener(({ angle }) => {
295
- rotate(angle);
359
+ interaction.rotated.addEventListener(({ angle, axis }) => {
360
+ rotate(angle, axis);
296
361
  });
297
362
  } else if (mode === TransformationMode.SCALE) {
298
363
  interaction = new ScaleInteraction(transformationHandler);
299
- interaction.scaled.addEventListener(([sx, sy]) => {
300
- scale(sx, sy);
364
+ interaction.scaled.addEventListener(([sx, sy, sz]) => {
365
+ scale(sx, sy, sz);
301
366
  });
302
367
  } else {
303
368
  throw new Error(`Unknown transformation mode ${String(mode)}`);
@@ -378,6 +443,7 @@ function startEditFeaturesSession(
378
443
  });
379
444
  allowPickingMap.clear();
380
445
  app.layers.remove(scratchLayer);
446
+ scratchLayer.destroy();
381
447
  modeChanged.destroy();
382
448
  removeRightClickStart();
383
449
  rightClickStart.destroy();