@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
@@ -3,7 +3,10 @@ import type { Coordinate } from 'ol/coordinate.js';
3
3
  import AbstractInteraction, {
4
4
  EventAfterEventHandler,
5
5
  } from '../../../interaction/abstractInteraction.js';
6
- import { EventType } from '../../../interaction/interactionType.js';
6
+ import {
7
+ EventType,
8
+ ModificationKeyType,
9
+ } from '../../../interaction/interactionType.js';
7
10
  import VcsEvent from '../../../vcsEvent.js';
8
11
  import {
9
12
  alreadyTransformedToImage,
@@ -31,7 +34,10 @@ class CreateLineStringInteraction
31
34
  created = new VcsEvent<LineString>();
32
35
 
33
36
  constructor() {
34
- super(EventType.CLICKMOVE | EventType.DBLCLICK);
37
+ super(
38
+ EventType.CLICKMOVE | EventType.DBLCLICK,
39
+ ModificationKeyType.NONE | ModificationKeyType.CTRL,
40
+ );
35
41
  this.setActive();
36
42
  }
37
43
 
@@ -57,7 +63,7 @@ class CreateLineStringInteraction
57
63
 
58
64
  if (event.type & EventType.CLICK) {
59
65
  if (!this._geometry) {
60
- this._geometry = new LineString([event.positionOrPixel], 'XYZ');
66
+ this._geometry = new LineString([event.positionOrPixel]);
61
67
  if (event.map instanceof ObliqueMap) {
62
68
  this._geometry[alreadyTransformedToImage] = true;
63
69
  } else {
@@ -31,7 +31,7 @@ class CreatePointInteraction
31
31
  }
32
32
 
33
33
  pipe(event: EventAfterEventHandler): Promise<EventAfterEventHandler> {
34
- this._geometry = new Point(event.positionOrPixel, 'XYZ');
34
+ this._geometry = new Point(event.positionOrPixel);
35
35
  if (event.map instanceof ObliqueMap) {
36
36
  this._geometry[alreadyTransformedToImage] = true;
37
37
  } else {
@@ -3,7 +3,10 @@ import type { Coordinate } from 'ol/coordinate.js';
3
3
  import AbstractInteraction, {
4
4
  EventAfterEventHandler,
5
5
  } from '../../../interaction/abstractInteraction.js';
6
- import { EventType } from '../../../interaction/interactionType.js';
6
+ import {
7
+ EventType,
8
+ ModificationKeyType,
9
+ } from '../../../interaction/interactionType.js';
7
10
  import VcsEvent from '../../../vcsEvent.js';
8
11
  import {
9
12
  alreadyTransformedToImage,
@@ -12,6 +15,11 @@ import {
12
15
  import ObliqueMap from '../../../map/obliqueMap.js';
13
16
  import { CreateInteraction } from '../createFeatureSession.js';
14
17
 
18
+ /**
19
+ * Set on polygon geometries which have a validity placeholder active
20
+ */
21
+ export const validityPlaceholder = Symbol('validityPlaceholder');
22
+
15
23
  class CreatePolygonInteraction
16
24
  extends AbstractInteraction
17
25
  implements CreateInteraction<Polygon>
@@ -34,7 +42,10 @@ class CreatePolygonInteraction
34
42
  created = new VcsEvent<Polygon>();
35
43
 
36
44
  constructor() {
37
- super(EventType.CLICKMOVE | EventType.DBLCLICK);
45
+ super(
46
+ EventType.CLICKMOVE | EventType.DBLCLICK,
47
+ ModificationKeyType.NONE | ModificationKeyType.CTRL,
48
+ );
38
49
  this.setActive();
39
50
  }
40
51
 
@@ -60,12 +71,13 @@ class CreatePolygonInteraction
60
71
 
61
72
  if (event.type & EventType.CLICK) {
62
73
  if (!this._geometry) {
63
- this._geometry = new Polygon([[event.positionOrPixel.slice()]], 'XYZ');
74
+ this._geometry = new Polygon([[event.positionOrPixel.slice()]]);
64
75
  if (event.map instanceof ObliqueMap) {
65
76
  this._geometry[alreadyTransformedToImage] = true;
66
77
  } else {
67
78
  this._geometry[alreadyTransformedToMercator] = true;
68
79
  }
80
+ this._geometry[validityPlaceholder] = true;
69
81
  this.created.raiseEvent(this._geometry);
70
82
  this._coordinates = [event.positionOrPixel.slice()];
71
83
  this._lastCoordinate = [...event.positionOrPixel];
@@ -76,6 +88,7 @@ class CreatePolygonInteraction
76
88
  this._lastCoordinate = [...(this._lastCoordinate as Coordinate)];
77
89
  this._coordinates.splice(2, 1, this._lastCoordinate);
78
90
  this._validityPlaceHolder = null;
91
+ this._geometry[validityPlaceholder] = false;
79
92
  } else {
80
93
  this._lastCoordinate = [...(this._lastCoordinate as Coordinate)];
81
94
  this._coordinates.push(this._lastCoordinate);
@@ -0,0 +1,226 @@
1
+ import { LineString, Polygon } from 'ol/geom.js';
2
+ import { Coordinate } from 'ol/coordinate.js';
3
+ import { unByKey } from 'ol/Observable.js';
4
+ import AbstractInteraction from '../../../interaction/abstractInteraction.js';
5
+ import {
6
+ EventType,
7
+ ModificationKeyType,
8
+ } from '../../../interaction/interactionType.js';
9
+ import {
10
+ getSnappedCoordinateForResults,
11
+ getAngleSnapResult,
12
+ setSnappingFeatures,
13
+ SnapResult,
14
+ getGeometrySnapResult,
15
+ SnapType,
16
+ snapTypes,
17
+ } from '../snappingHelpers.js';
18
+ import { getCartesianBearing } from '../../math.js';
19
+ import type VectorLayer from '../../../layer/vectorLayer.js';
20
+ import { validityPlaceholder } from './createPolygonInteraction.js';
21
+ import {
22
+ alreadySnapped,
23
+ SnappingInteractionEvent,
24
+ } from '../editorSessionHelpers.js';
25
+
26
+ function getBearings(coordinates: Coordinate[]): number[] {
27
+ // we dont want to take into account the last bearing, since that would be our own
28
+ const length = coordinates.length - 2;
29
+ if (length > 0) {
30
+ const bearings = new Array<number>(length);
31
+ for (let i = 0; i < length; i++) {
32
+ bearings[i] = getCartesianBearing(coordinates[i], coordinates[i + 1]);
33
+ }
34
+ return bearings;
35
+ }
36
+
37
+ return [];
38
+ }
39
+
40
+ export default class CreationSnapping extends AbstractInteraction {
41
+ private _coordinates: Coordinate[] = [];
42
+
43
+ private _bearings: number[] = [];
44
+
45
+ private _scratchLayer: VectorLayer;
46
+
47
+ private _isPolygon = false;
48
+
49
+ private _coordinatesDirty = false;
50
+
51
+ private _geometryLister: (() => void) | undefined;
52
+
53
+ private _removeFeatures: (() => void) | undefined;
54
+
55
+ private _snappingGeometry: LineString | undefined;
56
+
57
+ private _snapToVertex = true;
58
+
59
+ private _snapToEdge = true;
60
+
61
+ private _snapOrthogonal = true;
62
+
63
+ private _snapParallel = true;
64
+
65
+ constructor(scratchLayer: VectorLayer, snapTo: SnapType[] = [...snapTypes]) {
66
+ super(
67
+ EventType.CLICKMOVE | EventType.DBLCLICK,
68
+ ModificationKeyType.NONE | ModificationKeyType.CTRL,
69
+ );
70
+
71
+ this._scratchLayer = scratchLayer;
72
+ this.snapTo = snapTo;
73
+ }
74
+
75
+ get snapTo(): SnapType[] {
76
+ const snapTo: SnapType[] = [];
77
+ if (this._snapToVertex) {
78
+ snapTo.push('vertex');
79
+ }
80
+
81
+ if (this._snapToEdge) {
82
+ snapTo.push('edge');
83
+ }
84
+
85
+ if (this._snapOrthogonal) {
86
+ snapTo.push('orthogonal');
87
+ }
88
+
89
+ if (this._snapParallel) {
90
+ snapTo.push('parallel');
91
+ }
92
+
93
+ return snapTo;
94
+ }
95
+
96
+ set snapTo(snapTo: SnapType[]) {
97
+ this._snapToVertex = snapTo.includes('vertex');
98
+ this._snapToEdge = snapTo.includes('edge');
99
+ this._snapOrthogonal = snapTo.includes('orthogonal');
100
+ this._snapParallel = snapTo.includes('parallel');
101
+ }
102
+
103
+ private _setCoordinates(coordinates: Coordinate[]): void {
104
+ this._coordinates = coordinates;
105
+ this._bearings = getBearings(this._coordinates);
106
+ if (this._coordinates.length > 2) {
107
+ this._snappingGeometry = new LineString(
108
+ this._coordinates.slice(0, this._coordinates.length - 1),
109
+ );
110
+ }
111
+ }
112
+
113
+ setGeometry(geometry: LineString | Polygon): void {
114
+ this._geometryLister?.();
115
+ this._snappingGeometry = undefined;
116
+ let setCoordinates: () => void;
117
+ if (geometry instanceof Polygon) {
118
+ this._isPolygon = true;
119
+ setCoordinates = (): void => {
120
+ if (!geometry[validityPlaceholder]) {
121
+ this._setCoordinates(geometry.getCoordinates()[0]);
122
+ }
123
+ };
124
+ } else {
125
+ this._isPolygon = false;
126
+ setCoordinates = (): void => {
127
+ this._setCoordinates(geometry.getCoordinates());
128
+ };
129
+ }
130
+ setCoordinates();
131
+ const key = geometry.on('change', () => {
132
+ if (this._coordinatesDirty) {
133
+ setCoordinates();
134
+ this._coordinatesDirty = false;
135
+ }
136
+ });
137
+ this._geometryLister = (): void => {
138
+ unByKey(key);
139
+ };
140
+ }
141
+
142
+ pipe(event: SnappingInteractionEvent): Promise<SnappingInteractionEvent> {
143
+ this._removeFeatures?.();
144
+ if (event.type === EventType.CLICK) {
145
+ event.chainEnded?.addEventListener(() => {
146
+ this._coordinatesDirty = true;
147
+ });
148
+ }
149
+ if (
150
+ !event[alreadySnapped] &&
151
+ event.key !== ModificationKeyType.CTRL &&
152
+ this._coordinates.length >= 3
153
+ ) {
154
+ const results = new Array<SnapResult | undefined>(2);
155
+ const maxDistanceSquared =
156
+ (event.map.getCurrentResolution(event.positionOrPixel!) * 12) ** 2;
157
+
158
+ if (this._snappingGeometry) {
159
+ results[0] = getGeometrySnapResult(
160
+ [this._snappingGeometry],
161
+ event.positionOrPixel!,
162
+ maxDistanceSquared,
163
+ this._snapToVertex,
164
+ this._snapToEdge,
165
+ );
166
+ }
167
+
168
+ if (!results[0] && (this._snapOrthogonal || this._snapParallel)) {
169
+ results[0] = getAngleSnapResult(
170
+ event.positionOrPixel!,
171
+ this._coordinates.at(-2)!,
172
+ this._coordinates.at(-3)!,
173
+ this._bearings,
174
+ this._coordinates.length - 2,
175
+ maxDistanceSquared,
176
+ this._snapOrthogonal,
177
+ this._snapParallel,
178
+ );
179
+
180
+ if (this._isPolygon) {
181
+ const newCandidate = results[0]?.snapped ?? event.positionOrPixel!;
182
+ results[1] = getAngleSnapResult(
183
+ newCandidate,
184
+ this._coordinates.at(0)!,
185
+ this._coordinates.at(1)!,
186
+ this._bearings,
187
+ 0,
188
+ maxDistanceSquared,
189
+ this._snapOrthogonal,
190
+ this._snapParallel,
191
+ );
192
+ }
193
+ }
194
+
195
+ const lastResult = getSnappedCoordinateForResults(
196
+ results,
197
+ this._coordinates,
198
+ maxDistanceSquared,
199
+ );
200
+
201
+ if (lastResult) {
202
+ if (event.positionOrPixel!.length > lastResult.length) {
203
+ lastResult[2] = event.positionOrPixel![2];
204
+ } else if (event.positionOrPixel!.length < lastResult.length) {
205
+ lastResult.pop();
206
+ }
207
+
208
+ event.positionOrPixel = lastResult;
209
+
210
+ this._removeFeatures = setSnappingFeatures(
211
+ results,
212
+ this._coordinates,
213
+ this._scratchLayer,
214
+ );
215
+ }
216
+ }
217
+
218
+ return Promise.resolve(event);
219
+ }
220
+
221
+ destroy(): void {
222
+ this._geometryLister?.();
223
+ this._removeFeatures?.();
224
+ super.destroy();
225
+ }
226
+ }
@@ -46,9 +46,10 @@ class EditGeometryMouseOverInteraction extends AbstractInteraction {
46
46
  constructor(denyRemoval?: boolean) {
47
47
  super(
48
48
  EventType.MOVE,
49
- denyRemoval
49
+ (denyRemoval
50
50
  ? ModificationKeyType.NONE
51
- : ModificationKeyType.NONE | ModificationKeyType.SHIFT,
51
+ : ModificationKeyType.NONE | ModificationKeyType.SHIFT) |
52
+ ModificationKeyType.CTRL,
52
53
  );
53
54
 
54
55
  this.setActive();
@@ -7,7 +7,7 @@ import {
7
7
  EventType,
8
8
  ModificationKeyType,
9
9
  } from '../../../interaction/interactionType.js';
10
- import { cartesian2DDistance } from '../../math.js';
10
+ import { cartesian2DDistanceSquared } from '../../math.js';
11
11
  import {
12
12
  createVertex,
13
13
  getOlcsPropsFromFeature,
@@ -16,6 +16,9 @@ import {
16
16
  type Vertex,
17
17
  } from '../editorHelpers.js';
18
18
  import VcsEvent from '../../../vcsEvent.js';
19
+ import { is2DLayout } from '../../geometryHelpers.js';
20
+ import { isClampedHeightReference } from '../../featureconverter/vectorHeightInfo.js';
21
+ import VectorProperties from '../../../layer/vectorProperties.js';
19
22
 
20
23
  export type VertexInsertedEvent = {
21
24
  vertex: Vertex;
@@ -31,6 +34,8 @@ class InsertVertexInteraction extends AbstractInteraction {
31
34
 
32
35
  private _isLinearRing: boolean;
33
36
 
37
+ private _vectorProperties: VectorProperties;
38
+
34
39
  /**
35
40
  * @param feature
36
41
  * @param geometry
@@ -38,11 +43,13 @@ class InsertVertexInteraction extends AbstractInteraction {
38
43
  constructor(
39
44
  feature: Feature<LineString | Polygon>,
40
45
  geometry: LineString | LinearRing,
46
+ vectorProperties: VectorProperties,
41
47
  ) {
42
48
  super(EventType.CLICK, ModificationKeyType.NONE);
43
49
 
44
50
  this._feature = feature;
45
51
  this._geometry = geometry;
52
+ this._vectorProperties = vectorProperties;
46
53
  this._isLinearRing = this._geometry instanceof LinearRing;
47
54
  this.setActive();
48
55
  }
@@ -56,15 +63,27 @@ class InsertVertexInteraction extends AbstractInteraction {
56
63
  if (this._isLinearRing) {
57
64
  lineCoords.push(lineCoords[0]);
58
65
  }
59
- const distance = cartesian2DDistance(closestCoord, coordinate); // todo respect altitude mode here. e.g. distance3D
60
- if (distance < event.map.getCurrentResolution(coordinate) * 5) {
66
+ const distanceSquared = cartesian2DDistanceSquared(
67
+ closestCoord,
68
+ coordinate,
69
+ ); // todo respect altitude mode here. e.g. distance3D
70
+ const is2DLine =
71
+ is2DLayout(this._geometry.getLayout()) ||
72
+ isClampedHeightReference(
73
+ this._vectorProperties.getAltitudeMode(this._feature),
74
+ );
75
+
76
+ // XXX how to handle relative to ground height references?
77
+ if (
78
+ distanceSquared <
79
+ (event.map.getCurrentResolution(coordinate) * 5) ** 2
80
+ ) {
61
81
  const length = lineCoords.length - 1;
62
82
  let i = 0;
63
83
  for (i; i < length; i++) {
64
- const onLine =
65
- this._feature.get('olcs_altitudeMode') === 'clampToGround' // todo altitude mode
66
- ? pointOnLine2D(lineCoords[i], lineCoords[i + 1], closestCoord)
67
- : pointOnLine3D(lineCoords[i], lineCoords[i + 1], closestCoord);
84
+ const onLine = is2DLine
85
+ ? pointOnLine2D(lineCoords[i], lineCoords[i + 1], closestCoord)
86
+ : pointOnLine3D(lineCoords[i], lineCoords[i + 1], closestCoord);
68
87
  if (onLine) {
69
88
  break;
70
89
  }
@@ -78,6 +97,7 @@ class InsertVertexInteraction extends AbstractInteraction {
78
97
  vertex: createVertex(
79
98
  closestCoord,
80
99
  getOlcsPropsFromFeature(this._feature),
100
+ -1,
81
101
  ),
82
102
  index,
83
103
  });
@@ -0,0 +1,136 @@
1
+ import { Feature } from 'ol';
2
+ import VectorSource from 'ol/source/Vector.js';
3
+ import AbstractInteraction from '../../../interaction/abstractInteraction.js';
4
+ import {
5
+ EventType,
6
+ ModificationKeyType,
7
+ } from '../../../interaction/interactionType.js';
8
+ import VectorLayer from '../../../layer/vectorLayer.js';
9
+ import { originalFeatureSymbol } from '../../../layer/vectorSymbols.js';
10
+ import ObliqueMap from '../../../map/obliqueMap.js';
11
+ import type VectorObliqueImpl from '../../../layer/oblique/vectorObliqueImpl.js';
12
+ import {
13
+ alreadySnapped,
14
+ SnappingInteractionEvent,
15
+ } from '../editorSessionHelpers.js';
16
+ import {
17
+ setSnappingFeatures,
18
+ getGeometrySnapResult,
19
+ SnapType,
20
+ } from '../snappingHelpers.js';
21
+
22
+ export default class LayerSnapping extends AbstractInteraction {
23
+ layers: VectorLayer[];
24
+
25
+ private _scratchLayer: VectorLayer;
26
+
27
+ private _removeFeatures: (() => void) | undefined;
28
+
29
+ private _filter: (f: Feature) => boolean;
30
+
31
+ private _snapToVertex = true;
32
+
33
+ private _snapToEdge = true;
34
+
35
+ constructor(
36
+ layers: VectorLayer[],
37
+ scratchLayer: VectorLayer,
38
+ filter: (f: Feature) => boolean,
39
+ snapTo: SnapType[] = ['vertex', 'edge'],
40
+ type: EventType = EventType.CLICKMOVE | EventType.DBLCLICK,
41
+ ) {
42
+ super(type, ModificationKeyType.NONE | ModificationKeyType.CTRL);
43
+
44
+ this.layers = layers;
45
+ this._scratchLayer = scratchLayer;
46
+ this._filter = filter;
47
+ this.snapTo = snapTo;
48
+ }
49
+
50
+ get snapTo(): SnapType[] {
51
+ const snapTo: SnapType[] = [];
52
+ if (this._snapToVertex) {
53
+ snapTo.push('vertex');
54
+ }
55
+
56
+ if (this._snapToEdge) {
57
+ snapTo.push('edge');
58
+ }
59
+
60
+ return snapTo;
61
+ }
62
+
63
+ set snapTo(snapTo: SnapType[]) {
64
+ this._snapToVertex = snapTo.includes('vertex');
65
+ this._snapToEdge = snapTo.includes('edge');
66
+ }
67
+
68
+ pipe(event: SnappingInteractionEvent): Promise<SnappingInteractionEvent> {
69
+ this._removeFeatures?.();
70
+ if (event.key !== ModificationKeyType.CTRL) {
71
+ const coordinate = event.positionOrPixel!;
72
+ const bufferDistance = event.map.getCurrentResolution(coordinate) * 12;
73
+ const maxDistanceSquared = bufferDistance ** 2;
74
+
75
+ const isOblique = event.map instanceof ObliqueMap;
76
+
77
+ const geometries = this.layers
78
+ .flatMap((layer) => {
79
+ let source: VectorSource;
80
+
81
+ if (isOblique) {
82
+ source = (
83
+ layer.getImplementationsForMap(event.map)[0] as VectorObliqueImpl
84
+ )
85
+ .getOLLayer()
86
+ .getSource() as VectorSource;
87
+ } else {
88
+ source = layer.getSource();
89
+ }
90
+
91
+ return source.getFeaturesInExtent([
92
+ coordinate[0] - bufferDistance,
93
+ coordinate[1] - bufferDistance,
94
+ coordinate[0] + bufferDistance,
95
+ coordinate[1] + bufferDistance,
96
+ ]);
97
+ })
98
+ .filter((feature) => {
99
+ const originalFeature = feature[originalFeatureSymbol] ?? feature;
100
+ return this._filter(originalFeature);
101
+ })
102
+ .map((f) => f.getGeometry()!);
103
+
104
+ const result = getGeometrySnapResult(
105
+ geometries,
106
+ coordinate,
107
+ maxDistanceSquared,
108
+ this._snapToVertex,
109
+ this._snapToEdge,
110
+ );
111
+
112
+ if (result) {
113
+ const closest = result.snapped;
114
+ if (coordinate.length > closest.length) {
115
+ closest[2] = coordinate[2];
116
+ } else if (coordinate.length < closest.length) {
117
+ closest.pop();
118
+ }
119
+ event.positionOrPixel = closest;
120
+ event[alreadySnapped] = true;
121
+ this._removeFeatures = setSnappingFeatures(
122
+ [result],
123
+ [result.snapped],
124
+ this._scratchLayer,
125
+ );
126
+ }
127
+ }
128
+ return Promise.resolve(event);
129
+ }
130
+
131
+ destroy(): void {
132
+ this._removeFeatures?.();
133
+ this.layers = [];
134
+ super.destroy();
135
+ }
136
+ }
@@ -2,7 +2,10 @@ import Feature from 'ol/Feature.js';
2
2
  import AbstractInteraction, {
3
3
  EventAfterEventHandler,
4
4
  } from '../../../interaction/abstractInteraction.js';
5
- import { EventType } from '../../../interaction/interactionType.js';
5
+ import {
6
+ EventType,
7
+ ModificationKeyType,
8
+ } from '../../../interaction/interactionType.js';
6
9
  import { vertexSymbol } from '../editorSymbols.js';
7
10
  import VcsEvent from '../../../vcsEvent.js';
8
11
  import { Vertex } from '../editorHelpers.js';
@@ -20,7 +23,10 @@ class TranslateVertexInteraction extends AbstractInteraction {
20
23
  private _feature: Feature;
21
24
 
22
25
  constructor(feature: Feature) {
23
- super(EventType.DRAGEVENTS);
26
+ super(
27
+ EventType.DRAGEVENTS,
28
+ ModificationKeyType.NONE | ModificationKeyType.CTRL,
29
+ );
24
30
  this._feature = feature;
25
31
  this.setActive();
26
32
  }