@deck.gl-community/editable-layers 9.0.0-alpha.1

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 (295) hide show
  1. package/README.md +82 -0
  2. package/dist/constants.d.ts +14 -0
  3. package/dist/constants.js +14 -0
  4. package/dist/curve-utils.d.ts +2 -0
  5. package/dist/curve-utils.js +61 -0
  6. package/dist/edit-modes/composite-mode.d.ts +14 -0
  7. package/dist/edit-modes/composite-mode.js +47 -0
  8. package/dist/edit-modes/draw-90degree-polygon-mode.d.ts +11 -0
  9. package/dist/edit-modes/draw-90degree-polygon-mode.js +179 -0
  10. package/dist/edit-modes/draw-circle-by-diameter-mode.d.ts +24 -0
  11. package/dist/edit-modes/draw-circle-by-diameter-mode.js +78 -0
  12. package/dist/edit-modes/draw-circle-from-center-mode.d.ts +22 -0
  13. package/dist/edit-modes/draw-circle-from-center-mode.js +70 -0
  14. package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.d.ts +5 -0
  15. package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.js +20 -0
  16. package/dist/edit-modes/draw-ellipse-using-three-points-mode.d.ts +5 -0
  17. package/dist/edit-modes/draw-ellipse-using-three-points-mode.js +16 -0
  18. package/dist/edit-modes/draw-line-string-mode.d.ts +25 -0
  19. package/dist/edit-modes/draw-line-string-mode.js +170 -0
  20. package/dist/edit-modes/draw-point-mode.d.ts +8 -0
  21. package/dist/edit-modes/draw-point-mode.js +28 -0
  22. package/dist/edit-modes/draw-polygon-by-dragging-mode.d.ts +14 -0
  23. package/dist/edit-modes/draw-polygon-by-dragging-mode.js +87 -0
  24. package/dist/edit-modes/draw-polygon-mode.d.ts +10 -0
  25. package/dist/edit-modes/draw-polygon-mode.js +143 -0
  26. package/dist/edit-modes/draw-rectangle-from-center-mode.d.ts +5 -0
  27. package/dist/edit-modes/draw-rectangle-from-center-mode.js +17 -0
  28. package/dist/edit-modes/draw-rectangle-mode.d.ts +5 -0
  29. package/dist/edit-modes/draw-rectangle-mode.js +11 -0
  30. package/dist/edit-modes/draw-rectangle-using-three-points-mode.d.ts +5 -0
  31. package/dist/edit-modes/draw-rectangle-using-three-points-mode.js +28 -0
  32. package/dist/edit-modes/draw-square-from-center-mode.d.ts +5 -0
  33. package/dist/edit-modes/draw-square-from-center-mode.js +35 -0
  34. package/dist/edit-modes/draw-square-mode.d.ts +5 -0
  35. package/dist/edit-modes/draw-square-mode.js +28 -0
  36. package/dist/edit-modes/duplicate-mode.d.ts +7 -0
  37. package/dist/edit-modes/duplicate-mode.js +17 -0
  38. package/dist/edit-modes/edit-mode.d.ts +11 -0
  39. package/dist/edit-modes/edit-mode.js +2 -0
  40. package/dist/edit-modes/elevation-mode.d.ts +13 -0
  41. package/dist/edit-modes/elevation-mode.js +49 -0
  42. package/dist/edit-modes/extend-line-string-mode.d.ts +9 -0
  43. package/dist/edit-modes/extend-line-string-mode.js +72 -0
  44. package/dist/edit-modes/extrude-mode.d.ts +15 -0
  45. package/dist/edit-modes/extrude-mode.js +186 -0
  46. package/dist/edit-modes/geojson-edit-mode.d.ts +33 -0
  47. package/dist/edit-modes/geojson-edit-mode.js +208 -0
  48. package/dist/edit-modes/immutable-feature-collection.d.ts +43 -0
  49. package/dist/edit-modes/immutable-feature-collection.js +300 -0
  50. package/dist/edit-modes/measure-angle-mode.d.ts +11 -0
  51. package/dist/edit-modes/measure-angle-mode.js +99 -0
  52. package/dist/edit-modes/measure-area-mode.d.ts +8 -0
  53. package/dist/edit-modes/measure-area-mode.js +50 -0
  54. package/dist/edit-modes/measure-distance-mode.d.ts +19 -0
  55. package/dist/edit-modes/measure-distance-mode.js +171 -0
  56. package/dist/edit-modes/modify-mode.d.ts +15 -0
  57. package/dist/edit-modes/modify-mode.js +203 -0
  58. package/dist/edit-modes/resize-circle-mode.d.ts +16 -0
  59. package/dist/edit-modes/resize-circle-mode.js +142 -0
  60. package/dist/edit-modes/rotate-mode.d.ts +17 -0
  61. package/dist/edit-modes/rotate-mode.js +151 -0
  62. package/dist/edit-modes/scale-mode.d.ts +27 -0
  63. package/dist/edit-modes/scale-mode.js +173 -0
  64. package/dist/edit-modes/snappable-mode.d.ts +21 -0
  65. package/dist/edit-modes/snappable-mode.js +109 -0
  66. package/dist/edit-modes/split-polygon-mode.d.ts +10 -0
  67. package/dist/edit-modes/split-polygon-mode.js +164 -0
  68. package/dist/edit-modes/three-click-polygon-mode.d.ts +10 -0
  69. package/dist/edit-modes/three-click-polygon-mode.js +72 -0
  70. package/dist/edit-modes/transform-mode.d.ts +9 -0
  71. package/dist/edit-modes/transform-mode.js +63 -0
  72. package/dist/edit-modes/translate-mode.d.ts +13 -0
  73. package/dist/edit-modes/translate-mode.js +113 -0
  74. package/dist/edit-modes/two-click-polygon-mode.d.ts +13 -0
  75. package/dist/edit-modes/two-click-polygon-mode.js +93 -0
  76. package/dist/edit-modes/types.d.ts +86 -0
  77. package/dist/edit-modes/types.js +1 -0
  78. package/dist/edit-modes/utils.d.ts +36 -0
  79. package/dist/edit-modes/utils.js +381 -0
  80. package/dist/edit-modes/view-mode.d.ts +3 -0
  81. package/dist/edit-modes/view-mode.js +3 -0
  82. package/dist/editable-layers/editable-geojson-layer.d.ts +98 -0
  83. package/dist/editable-layers/editable-geojson-layer.js +450 -0
  84. package/dist/editable-layers/editable-h3-cluster-layer.d.ts +34 -0
  85. package/dist/editable-layers/editable-h3-cluster-layer.js +164 -0
  86. package/dist/editable-layers/editable-layer.d.ts +49 -0
  87. package/dist/editable-layers/editable-layer.js +195 -0
  88. package/dist/editable-layers/editable-path-layer.d.ts +9 -0
  89. package/dist/editable-layers/editable-path-layer.js +34 -0
  90. package/dist/editable-layers/elevated-edit-handle-layer.d.ts +7 -0
  91. package/dist/editable-layers/elevated-edit-handle-layer.js +24 -0
  92. package/dist/editable-layers/junction-scatterplot-layer.d.ts +14 -0
  93. package/dist/editable-layers/junction-scatterplot-layer.js +41 -0
  94. package/dist/editable-layers/path-marker-layer/arrow-2d-geometry.d.ts +4 -0
  95. package/dist/editable-layers/path-marker-layer/arrow-2d-geometry.js +55 -0
  96. package/dist/editable-layers/path-marker-layer/create-path-markers.d.ts +16 -0
  97. package/dist/editable-layers/path-marker-layer/create-path-markers.js +75 -0
  98. package/dist/editable-layers/path-marker-layer/path-marker-layer.d.ts +40 -0
  99. package/dist/editable-layers/path-marker-layer/path-marker-layer.js +121 -0
  100. package/dist/editable-layers/path-marker-layer/polyline.d.ts +18 -0
  101. package/dist/editable-layers/path-marker-layer/polyline.js +37 -0
  102. package/dist/editable-layers/path-outline-layer/path-outline-layer.d.ts +26 -0
  103. package/dist/editable-layers/path-outline-layer/path-outline-layer.js +106 -0
  104. package/dist/editable-layers/selection-layer.d.ts +26 -0
  105. package/dist/editable-layers/selection-layer.js +167 -0
  106. package/dist/geojson-types.d.ts +58 -0
  107. package/dist/geojson-types.js +2 -0
  108. package/dist/index.cjs +5825 -0
  109. package/dist/index.cjs.map +7 -0
  110. package/dist/index.d.ts +60 -0
  111. package/dist/index.js +62 -0
  112. package/dist/lib/constants.d.ts +6 -0
  113. package/dist/lib/constants.js +6 -0
  114. package/dist/lib/deck-renderer/deck-cache.d.ts +14 -0
  115. package/dist/lib/deck-renderer/deck-cache.js +51 -0
  116. package/dist/lib/deck-renderer/deck-drawer.d.ts +63 -0
  117. package/dist/lib/deck-renderer/deck-drawer.js +232 -0
  118. package/dist/lib/feature.d.ts +10 -0
  119. package/dist/lib/feature.js +16 -0
  120. package/dist/lib/layer-mouse-event.d.ts +11 -0
  121. package/dist/lib/layer-mouse-event.js +24 -0
  122. package/dist/lib/layers/junctions-layer.d.ts +8 -0
  123. package/dist/lib/layers/junctions-layer.js +33 -0
  124. package/dist/lib/layers/segments-layer.d.ts +18 -0
  125. package/dist/lib/layers/segments-layer.js +94 -0
  126. package/dist/lib/layers/texts-layer.d.ts +8 -0
  127. package/dist/lib/layers/texts-layer.js +32 -0
  128. package/dist/lib/math.d.ts +11 -0
  129. package/dist/lib/math.js +22 -0
  130. package/dist/lib/nebula-layer.d.ts +13 -0
  131. package/dist/lib/nebula-layer.js +26 -0
  132. package/dist/lib/nebula.d.ts +34 -0
  133. package/dist/lib/nebula.js +254 -0
  134. package/dist/lib/style.d.ts +19 -0
  135. package/dist/lib/style.js +20 -0
  136. package/dist/memoize.d.ts +6 -0
  137. package/dist/memoize.js +40 -0
  138. package/dist/mode-handlers/composite-mode-handler.d.ts +24 -0
  139. package/dist/mode-handlers/composite-mode-handler.js +55 -0
  140. package/dist/mode-handlers/draw-90degree-polygon-handler.d.ts +13 -0
  141. package/dist/mode-handlers/draw-90degree-polygon-handler.js +169 -0
  142. package/dist/mode-handlers/draw-circle-by-bounding-box-handler.d.ts +9 -0
  143. package/dist/mode-handlers/draw-circle-by-bounding-box-handler.js +29 -0
  144. package/dist/mode-handlers/draw-circle-from-center-handler.d.ts +9 -0
  145. package/dist/mode-handlers/draw-circle-from-center-handler.js +27 -0
  146. package/dist/mode-handlers/draw-ellipse-by-bounding-box-handler.d.ts +9 -0
  147. package/dist/mode-handlers/draw-ellipse-by-bounding-box-handler.js +30 -0
  148. package/dist/mode-handlers/draw-ellipse-using-three-points-handler.d.ts +9 -0
  149. package/dist/mode-handlers/draw-ellipse-using-three-points-handler.js +37 -0
  150. package/dist/mode-handlers/draw-line-string-handler.d.ts +9 -0
  151. package/dist/mode-handlers/draw-line-string-handler.js +83 -0
  152. package/dist/mode-handlers/draw-point-handler.d.ts +5 -0
  153. package/dist/mode-handlers/draw-point-handler.js +11 -0
  154. package/dist/mode-handlers/draw-polygon-handler.d.ts +11 -0
  155. package/dist/mode-handlers/draw-polygon-handler.js +92 -0
  156. package/dist/mode-handlers/draw-rectangle-handler.d.ts +9 -0
  157. package/dist/mode-handlers/draw-rectangle-handler.js +18 -0
  158. package/dist/mode-handlers/draw-rectangle-using-three-points-handler.d.ts +9 -0
  159. package/dist/mode-handlers/draw-rectangle-using-three-points-handler.js +49 -0
  160. package/dist/mode-handlers/duplicate-handler.d.ts +9 -0
  161. package/dist/mode-handlers/duplicate-handler.js +19 -0
  162. package/dist/mode-handlers/elevation-handler.d.ts +19 -0
  163. package/dist/mode-handlers/elevation-handler.js +48 -0
  164. package/dist/mode-handlers/extrude-handler.d.ts +18 -0
  165. package/dist/mode-handlers/extrude-handler.js +176 -0
  166. package/dist/mode-handlers/mode-handler.d.ts +61 -0
  167. package/dist/mode-handlers/mode-handler.js +286 -0
  168. package/dist/mode-handlers/modify-handler.d.ts +19 -0
  169. package/dist/mode-handlers/modify-handler.js +193 -0
  170. package/dist/mode-handlers/rotate-handler.d.ts +17 -0
  171. package/dist/mode-handlers/rotate-handler.js +74 -0
  172. package/dist/mode-handlers/scale-handler.d.ts +17 -0
  173. package/dist/mode-handlers/scale-handler.js +76 -0
  174. package/dist/mode-handlers/snappable-handler.d.ts +33 -0
  175. package/dist/mode-handlers/snappable-handler.js +133 -0
  176. package/dist/mode-handlers/split-polygon-handler.d.ts +11 -0
  177. package/dist/mode-handlers/split-polygon-handler.js +154 -0
  178. package/dist/mode-handlers/three-click-polygon-handler.d.ts +5 -0
  179. package/dist/mode-handlers/three-click-polygon-handler.js +18 -0
  180. package/dist/mode-handlers/translate-handler.d.ts +17 -0
  181. package/dist/mode-handlers/translate-handler.js +72 -0
  182. package/dist/mode-handlers/two-click-polygon-handler.d.ts +5 -0
  183. package/dist/mode-handlers/two-click-polygon-handler.js +18 -0
  184. package/dist/mode-handlers/view-handler.d.ts +8 -0
  185. package/dist/mode-handlers/view-handler.js +10 -0
  186. package/dist/shaderlib/color/color.d.ts +8 -0
  187. package/dist/shaderlib/color/color.js +51 -0
  188. package/dist/shaderlib/outline/outline.d.ts +8 -0
  189. package/dist/shaderlib/outline/outline.js +97 -0
  190. package/dist/shaderlib/utils/utils.d.ts +8 -0
  191. package/dist/shaderlib/utils/utils.js +28 -0
  192. package/dist/translateFromCenter.d.ts +4 -0
  193. package/dist/translateFromCenter.js +19 -0
  194. package/dist/types.d.ts +35 -0
  195. package/dist/types.js +1 -0
  196. package/dist/utils.d.ts +20 -0
  197. package/dist/utils.js +144 -0
  198. package/package.json +84 -0
  199. package/src/constants.ts +15 -0
  200. package/src/curve-utils.ts +77 -0
  201. package/src/edit-modes/composite-mode.ts +74 -0
  202. package/src/edit-modes/draw-90degree-polygon-mode.ts +220 -0
  203. package/src/edit-modes/draw-circle-by-diameter-mode.ts +88 -0
  204. package/src/edit-modes/draw-circle-from-center-mode.ts +79 -0
  205. package/src/edit-modes/draw-ellipse-by-bounding-box-mode.ts +25 -0
  206. package/src/edit-modes/draw-ellipse-using-three-points-mode.ts +23 -0
  207. package/src/edit-modes/draw-line-string-mode.ts +200 -0
  208. package/src/edit-modes/draw-point-mode.ts +35 -0
  209. package/src/edit-modes/draw-polygon-by-dragging-mode.ts +106 -0
  210. package/src/edit-modes/draw-polygon-mode.ts +171 -0
  211. package/src/edit-modes/draw-rectangle-from-center-mode.ts +23 -0
  212. package/src/edit-modes/draw-rectangle-mode.ts +14 -0
  213. package/src/edit-modes/draw-rectangle-using-three-points-mode.ts +36 -0
  214. package/src/edit-modes/draw-square-from-center-mode.ts +46 -0
  215. package/src/edit-modes/draw-square-mode.ts +36 -0
  216. package/src/edit-modes/duplicate-mode.ts +21 -0
  217. package/src/edit-modes/edit-mode.ts +30 -0
  218. package/src/edit-modes/elevation-mode.ts +86 -0
  219. package/src/edit-modes/extend-line-string-mode.ts +87 -0
  220. package/src/edit-modes/extrude-mode.ts +254 -0
  221. package/src/edit-modes/geojson-edit-mode.ts +283 -0
  222. package/src/edit-modes/immutable-feature-collection.ts +417 -0
  223. package/src/edit-modes/measure-angle-mode.ts +127 -0
  224. package/src/edit-modes/measure-area-mode.ts +62 -0
  225. package/src/edit-modes/measure-distance-mode.ts +215 -0
  226. package/src/edit-modes/modify-mode.ts +293 -0
  227. package/src/edit-modes/resize-circle-mode.ts +202 -0
  228. package/src/edit-modes/rotate-mode.ts +208 -0
  229. package/src/edit-modes/scale-mode.ts +231 -0
  230. package/src/edit-modes/snappable-mode.ts +174 -0
  231. package/src/edit-modes/split-polygon-mode.ts +201 -0
  232. package/src/edit-modes/three-click-polygon-mode.ts +111 -0
  233. package/src/edit-modes/transform-mode.ts +75 -0
  234. package/src/edit-modes/translate-mode.ts +161 -0
  235. package/src/edit-modes/two-click-polygon-mode.ts +132 -0
  236. package/src/edit-modes/types.ts +135 -0
  237. package/src/edit-modes/utils.ts +513 -0
  238. package/src/edit-modes/view-mode.ts +3 -0
  239. package/src/editable-layers/editable-geojson-layer.ts +603 -0
  240. package/src/editable-layers/editable-h3-cluster-layer.ts +226 -0
  241. package/src/editable-layers/editable-layer.ts +252 -0
  242. package/src/editable-layers/editable-path-layer.ts +51 -0
  243. package/src/editable-layers/elevated-edit-handle-layer.ts +33 -0
  244. package/src/editable-layers/junction-scatterplot-layer.ts +53 -0
  245. package/src/editable-layers/path-marker-layer/arrow-2d-geometry.ts +61 -0
  246. package/src/editable-layers/path-marker-layer/create-path-markers.ts +107 -0
  247. package/src/editable-layers/path-marker-layer/path-marker-layer.ts +179 -0
  248. package/src/editable-layers/path-marker-layer/polyline.ts +40 -0
  249. package/src/editable-layers/path-outline-layer/path-outline-layer.ts +147 -0
  250. package/src/editable-layers/selection-layer.ts +209 -0
  251. package/src/geojson-types.ts +89 -0
  252. package/src/index.ts +125 -0
  253. package/src/lib/constants.ts +6 -0
  254. package/src/lib/deck-renderer/deck-cache.ts +61 -0
  255. package/src/lib/deck-renderer/deck-drawer.ts +263 -0
  256. package/src/lib/feature.ts +27 -0
  257. package/src/lib/layer-mouse-event.ts +32 -0
  258. package/src/lib/layers/junctions-layer.ts +40 -0
  259. package/src/lib/layers/segments-layer.ts +108 -0
  260. package/src/lib/layers/texts-layer.ts +43 -0
  261. package/src/lib/math.ts +26 -0
  262. package/src/lib/nebula-layer.ts +33 -0
  263. package/src/lib/nebula.ts +323 -0
  264. package/src/lib/style.ts +22 -0
  265. package/src/memoize.ts +43 -0
  266. package/src/mode-handlers/composite-mode-handler.ts +89 -0
  267. package/src/mode-handlers/draw-90degree-polygon-handler.ts +201 -0
  268. package/src/mode-handlers/draw-circle-by-bounding-box-handler.ts +39 -0
  269. package/src/mode-handlers/draw-circle-from-center-handler.ts +38 -0
  270. package/src/mode-handlers/draw-ellipse-by-bounding-box-handler.ts +41 -0
  271. package/src/mode-handlers/draw-ellipse-using-three-points-handler.ts +46 -0
  272. package/src/mode-handlers/draw-line-string-handler.ts +108 -0
  273. package/src/mode-handlers/draw-point-handler.ts +15 -0
  274. package/src/mode-handlers/draw-polygon-handler.ts +121 -0
  275. package/src/mode-handlers/draw-rectangle-handler.ts +28 -0
  276. package/src/mode-handlers/draw-rectangle-using-three-points-handler.ts +60 -0
  277. package/src/mode-handlers/duplicate-handler.ts +25 -0
  278. package/src/mode-handlers/elevation-handler.ts +88 -0
  279. package/src/mode-handlers/extrude-handler.ts +245 -0
  280. package/src/mode-handlers/mode-handler.ts +394 -0
  281. package/src/mode-handlers/modify-handler.ts +263 -0
  282. package/src/mode-handlers/rotate-handler.ts +107 -0
  283. package/src/mode-handlers/scale-handler.ts +105 -0
  284. package/src/mode-handlers/snappable-handler.ts +184 -0
  285. package/src/mode-handlers/split-polygon-handler.ts +177 -0
  286. package/src/mode-handlers/three-click-polygon-handler.ts +25 -0
  287. package/src/mode-handlers/translate-handler.ts +110 -0
  288. package/src/mode-handlers/two-click-polygon-handler.ts +25 -0
  289. package/src/mode-handlers/view-handler.ts +13 -0
  290. package/src/shaderlib/color/color.ts +56 -0
  291. package/src/shaderlib/outline/outline.ts +101 -0
  292. package/src/shaderlib/utils/utils.ts +33 -0
  293. package/src/translateFromCenter.ts +48 -0
  294. package/src/types.ts +39 -0
  295. package/src/utils.ts +185 -0
