@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,43 @@
1
+ import { Feature, FeatureCollection, Geometry, Position } from '../geojson-types';
2
+ export declare class ImmutableFeatureCollection {
3
+ featureCollection: FeatureCollection;
4
+ constructor(featureCollection: FeatureCollection);
5
+ getObject(): FeatureCollection;
6
+ /**
7
+ * Replaces the position deeply nested withing the given feature's geometry.
8
+ * Works with Point, MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon.
9
+ *
10
+ * @param featureIndex The index of the feature to update
11
+ * @param positionIndexes An array containing the indexes of the position to replace
12
+ * @param updatedPosition The updated position to place in the result (i.e. [lng, lat])
13
+ *
14
+ * @returns A new `ImmutableFeatureCollection` with the given position replaced. Does not modify this `ImmutableFeatureCollection`.
15
+ */
16
+ replacePosition(featureIndex: number, positionIndexes: number[] | null | undefined, updatedPosition: Position): ImmutableFeatureCollection;
17
+ /**
18
+ * Removes a position deeply nested in a GeoJSON geometry coordinates array.
19
+ * Works with MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon.
20
+ *
21
+ * @param featureIndex The index of the feature to update
22
+ * @param positionIndexes An array containing the indexes of the postion to remove
23
+ *
24
+ * @returns A new `ImmutableFeatureCollection` with the given coordinate removed. Does not modify this `ImmutableFeatureCollection`.
25
+ */
26
+ removePosition(featureIndex: number, positionIndexes: number[] | null | undefined): ImmutableFeatureCollection;
27
+ /**
28
+ * Adds a position deeply nested in a GeoJSON geometry coordinates array.
29
+ * Works with MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon.
30
+ *
31
+ * @param featureIndex The index of the feature to update
32
+ * @param positionIndexes An array containing the indexes of the position that will proceed the new position
33
+ * @param positionToAdd The new position to place in the result (i.e. [lng, lat])
34
+ *
35
+ * @returns A new `ImmutableFeatureCollection` with the given coordinate removed. Does not modify this `ImmutableFeatureCollection`.
36
+ */
37
+ addPosition(featureIndex: number, positionIndexes: number[] | null | undefined, positionToAdd: Position): ImmutableFeatureCollection;
38
+ replaceGeometry(featureIndex: number, geometry: Geometry): ImmutableFeatureCollection;
39
+ addFeature(feature: Feature): ImmutableFeatureCollection;
40
+ addFeatures(features: Feature[]): ImmutableFeatureCollection;
41
+ deleteFeature(featureIndex: number): ImmutableFeatureCollection;
42
+ deleteFeatures(featureIndexes: number[]): ImmutableFeatureCollection;
43
+ }
@@ -0,0 +1,300 @@
1
+ export class ImmutableFeatureCollection {
2
+ featureCollection;
3
+ constructor(featureCollection) {
4
+ this.featureCollection = featureCollection;
5
+ }
6
+ getObject() {
7
+ return this.featureCollection;
8
+ }
9
+ /**
10
+ * Replaces the position deeply nested withing the given feature's geometry.
11
+ * Works with Point, MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon.
12
+ *
13
+ * @param featureIndex The index of the feature to update
14
+ * @param positionIndexes An array containing the indexes of the position to replace
15
+ * @param updatedPosition The updated position to place in the result (i.e. [lng, lat])
16
+ *
17
+ * @returns A new `ImmutableFeatureCollection` with the given position replaced. Does not modify this `ImmutableFeatureCollection`.
18
+ */
19
+ replacePosition(featureIndex, positionIndexes, updatedPosition) {
20
+ const geometry = this.featureCollection.features[featureIndex].geometry;
21
+ const isPolygonal = geometry.type === 'Polygon' || geometry.type === 'MultiPolygon';
22
+ const updatedGeometry = {
23
+ ...geometry,
24
+ coordinates: immutablyReplacePosition(geometry.coordinates, positionIndexes, updatedPosition, isPolygonal),
25
+ };
26
+ return this.replaceGeometry(featureIndex, updatedGeometry);
27
+ }
28
+ /**
29
+ * Removes a position deeply nested in a GeoJSON geometry coordinates array.
30
+ * Works with MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon.
31
+ *
32
+ * @param featureIndex The index of the feature to update
33
+ * @param positionIndexes An array containing the indexes of the postion to remove
34
+ *
35
+ * @returns A new `ImmutableFeatureCollection` with the given coordinate removed. Does not modify this `ImmutableFeatureCollection`.
36
+ */
37
+ removePosition(featureIndex, positionIndexes) {
38
+ const geometry = this.featureCollection.features[featureIndex].geometry;
39
+ if (geometry.type === 'Point') {
40
+ throw Error('Can\'t remove a position from a Point or there\'d be nothing left');
41
+ }
42
+ if (geometry.type === 'MultiPoint' && // only 1 point left
43
+ geometry.coordinates.length < 2) {
44
+ throw Error('Can\'t remove the last point of a MultiPoint or there\'d be nothing left');
45
+ }
46
+ if (geometry.type === 'LineString' && // only 2 positions
47
+ geometry.coordinates.length < 3) {
48
+ throw Error('Can\'t remove position. LineString must have at least two positions');
49
+ }
50
+ if (geometry.type === 'Polygon' && // outer ring is a triangle
51
+ geometry.coordinates[0].length < 5 &&
52
+ Array.isArray(positionIndexes) && // trying to remove from outer ring
53
+ positionIndexes[0] === 0) {
54
+ throw Error('Can\'t remove position. Polygon\'s outer ring must have at least four positions');
55
+ }
56
+ if (geometry.type === 'MultiLineString' && // only 1 LineString left
57
+ geometry.coordinates.length === 1 && // only 2 positions
58
+ geometry.coordinates[0].length < 3) {
59
+ throw Error('Can\'t remove position. MultiLineString must have at least two positions');
60
+ }
61
+ if (geometry.type === 'MultiPolygon' && // only 1 polygon left
62
+ geometry.coordinates.length === 1 && // outer ring is a triangle
63
+ geometry.coordinates[0][0].length < 5 &&
64
+ Array.isArray(positionIndexes) && // trying to remove from first polygon
65
+ positionIndexes[0] === 0 && // trying to remove from outer ring
66
+ positionIndexes[1] === 0) {
67
+ throw Error('Can\'t remove position. MultiPolygon\'s outer ring must have at least four positions');
68
+ }
69
+ const isPolygonal = geometry.type === 'Polygon' || geometry.type === 'MultiPolygon';
70
+ const updatedGeometry = {
71
+ ...geometry,
72
+ coordinates: immutablyRemovePosition(geometry.coordinates, positionIndexes, isPolygonal),
73
+ };
74
+ // Handle cases where incomplete geometries need pruned (e.g. holes that were triangles)
75
+ pruneGeometryIfNecessary(updatedGeometry);
76
+ return this.replaceGeometry(featureIndex, updatedGeometry);
77
+ }
78
+ /**
79
+ * Adds a position deeply nested in a GeoJSON geometry coordinates array.
80
+ * Works with MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon.
81
+ *
82
+ * @param featureIndex The index of the feature to update
83
+ * @param positionIndexes An array containing the indexes of the position that will proceed the new position
84
+ * @param positionToAdd The new position to place in the result (i.e. [lng, lat])
85
+ *
86
+ * @returns A new `ImmutableFeatureCollection` with the given coordinate removed. Does not modify this `ImmutableFeatureCollection`.
87
+ */
88
+ addPosition(featureIndex, positionIndexes, positionToAdd) {
89
+ const geometry = this.featureCollection.features[featureIndex].geometry;
90
+ if (geometry.type === 'Point') {
91
+ throw new Error('Unable to add a position to a Point feature');
92
+ }
93
+ const isPolygonal = geometry.type === 'Polygon' || geometry.type === 'MultiPolygon';
94
+ const updatedGeometry = {
95
+ ...geometry,
96
+ coordinates: immutablyAddPosition(geometry.coordinates, positionIndexes, positionToAdd, isPolygonal),
97
+ };
98
+ return this.replaceGeometry(featureIndex, updatedGeometry);
99
+ }
100
+ replaceGeometry(featureIndex, geometry) {
101
+ const updatedFeature = {
102
+ ...this.featureCollection.features[featureIndex],
103
+ geometry,
104
+ };
105
+ const updatedFeatureCollection = {
106
+ ...this.featureCollection,
107
+ features: [
108
+ ...this.featureCollection.features.slice(0, featureIndex),
109
+ updatedFeature,
110
+ ...this.featureCollection.features.slice(featureIndex + 1),
111
+ ],
112
+ };
113
+ return new ImmutableFeatureCollection(updatedFeatureCollection);
114
+ }
115
+ addFeature(feature) {
116
+ return this.addFeatures([feature]);
117
+ }
118
+ addFeatures(features) {
119
+ const updatedFeatureCollection = {
120
+ ...this.featureCollection,
121
+ features: [...this.featureCollection.features, ...features],
122
+ };
123
+ return new ImmutableFeatureCollection(updatedFeatureCollection);
124
+ }
125
+ deleteFeature(featureIndex) {
126
+ return this.deleteFeatures([featureIndex]);
127
+ }
128
+ deleteFeatures(featureIndexes) {
129
+ const features = [...this.featureCollection.features];
130
+ featureIndexes.sort();
131
+ for (let i = featureIndexes.length - 1; i >= 0; i--) {
132
+ const featureIndex = featureIndexes[i];
133
+ if (featureIndex >= 0 && featureIndex < features.length) {
134
+ features.splice(featureIndex, 1);
135
+ }
136
+ }
137
+ const updatedFeatureCollection = {
138
+ ...this.featureCollection,
139
+ features,
140
+ };
141
+ return new ImmutableFeatureCollection(updatedFeatureCollection);
142
+ }
143
+ }
144
+ function getUpdatedPosition(updatedPosition, previousPosition) {
145
+ // This function checks if the updatedPosition is missing elevation
146
+ // and copies it from previousPosition
147
+ if (updatedPosition.length === 2 && previousPosition.length === 3) {
148
+ const elevation = previousPosition[2];
149
+ return [updatedPosition[0], updatedPosition[1], elevation];
150
+ }
151
+ return updatedPosition;
152
+ }
153
+ function immutablyReplacePosition(coordinates, positionIndexes, updatedPosition, isPolygonal) {
154
+ if (!positionIndexes) {
155
+ return coordinates;
156
+ }
157
+ if (positionIndexes.length === 0) {
158
+ return getUpdatedPosition(updatedPosition, coordinates);
159
+ }
160
+ if (positionIndexes.length === 1) {
161
+ const updated = [
162
+ ...coordinates.slice(0, positionIndexes[0]),
163
+ getUpdatedPosition(updatedPosition, coordinates[positionIndexes[0]]),
164
+ ...coordinates.slice(positionIndexes[0] + 1),
165
+ ];
166
+ if (isPolygonal &&
167
+ (positionIndexes[0] === 0 || positionIndexes[0] === coordinates.length - 1)) {
168
+ // for polygons, the first point is repeated at the end of the array
169
+ // so, update it on both ends of the array
170
+ updated[0] = getUpdatedPosition(updatedPosition, coordinates[0]);
171
+ updated[coordinates.length - 1] = getUpdatedPosition(updatedPosition, coordinates[0]);
172
+ }
173
+ return updated;
174
+ }
175
+ // recursively update inner array
176
+ return [
177
+ ...coordinates.slice(0, positionIndexes[0]),
178
+ immutablyReplacePosition(coordinates[positionIndexes[0]], positionIndexes.slice(1, positionIndexes.length), updatedPosition, isPolygonal),
179
+ ...coordinates.slice(positionIndexes[0] + 1),
180
+ ];
181
+ }
182
+ function immutablyRemovePosition(coordinates, positionIndexes, isPolygonal) {
183
+ if (!positionIndexes) {
184
+ return coordinates;
185
+ }
186
+ if (positionIndexes.length === 0) {
187
+ throw Error('Must specify the index of the position to remove');
188
+ }
189
+ if (positionIndexes.length === 1) {
190
+ const updated = [
191
+ ...coordinates.slice(0, positionIndexes[0]),
192
+ ...coordinates.slice(positionIndexes[0] + 1),
193
+ ];
194
+ if (isPolygonal &&
195
+ (positionIndexes[0] === 0 || positionIndexes[0] === coordinates.length - 1)) {
196
+ // for polygons, the first point is repeated at the end of the array
197
+ // so, if the first/last coordinate is to be removed, coordinates[1] will be the new first/last coordinate
198
+ if (positionIndexes[0] === 0) {
199
+ // change the last to be the same as the first
200
+ updated[updated.length - 1] = updated[0];
201
+ }
202
+ else if (positionIndexes[0] === coordinates.length - 1) {
203
+ // change the first to be the same as the last
204
+ updated[0] = updated[updated.length - 1];
205
+ }
206
+ }
207
+ return updated;
208
+ }
209
+ // recursively update inner array
210
+ return [
211
+ ...coordinates.slice(0, positionIndexes[0]),
212
+ immutablyRemovePosition(coordinates[positionIndexes[0]], positionIndexes.slice(1, positionIndexes.length), isPolygonal),
213
+ ...coordinates.slice(positionIndexes[0] + 1),
214
+ ];
215
+ }
216
+ function immutablyAddPosition(coordinates, positionIndexes, positionToAdd, isPolygonal) {
217
+ if (!positionIndexes) {
218
+ return coordinates;
219
+ }
220
+ if (positionIndexes.length === 0) {
221
+ throw Error('Must specify the index of the position to remove');
222
+ }
223
+ if (positionIndexes.length === 1) {
224
+ const updated = [
225
+ ...coordinates.slice(0, positionIndexes[0]),
226
+ positionToAdd,
227
+ ...coordinates.slice(positionIndexes[0]),
228
+ ];
229
+ return updated;
230
+ }
231
+ // recursively update inner array
232
+ return [
233
+ ...coordinates.slice(0, positionIndexes[0]),
234
+ immutablyAddPosition(coordinates[positionIndexes[0]], positionIndexes.slice(1, positionIndexes.length), positionToAdd, isPolygonal),
235
+ ...coordinates.slice(positionIndexes[0] + 1),
236
+ ];
237
+ }
238
+ function pruneGeometryIfNecessary(geometry) {
239
+ switch (geometry.type) {
240
+ case 'Polygon':
241
+ prunePolygonIfNecessary(geometry);
242
+ break;
243
+ case 'MultiLineString':
244
+ pruneMultiLineStringIfNecessary(geometry);
245
+ break;
246
+ case 'MultiPolygon':
247
+ pruneMultiPolygonIfNecessary(geometry);
248
+ break;
249
+ default:
250
+ // Not downgradable
251
+ break;
252
+ }
253
+ }
254
+ function prunePolygonIfNecessary(geometry) {
255
+ const polygon = geometry.coordinates;
256
+ // If any hole is no longer a polygon, remove the hole entirely
257
+ for (let holeIndex = 1; holeIndex < polygon.length; holeIndex++) {
258
+ if (removeHoleIfNecessary(polygon, holeIndex)) {
259
+ // It was removed, so keep the index the same
260
+ holeIndex--;
261
+ }
262
+ }
263
+ }
264
+ function pruneMultiLineStringIfNecessary(geometry) {
265
+ for (let lineStringIndex = 0; lineStringIndex < geometry.coordinates.length; lineStringIndex++) {
266
+ const lineString = geometry.coordinates[lineStringIndex];
267
+ if (lineString.length === 1) {
268
+ // Only a single position left on this LineString, so remove it (can't have Point in MultiLineString)
269
+ geometry.coordinates.splice(lineStringIndex, 1);
270
+ // Keep the index the same
271
+ lineStringIndex--;
272
+ }
273
+ }
274
+ }
275
+ function pruneMultiPolygonIfNecessary(geometry) {
276
+ for (let polygonIndex = 0; polygonIndex < geometry.coordinates.length; polygonIndex++) {
277
+ const polygon = geometry.coordinates[polygonIndex];
278
+ const outerRing = polygon[0];
279
+ // If the outer ring is no longer a polygon, remove the whole polygon
280
+ if (outerRing.length <= 3) {
281
+ geometry.coordinates.splice(polygonIndex, 1);
282
+ // It was removed, so keep the index the same
283
+ polygonIndex--;
284
+ }
285
+ for (let holeIndex = 1; holeIndex < polygon.length; holeIndex++) {
286
+ if (removeHoleIfNecessary(polygon, holeIndex)) {
287
+ // It was removed, so keep the index the same
288
+ holeIndex--;
289
+ }
290
+ }
291
+ }
292
+ }
293
+ function removeHoleIfNecessary(polygon, holeIndex) {
294
+ const hole = polygon[holeIndex];
295
+ if (hole.length <= 3) {
296
+ polygon.splice(holeIndex, 1);
297
+ return true;
298
+ }
299
+ return false;
300
+ }
@@ -0,0 +1,11 @@
1
+ import { ClickEvent, PointerMoveEvent, Tooltip, ModeProps, GuideFeatureCollection } from './types';
2
+ import { FeatureCollection, Position } from '../geojson-types';
3
+ import { GeoJsonEditMode } from './geojson-edit-mode';
4
+ export declare class MeasureAngleMode extends GeoJsonEditMode {
5
+ _getTooltips: (args: any) => any;
6
+ handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
7
+ handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>): void;
8
+ getPoints(props: ModeProps<FeatureCollection>): Position[];
9
+ getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection;
10
+ getTooltips(props: ModeProps<FeatureCollection>): Tooltip[];
11
+ }
@@ -0,0 +1,99 @@
1
+ import turfBearing from '@turf/bearing';
2
+ import turfCenter from '@turf/center';
3
+ import memoize from '../memoize';
4
+ import { GeoJsonEditMode } from './geojson-edit-mode';
5
+ const DEFAULT_TOOLTIPS = [];
6
+ export class MeasureAngleMode extends GeoJsonEditMode {
7
+ _getTooltips = memoize(({ modeConfig, vertex, point1, point2 }) => {
8
+ let tooltips = DEFAULT_TOOLTIPS;
9
+ if (vertex && point1 && point2) {
10
+ const { formatTooltip, measurementCallback } = modeConfig || {};
11
+ const units = 'deg';
12
+ const angle1 = turfBearing(vertex, point1);
13
+ const angle2 = turfBearing(vertex, point2);
14
+ let angle = Math.abs(angle1 - angle2);
15
+ if (angle > 180) {
16
+ angle = 360 - angle;
17
+ }
18
+ let text;
19
+ if (formatTooltip) {
20
+ text = formatTooltip(angle);
21
+ }
22
+ else {
23
+ // By default, round to 2 decimal places and append units
24
+ // @ts-expect-error angle isn't string
25
+ text = `${parseFloat(angle).toFixed(2)} ${units}`;
26
+ }
27
+ if (measurementCallback) {
28
+ measurementCallback(angle);
29
+ }
30
+ const position = turfCenter({
31
+ type: 'FeatureCollection',
32
+ features: [point1, point2].map((p) => ({
33
+ type: 'Feature',
34
+ geometry: {
35
+ type: 'Point',
36
+ coordinates: p,
37
+ },
38
+ properties: {}
39
+ })),
40
+ }).geometry.coordinates;
41
+ tooltips = [{ position, text }];
42
+ }
43
+ return tooltips;
44
+ });
45
+ handleClick(event, props) {
46
+ if (this.getClickSequence().length >= 3) {
47
+ this.resetClickSequence();
48
+ }
49
+ this.addClickSequence(event);
50
+ }
51
+ // Called when the pointer moved, regardless of whether the pointer is down, up, and whether something was picked
52
+ handlePointerMove(event, props) {
53
+ props.onUpdateCursor('cell');
54
+ }
55
+ getPoints(props) {
56
+ const clickSequence = this.getClickSequence();
57
+ const points = [...clickSequence];
58
+ if (clickSequence.length < 3 && props.lastPointerMoveEvent) {
59
+ points.push(props.lastPointerMoveEvent.mapCoords);
60
+ }
61
+ return points;
62
+ }
63
+ // Return features that can be used as a guide for editing the data
64
+ getGuides(props) {
65
+ const guides = { type: 'FeatureCollection', features: [] };
66
+ const { features } = guides;
67
+ const points = this.getPoints(props);
68
+ if (points.length > 2) {
69
+ features.push({
70
+ type: 'Feature',
71
+ properties: { guideType: 'tentative' },
72
+ geometry: {
73
+ type: 'LineString',
74
+ coordinates: [points[1], points[0], points[2]],
75
+ },
76
+ });
77
+ }
78
+ else if (points.length > 1) {
79
+ features.push({
80
+ type: 'Feature',
81
+ properties: { guideType: 'tentative' },
82
+ geometry: {
83
+ type: 'LineString',
84
+ coordinates: [points[1], points[0]],
85
+ },
86
+ });
87
+ }
88
+ return guides;
89
+ }
90
+ getTooltips(props) {
91
+ const points = this.getPoints(props);
92
+ return this._getTooltips({
93
+ modeConfig: props.modeConfig,
94
+ vertex: points[0],
95
+ point1: points[1],
96
+ point2: points[2],
97
+ });
98
+ }
99
+ }
@@ -0,0 +1,8 @@
1
+ import { ClickEvent, Tooltip, ModeProps } from './types';
2
+ import { FeatureCollection } from '../geojson-types';
3
+ import { DrawPolygonMode } from './draw-polygon-mode';
4
+ export declare class MeasureAreaMode extends DrawPolygonMode {
5
+ handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
6
+ handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>): void;
7
+ getTooltips(props: ModeProps<FeatureCollection>): Tooltip[];
8
+ }
@@ -0,0 +1,50 @@
1
+ import turfArea from '@turf/area';
2
+ import turfCentroid from '@turf/centroid';
3
+ import { DrawPolygonMode } from './draw-polygon-mode';
4
+ const DEFAULT_TOOLTIPS = [];
5
+ export class MeasureAreaMode extends DrawPolygonMode {
6
+ handleClick(event, props) {
7
+ const propsWithoutEdit = {
8
+ ...props,
9
+ onEdit: () => { },
10
+ };
11
+ super.handleClick(event, propsWithoutEdit);
12
+ }
13
+ handleKeyUp(event, props) {
14
+ const propsWithoutEdit = {
15
+ ...props,
16
+ onEdit: () => { },
17
+ };
18
+ super.handleKeyUp(event, propsWithoutEdit);
19
+ }
20
+ getTooltips(props) {
21
+ const tentativeGuide = this.getTentativeGuide(props);
22
+ if (tentativeGuide && tentativeGuide.geometry.type === 'Polygon') {
23
+ const { modeConfig } = props;
24
+ const { formatTooltip, measurementCallback } = modeConfig || {};
25
+ const units = 'sq. m';
26
+ const centroid = turfCentroid(tentativeGuide);
27
+ const area = turfArea(tentativeGuide);
28
+ let text;
29
+ if (formatTooltip) {
30
+ text = formatTooltip(area);
31
+ }
32
+ else {
33
+ // By default, round to 2 decimal places and append units
34
+ // @ts-expect-error are isn't string
35
+ text = `${parseFloat(area).toFixed(2)} ${units}`;
36
+ }
37
+ if (measurementCallback) {
38
+ measurementCallback(area);
39
+ }
40
+ return [
41
+ {
42
+ // @ts-expect-error turf types diff
43
+ position: centroid.geometry.coordinates,
44
+ text,
45
+ },
46
+ ];
47
+ }
48
+ return DEFAULT_TOOLTIPS;
49
+ }
50
+ }
@@ -0,0 +1,19 @@
1
+ import { FeatureCollection } from '../geojson-types';
2
+ import { ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection, Tooltip } from './types';
3
+ import { GeoJsonEditMode } from './geojson-edit-mode';
4
+ export declare class MeasureDistanceMode extends GeoJsonEditMode {
5
+ _isMeasuringSessionFinished: boolean;
6
+ _currentTooltips: Tooltip[];
7
+ _currentDistance: number;
8
+ _calculateDistanceForTooltip: ({ positionA, positionB, modeConfig }: {
9
+ positionA: any;
10
+ positionB: any;
11
+ modeConfig: any;
12
+ }) => number;
13
+ _formatTooltip(distance: any, modeConfig?: any): any;
14
+ handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
15
+ handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>): void;
16
+ getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection;
17
+ handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>): void;
18
+ getTooltips(props: ModeProps<FeatureCollection>): Tooltip[];
19
+ }