@@ -0,0 +1,135 @@
1
+ import { Position, Point, Geometry, FeatureWithProps } from '../geojson-types';
2
+
3
+ export type ScreenCoordinates = [number, number];
4
+
5
+ // Represents an edit action, i.e. a suggestion to update the data based on user interaction events
6
+ export type EditAction<TData> = {
7
+ updatedData: TData;
8
+ editType: string;
9
+ editContext: any;
10
+ };
11
+
12
+ // Represents an object "picked" from the screen. This usually reflects an object under the cursor
13
+ export type Pick = {
14
+ index: number;
15
+ object?: any;
16
+ isGuide?: boolean;
17
+ featureIndex?: number;
18
+ type?: string;
19
+ isEditingHandle?: boolean | null;
20
+ };
21
+
22
+ export type Viewport = {
23
+ width: number;
24
+ height: number;
25
+ longitude: number;
26
+ latitude: number;
27
+ zoom: number;
28
+ bearing?: number;
29
+ pitch?: number;
30
+ };
31
+
32
+ export type BasePointerEvent = {
33
+ picks: Pick[];
34
+ screenCoords: ScreenCoordinates;
35
+ mapCoords: Position;
36
+ sourceEvent: any;
37
+ };
38
+
39
+ // Represents a click event
40
+ export type ClickEvent = BasePointerEvent;
41
+
42
+ // Represents an event that occurs when the pointer goes down and the cursor starts moving
43
+ export type StartDraggingEvent = BasePointerEvent & {
44
+ pointerDownPicks?: Pick[] | null;
45
+ pointerDownScreenCoords: ScreenCoordinates;
46
+ pointerDownMapCoords: Position;
47
+ cancelPan: () => void;
48
+ };
49
+
50
+ // Represents an event that occurs after the pointer goes down, moves some, then the pointer goes back up
51
+ export type StopDraggingEvent = BasePointerEvent & {
52
+ pointerDownPicks?: Pick[] | null;
53
+ pointerDownScreenCoords: ScreenCoordinates;
54
+ pointerDownMapCoords: Position;
55
+ };
56
+
57
+ // Represents an event that occurs after the pointer goes down and is moving
58
+ export type DraggingEvent = BasePointerEvent & {
59
+ pointerDownPicks?: Pick[] | null;
60
+ pointerDownScreenCoords: ScreenCoordinates;
61
+ pointerDownMapCoords: Position;
62
+ cancelPan: () => void;
63
+ };
64
+
65
+ // Represents an event that occurs every time the pointer moves
66
+ export type PointerMoveEvent = BasePointerEvent & {
67
+ pointerDownPicks?: Pick[] | null;
68
+ pointerDownScreenCoords?: ScreenCoordinates | null;
69
+ pointerDownMapCoords?: Position | null;
70
+ cancelPan: () => void;
71
+ isDragging?: boolean;
72
+ };
73
+
74
+ export type Tooltip = {
75
+ position: Position;
76
+ text: string;
77
+ };
78
+
79
+ export type EditHandleType =
80
+ | 'existing'
81
+ | 'intermediate'
82
+ | 'snap-source'
83
+ | 'snap-target'
84
+ | 'scale'
85
+ | 'rotate';
86
+
87
+ export type EditHandleFeature = FeatureWithProps<
88
+ Point,
89
+ {
90
+ guideType: 'editHandle';
91
+ editHandleType: EditHandleType;
92
+ featureIndex: number;
93
+ positionIndexes?: number[];
94
+ shape?: string;
95
+ }
96
+ >;
97
+
98
+ export type TentativeFeature = FeatureWithProps<
99
+ Geometry,
100
+ {
101
+ guideType: 'tentative';
102
+ shape?: string;
103
+ }
104
+ >;
105
+
106
+ export type GuideFeature = EditHandleFeature | TentativeFeature;
107
+
108
+ export type GuideFeatureCollection = {
109
+ type: 'FeatureCollection';
110
+ features: Readonly<GuideFeature>[];
111
+ properties?: {};
112
+ };
113
+
114
+ export type ModeProps<TData> = {
115
+ // The data being edited, this can be an array or an object
116
+ data: TData;
117
+
118
+ // Additional configuration for this mode
119
+ modeConfig: any;
120
+
121
+ // The indexes of the selected features
122
+ selectedIndexes: number[];
123
+
124
+ // The cursor type, as a [CSS Cursor](https://developer.mozilla.org/en-US/docs/Web/CSS/cursor)
125
+ cursor: string | null | undefined;
126
+
127
+ // The last pointer move event that occurred
128
+ lastPointerMoveEvent: PointerMoveEvent;
129
+
130
+ // Callback used to notify applications of an edit action
131
+ onEdit: (editAction: EditAction<TData>) => void;
132
+
133
+ // Callback used to update cursor
134
+ onUpdateCursor: (cursor: string | null | undefined) => void;
135
+ };
@@ -0,0 +1,513 @@
1
+ import destination from '@turf/destination';
2
+ import bearing from '@turf/bearing';
3
+ import pointToLineDistance from '@turf/point-to-line-distance';
4
+ import { flattenEach } from '@turf/meta';
5
+ import { point, MultiLineString } from '@turf/helpers';
6
+ import { getCoords } from '@turf/invariant';
7
+ import WebMercatorViewport from 'viewport-mercator-project';
8
+ import { Viewport, Pick, EditHandleFeature, EditHandleType } from './types';
9
+ import {
10
+ Geometry,
11
+ Position,
12
+ Point,
13
+ LineString,
14
+ Polygon,
15
+ FeatureOf,
16
+ FeatureWithProps,
17
+ AnyCoordinates,
18
+ } from '../geojson-types';
19
+
20
+ export type NearestPointType = FeatureWithProps<Point, { dist: number; index: number }>;
21
+
22
+ export function toDeckColor(
23
+ color?: [number, number, number, number] | number,
24
+ defaultColor: [number, number, number, number] = [255, 0, 0, 255]
25
+ ): [number, number, number, number] {
26
+ if (!Array.isArray(color)) {
27
+ return defaultColor;
28
+ }
29
+ return [color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255];
30
+ }
31
+
32
+ //
33
+ // a GeoJSON helper function that calls the provided function with
34
+ // an argument that is the most deeply-nested array having elements
35
+ // that are arrays of primitives as an argument, e.g.
36
+ //
37
+ // {
38
+ // "type": "MultiPolygon",
39
+ // "coordinates": [
40
+ // [
41
+ // [[30, 20], [45, 40], [10, 40], [30, 20]]
42
+ // ],
43
+ // [
44
+ // [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]
45
+ // ]
46
+ // ]
47
+ // }
48
+ //
49
+ // the function would be called on:
50
+ //
51
+ // [[30, 20], [45, 40], [10, 40], [30, 20]]
52
+ //
53
+ // and
54
+ //
55
+ // [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]
56
+ //
57
+ export function recursivelyTraverseNestedArrays(
58
+ array: Array<any>,
59
+ prefix: Array<number>,
60
+ fn: (array: Array<any>, prefix: number[]) => void
61
+ ) {
62
+ if (!Array.isArray(array[0])) {
63
+ return true;
64
+ }
65
+ for (let i = 0; i < array.length; i++) {
66
+ if (recursivelyTraverseNestedArrays(array[i], [...prefix, i], fn)) {
67
+ fn(array, prefix);
68
+ break;
69
+ }
70
+ }
71
+ return false;
72
+ }
73
+
74
+ export function generatePointsParallelToLinePoints(
75
+ p1: Position,
76
+ p2: Position,
77
+ mapCoords: Position
78
+ ): Position[] {
79
+ const lineString: LineString = {
80
+ type: 'LineString',
81
+ coordinates: [p1, p2],
82
+ };
83
+ const pt = point(mapCoords);
84
+ const ddistance = pointToLineDistance(pt, lineString);
85
+ const lineBearing = bearing(p1, p2);
86
+
87
+ // Check if current point is to the left or right of line
88
+ // Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
89
+ // then (x−x1)(y2−y1)−(y−y1)(x2−x1)
90
+ const isPointToLeftOfLine =
91
+ (mapCoords[0] - p1[0]) * (p2[1] - p1[1]) - (mapCoords[1] - p1[1]) * (p2[0] - p1[0]);
92
+
93
+ // Bearing to draw perpendicular to the line string
94
+ const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;
95
+
96
+ // Get coordinates for the point p3 and p4 which are perpendicular to the lineString
97
+ // Add the distance as the current position moves away from the lineString
98
+ const p3 = destination(p2, ddistance, orthogonalBearing);
99
+ const p4 = destination(p1, ddistance, orthogonalBearing);
100
+
101
+ return [p3.geometry.coordinates, p4.geometry.coordinates] as Position[];
102
+ }
103
+
104
+ export function distance2d(x1: number, y1: number, x2: number, y2: number): number {
105
+ const dx = x1 - x2;
106
+ const dy = y1 - y2;
107
+ return Math.sqrt(dx * dx + dy * dy);
108
+ }
109
+
110
+ export function mix(a: number, b: number, ratio: number): number {
111
+ return b * ratio + a * (1 - ratio);
112
+ }
113
+
114
+ export function nearestPointOnProjectedLine(
115
+ line: FeatureOf<LineString>,
116
+ inPoint: FeatureOf<Point>,
117
+ viewport: Viewport
118
+ ): NearestPointType {
119
+ const wmViewport = new WebMercatorViewport(viewport);
120
+ // Project the line to viewport, then find the nearest point
121
+ const coordinates: Array<Array<number>> = line.geometry.coordinates as any;
122
+ const projectedCoords = coordinates.map(([x, y, z = 0]) => wmViewport.project([x, y, z]));
123
+ const [x, y] = wmViewport.project(inPoint.geometry.coordinates);
124
+ // console.log('projectedCoords', JSON.stringify(projectedCoords));
125
+
126
+ let minDistance = Infinity;
127
+ let minPointInfo = {};
128
+
129
+ projectedCoords.forEach(([x2, y2], index) => {
130
+ if (index === 0) {
131
+ return;
132
+ }
133
+
134
+ const [x1, y1] = projectedCoords[index - 1];
135
+
136
+ // line from projectedCoords[index - 1] to projectedCoords[index]
137
+ // convert to Ax + By + C = 0
138
+ const A = y1 - y2;
139
+ const B = x2 - x1;
140
+ const C = x1 * y2 - x2 * y1;
141
+
142
+ // https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
143
+ const div = A * A + B * B;
144
+ const distance = Math.abs(A * x + B * y + C) / Math.sqrt(div);
145
+
146
+ // TODO: Check if inside bounds
147
+
148
+ if (distance < minDistance) {
149
+ minDistance = distance;
150
+ minPointInfo = {
151
+ index,
152
+ x0: (B * (B * x - A * y) - A * C) / div,
153
+ y0: (A * (-B * x + A * y) - B * C) / div,
154
+ };
155
+ }
156
+ });
157
+ // @ts-ignore
158
+ const { index, x0, y0 } = minPointInfo;
159
+ const [x1, y1, z1 = 0] = projectedCoords[index - 1];
160
+ const [x2, y2, z2 = 0] = projectedCoords[index];
161
+
162
+ // calculate what ratio of the line we are on to find the proper z
163
+ const lineLength = distance2d(x1, y1, x2, y2);
164
+ const startToPointLength = distance2d(x1, y1, x0, y0);
165
+ const ratio = startToPointLength / lineLength;
166
+ const z0 = mix(z1, z2, ratio);
167
+
168
+ return {
169
+ type: 'Feature',
170
+ geometry: {
171
+ type: 'Point',
172
+ // @ts-expect-error
173
+ coordinates: wmViewport.unproject([x0, y0, z0]),
174
+ },
175
+ properties: {
176
+ // TODO: calculate the distance in proper units
177
+ dist: minDistance,
178
+ index: index - 1,
179
+ },
180
+ };
181
+ }
182
+
183
+ export function nearestPointOnLine<G extends LineString | MultiLineString>(
184
+ lines: FeatureOf<LineString>,
185
+ inPoint: FeatureOf<Point>,
186
+ viewport?: Viewport
187
+ ): NearestPointType {
188
+ let mercator;
189
+
190
+ if (viewport) {
191
+ mercator = new WebMercatorViewport(viewport);
192
+ }
193
+ let closestPoint: any = point([Infinity, Infinity], {
194
+ dist: Infinity,
195
+ });
196
+
197
+ if (!lines.geometry?.coordinates.length || lines.geometry?.coordinates.length < 2) {
198
+ return closestPoint;
199
+ }
200
+
201
+ // @ts-ignore
202
+ // eslint-disable-next-line max-statements, complexity
203
+ flattenEach(lines, (line: any) => {
204
+ const coords: any = getCoords(line);
205
+ // @ts-ignore
206
+ const pointCoords: any = getCoords(inPoint);
207
+
208
+ let minDist;
209
+ let to;
210
+ let from;
211
+ let x;
212
+ let y;
213
+ let segmentIdx;
214
+ let dist;
215
+
216
+ if (coords.length > 1 && pointCoords.length) {
217
+ let lineCoordinates;
218
+ let pointCoordinate;
219
+
220
+ // If viewport is given, then translate these coordinates to pixels to increase precision
221
+ if (mercator) {
222
+ lineCoordinates = coords.map((lineCoordinate) => mercator.project(lineCoordinate));
223
+ pointCoordinate = mercator.project(pointCoords);
224
+ } else {
225
+ lineCoordinates = coords;
226
+ pointCoordinate = pointCoords;
227
+ }
228
+
229
+ for (let n = 1; n < lineCoordinates.length; n++) {
230
+ if (lineCoordinates[n][0] !== lineCoordinates[n - 1][0]) {
231
+ const slope =
232
+ (lineCoordinates[n][1] - lineCoordinates[n - 1][1]) /
233
+ (lineCoordinates[n][0] - lineCoordinates[n - 1][0]);
234
+ const inverseSlope = lineCoordinates[n][1] - slope * lineCoordinates[n][0];
235
+
236
+ dist =
237
+ Math.abs(slope * pointCoordinate[0] + inverseSlope - pointCoordinate[1]) /
238
+ Math.sqrt(slope * slope + 1);
239
+ } else dist = Math.abs(pointCoordinate[0] - lineCoordinates[n][0]);
240
+
241
+ // length^2 of line segment
242
+ const rl2 =
243
+ Math.pow(lineCoordinates[n][1] - lineCoordinates[n - 1][1], 2) +
244
+ Math.pow(lineCoordinates[n][0] - lineCoordinates[n - 1][0], 2);
245
+
246
+ // distance^2 of pt to end line segment
247
+ const ln2 =
248
+ Math.pow(lineCoordinates[n][1] - pointCoordinate[1], 2) +
249
+ Math.pow(lineCoordinates[n][0] - pointCoordinate[0], 2);
250
+
251
+ // distance^2 of pt to begin line segment
252
+ const lnm12 =
253
+ Math.pow(lineCoordinates[n - 1][1] - pointCoordinate[1], 2) +
254
+ Math.pow(lineCoordinates[n - 1][0] - pointCoordinate[0], 2);
255
+
256
+ // minimum distance^2 of pt to infinite line
257
+ const dist2 = Math.pow(dist, 2);
258
+
259
+ // calculated length^2 of line segment
260
+ const calcrl2 = ln2 - dist2 + lnm12 - dist2;
261
+
262
+ // redefine minimum distance to line segment (not infinite line) if necessary
263
+ if (calcrl2 > rl2) {
264
+ dist = Math.sqrt(Math.min(ln2, lnm12));
265
+ }
266
+
267
+ if (minDist === null || minDist === undefined || minDist > dist) {
268
+ // eslint-disable-next-line max-depth
269
+ if (calcrl2 > rl2) {
270
+ // eslint-disable-next-line max-depth
271
+ if (lnm12 < ln2) {
272
+ to = 0; // nearer to previous point
273
+ from = 1;
274
+ } else {
275
+ from = 0; // nearer to current point
276
+ to = 1;
277
+ }
278
+ } else {
279
+ // perpendicular from point intersects line segment
280
+ to = Math.sqrt(lnm12 - dist2) / Math.sqrt(rl2);
281
+ from = Math.sqrt(ln2 - dist2) / Math.sqrt(rl2);
282
+ }
283
+ minDist = dist;
284
+ segmentIdx = n;
285
+ }
286
+ }
287
+
288
+ const dx = lineCoordinates[segmentIdx - 1][0] - lineCoordinates[segmentIdx][0];
289
+ const dy = lineCoordinates[segmentIdx - 1][1] - lineCoordinates[segmentIdx][1];
290
+
291
+ x = lineCoordinates[segmentIdx - 1][0] - dx * to;
292
+ y = lineCoordinates[segmentIdx - 1][1] - dy * to;
293
+ }
294
+
295
+ // index needs to be -1 because we have to account for the shift from initial backscan
296
+ let snapPoint = { x, y, idx: segmentIdx - 1, to, from };
297
+
298
+ if (mercator) {
299
+ const pixelToLatLong = mercator.unproject([snapPoint.x, snapPoint.y]);
300
+ snapPoint = {
301
+ x: pixelToLatLong[0],
302
+ y: pixelToLatLong[1],
303
+ idx: segmentIdx - 1,
304
+ to,
305
+ from,
306
+ };
307
+ }
308
+
309
+ closestPoint = point([snapPoint.x, snapPoint.y], {
310
+ dist: Math.abs(snapPoint.from - snapPoint.to),
311
+ index: snapPoint.idx,
312
+ });
313
+ });
314
+
315
+ return closestPoint;
316
+ }
317
+
318
+ export function getPickedEditHandle(
319
+ picks: Pick[] | null | undefined
320
+ ): EditHandleFeature | null | undefined {
321
+ const handles = getPickedEditHandles(picks);
322
+ return handles.length ? handles[0] : null;
323
+ }
324
+
325
+ export function getPickedSnapSourceEditHandle(
326
+ picks: Pick[] | null | undefined
327
+ ): EditHandleFeature | null | undefined {
328
+ const handles = getPickedEditHandles(picks);
329
+ return handles.find((handle) => handle.properties.editHandleType === 'snap-source');
330
+ }
331
+
332
+ export function getNonGuidePicks(picks: Pick[]): Pick[] {
333
+ return picks && picks.filter((pick) => !pick.isGuide);
334
+ }
335
+
336
+ export function getPickedExistingEditHandle(
337
+ picks: Pick[] | null | undefined
338
+ ): EditHandleFeature | null | undefined {
339
+ const handles = getPickedEditHandles(picks);
340
+ return handles.find(
341
+ ({ properties }) => properties.featureIndex >= 0 && properties.editHandleType === 'existing'
342
+ );
343
+ }
344
+
345
+ export function getPickedIntermediateEditHandle(
346
+ picks: Pick[] | null | undefined
347
+ ): EditHandleFeature | null | undefined {
348
+ const handles = getPickedEditHandles(picks);
349
+ return handles.find(
350
+ ({ properties }) => properties.featureIndex >= 0 && properties.editHandleType === 'intermediate'
351
+ );
352
+ }
353
+
354
+ export function getPickedEditHandles(picks: Pick[] | null | undefined): EditHandleFeature[] {
355
+ const handles =
356
+ (picks &&
357
+ picks
358
+ .filter((pick) => pick.isGuide && pick.object.properties.guideType === 'editHandle')
359
+ .map((pick) => pick.object)) ||
360
+ [];
361
+
362
+ return handles;
363
+ }
364
+
365
+ export function getEditHandlesForGeometry(
366
+ geometry: Geometry,
367
+ featureIndex: number,
368
+ editHandleType: EditHandleType = 'existing'
369
+ ): EditHandleFeature[] {
370
+ let handles: EditHandleFeature[] = [];
371
+
372
+ switch (geometry.type) {
373
+ case 'Point':
374
+ // positions are not nested
375
+ handles = [
376
+ {
377
+ type: 'Feature',
378
+ properties: {
379
+ guideType: 'editHandle',
380
+ editHandleType,
381
+ positionIndexes: [],
382
+ featureIndex,
383
+ },
384
+ geometry: {
385
+ type: 'Point',
386
+ coordinates: geometry.coordinates,
387
+ },
388
+ },
389
+ ];
390
+ break;
391
+ case 'MultiPoint':
392
+ case 'LineString':
393
+ // positions are nested 1 level
394
+ handles = handles.concat(
395
+ getEditHandlesForCoordinates(geometry.coordinates, [], featureIndex, editHandleType)
396
+ );
397
+ break;
398
+ case 'Polygon':
399
+ case 'MultiLineString':
400
+ // positions are nested 2 levels
401
+ for (let a = 0; a < geometry.coordinates.length; a++) {
402
+ handles = handles.concat(
403
+ getEditHandlesForCoordinates(geometry.coordinates[a], [a], featureIndex, editHandleType)
404
+ );
405
+ if (geometry.type === 'Polygon') {
406
+ // Don't repeat the first/last handle for Polygons
407
+ handles = handles.slice(0, -1);
408
+ }
409
+ }
410
+
411
+ break;
412
+ case 'MultiPolygon':
413
+ // positions are nested 3 levels
414
+ for (let a = 0; a < geometry.coordinates.length; a++) {
415
+ for (let b = 0; b < geometry.coordinates[a].length; b++) {
416
+ handles = handles.concat(
417
+ getEditHandlesForCoordinates(
418
+ geometry.coordinates[a][b],
419
+ [a, b],
420
+ featureIndex,
421
+ editHandleType
422
+ )
423
+ );
424
+ // Don't repeat the first/last handle for Polygons
425
+ handles = handles.slice(0, -1);
426
+ }
427
+ }
428
+
429
+ break;
430
+ default:
431
+ throw Error(`Unhandled geometry type: ${(geometry as {type: string}).type}`);
432
+ }
433
+
434
+ return handles;
435
+ }
436
+
437
+ function getEditHandlesForCoordinates(
438
+ coordinates: any[],
439
+ positionIndexPrefix: number[],
440
+ featureIndex: number,
441
+ editHandleType: EditHandleType = 'existing'
442
+ ): EditHandleFeature[] {
443
+ const editHandles: EditHandleFeature[] = [];
444
+ for (let i = 0; i < coordinates.length; i++) {
445
+ const position = coordinates[i] as Position;
446
+ editHandles.push({
447
+ type: 'Feature',
448
+ properties: {
449
+ guideType: 'editHandle',
450
+ positionIndexes: [...positionIndexPrefix, i],
451
+ featureIndex,
452
+ editHandleType,
453
+ },
454
+ geometry: {
455
+ type: 'Point',
456
+ coordinates: position,
457
+ },
458
+ });
459
+ }
460
+ return editHandles;
461
+ }
462
+
463
+ /**
464
+ * Calculates coordinates for a feature preserving rectangular shape.
465
+ * @param feature Feature before modification.
466
+ * @param editHandleIndex Index of the point to modify.
467
+ * @param mapCoords New position for the point.
468
+ * @returns Updated coordinates.
469
+ */
470
+ export function updateRectanglePosition(
471
+ feature: FeatureOf<Polygon>,
472
+ editHandleIndex: number,
473
+ mapCoords: Position
474
+ ): Position[][] | null {
475
+ const coordinates = feature.geometry.coordinates;
476
+ if (!coordinates) {
477
+ return null;
478
+ }
479
+
480
+ const points = coordinates[0].slice(0, 4);
481
+ points[editHandleIndex % 4] = mapCoords;
482
+
483
+ const p0 = points[(editHandleIndex + 2) % 4];
484
+ const p2 = points[editHandleIndex % 4];
485
+ points[(editHandleIndex + 1) % 4] = [p2[0], p0[1]];
486
+ points[(editHandleIndex + 3) % 4] = [p0[0], p2[1]];
487
+
488
+ return [[...points, points[0]]];
489
+ }
490
+
491
+ /** Creates a copy of feature's coordinates.
492
+ * Each position in coordinates is transformed by calling the provided function.
493
+ * @param coords Coordinates of a feature.
494
+ * @param callback A function to transform each coordinate.
495
+ * @retuns Transformed coordinates.
496
+ */
497
+ export function mapCoords(
498
+ coords: AnyCoordinates,
499
+ callback: (coords: Position) => Position
500
+ ): AnyCoordinates {
501
+ if (typeof coords[0] === 'number') {
502
+ if (!isNaN(coords[0]) && isFinite(coords[0])) {
503
+ return callback(coords as Position);
504
+ }
505
+ return coords;
506
+ }
507
+
508
+ return (coords as Position[])
509
+ .map((coord) => {
510
+ return mapCoords(coord, callback) as Position;
511
+ })
512
+ .filter(Boolean);
513
+ }
@@ -0,0 +1,3 @@
1
+ import { GeoJsonEditMode } from './geojson-edit-mode';
2
+
3
+ export class ViewMode extends GeoJsonEditMode {}