@reearth/core 0.0.7-alpha.5 → 0.0.7-alpha.51

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 (480) hide show
  1. package/dist/core.js +58676 -51066
  2. package/dist/core.umd.cjs +3959 -3915
  3. package/dist/{index-DqatWUTw.js → index-DqGWVPtz.js} +0 -1
  4. package/dist/index.d.ts +150 -34
  5. package/package.json +55 -39
  6. package/src/Map/ClusteredLayers/index.tsx +1 -1
  7. package/src/Map/Geoid/index.tsx +68 -0
  8. package/src/Map/Geoid/types.ts +8 -0
  9. package/src/Map/Layer/hooks.ts +7 -4
  10. package/src/Map/Layer/index.tsx +3 -1
  11. package/src/Map/Layers/hooks.ts +19 -2
  12. package/src/Map/Layers/index.tsx +13 -2
  13. package/src/Map/Layers/keys.ts +1 -0
  14. package/src/Map/Sketch/hooks.ts +453 -410
  15. package/src/Map/Sketch/index.tsx +67 -20
  16. package/src/Map/Sketch/sketchMachine.ts +359 -4
  17. package/src/Map/Sketch/sketchMachine.typegen.ts +58 -1
  18. package/src/Map/Sketch/types.ts +10 -20
  19. package/src/Map/Sketch/usePluginSketchLayer.ts +105 -0
  20. package/src/Map/Sketch/useSketch.ts +559 -0
  21. package/src/Map/Sketch/useSketchFeature.ts +198 -0
  22. package/src/Map/SpatialId/constants.ts +21 -0
  23. package/src/Map/SpatialId/hooks.ts +448 -0
  24. package/src/Map/SpatialId/index.tsx +63 -0
  25. package/src/Map/SpatialId/types.ts +68 -0
  26. package/src/Map/SpatialId/utils.ts +65 -0
  27. package/src/Map/hooks.ts +54 -8
  28. package/src/Map/index.tsx +41 -8
  29. package/src/Map/ref.ts +32 -3
  30. package/src/Map/types/index.ts +39 -3
  31. package/src/Map/types/viewerProperty.ts +10 -0
  32. package/src/Map/useTimelineManager.ts +2 -2
  33. package/src/Map/utils.ts +1 -1
  34. package/src/Visualizer/context.tsx +5 -5
  35. package/src/Visualizer/coreContext.tsx +2 -0
  36. package/src/Visualizer/hooks.ts +54 -20
  37. package/src/Visualizer/index.tsx +22 -3
  38. package/src/Visualizer/interactionMode.ts +2 -1
  39. package/src/Visualizer/useViewport.ts +1 -1
  40. package/src/engines/Cesium/Feature/Box/hooks/box.ts +4 -4
  41. package/src/engines/Cesium/Feature/HeatMap/HeatmapMesh.tsx +1 -1
  42. package/src/engines/Cesium/Feature/Model/index.tsx +3 -3
  43. package/src/engines/Cesium/Feature/PhotoOverlay/hooks.ts +1 -1
  44. package/src/engines/Cesium/Feature/PhotoOverlay/index.tsx +3 -1
  45. package/src/engines/Cesium/Feature/Polygon/index.tsx +6 -4
  46. package/src/engines/Cesium/Feature/Raster/mvt.ts +2 -1
  47. package/src/engines/Cesium/Feature/Resource/utils.ts +86 -91
  48. package/src/engines/Cesium/Feature/Tileset/hooks.ts +135 -70
  49. package/src/engines/Cesium/Feature/Tileset/index.tsx +1 -1
  50. package/src/engines/Cesium/Feature/Tileset/useClippingBox.ts +2 -2
  51. package/src/engines/Cesium/Feature/context.ts +1 -0
  52. package/src/engines/Cesium/Feature/index.tsx +7 -3
  53. package/src/engines/Cesium/Feature/utils.tsx +18 -7
  54. package/src/engines/Cesium/Shaders/OverriddenShaders/GlobeFS/IBL.glsl +6 -10
  55. package/src/engines/Cesium/Sketch/ControlPoint.tsx +128 -24
  56. package/src/engines/Cesium/Sketch/ExtrudedControlPoints.tsx +70 -25
  57. package/src/engines/Cesium/Sketch/ExtrudedMeasurement.tsx +3 -1
  58. package/src/engines/Cesium/Sketch/ExtrudedPolygonEntity.tsx +14 -14
  59. package/src/engines/Cesium/Sketch/PolylineEntity.tsx +7 -4
  60. package/src/engines/Cesium/Sketch/SurfaceAddingPoints.tsx +60 -0
  61. package/src/engines/Cesium/Sketch/SurfaceControlPoints.tsx +125 -35
  62. package/src/engines/Cesium/Sketch/constants.ts +5 -0
  63. package/src/engines/Cesium/Sketch/index.tsx +68 -29
  64. package/src/engines/Cesium/SpatialId/CoordinateIndicator.tsx +28 -0
  65. package/src/engines/Cesium/SpatialId/SpatialIdSpace.tsx +33 -0
  66. package/src/engines/Cesium/SpatialId/VerticalSpaceIndicator.tsx +32 -0
  67. package/src/engines/Cesium/SpatialId/index.ts +3 -0
  68. package/src/engines/Cesium/common.ts +52 -16
  69. package/src/engines/Cesium/core/Clock.tsx +1 -1
  70. package/src/engines/Cesium/core/Globe/index.tsx +73 -0
  71. package/src/engines/Cesium/core/Globe/useTerrainProviderPromise.ts +79 -0
  72. package/src/engines/Cesium/core/Imagery.test.ts +29 -11
  73. package/src/engines/Cesium/core/Imagery.tsx +22 -6
  74. package/src/engines/Cesium/core/Indicator/Indicator.tsx +1 -1
  75. package/src/engines/Cesium/core/labels/JapanGSIOptimalBVmapVectorMapLabel/JapanGSIOptimalBVmapLabelImagery.tsx +9 -2
  76. package/src/engines/Cesium/core/labels/JapanGSIOptimalBVmapVectorMapLabel/JapanGSIOptimalBVmapVectorMapLabel.tsx +14 -2
  77. package/src/engines/Cesium/core/labels/LabelImageryLayers.tsx +10 -1
  78. package/src/engines/Cesium/core/presets.ts +24 -28
  79. package/src/engines/Cesium/helpers/getGeometryFromEntity.ts +55 -0
  80. package/src/engines/Cesium/hooks/useCamera.ts +1 -1
  81. package/src/engines/Cesium/hooks/useCameraLimiter.ts +1 -1
  82. package/src/engines/Cesium/hooks/useEngineRef.ts +48 -3
  83. package/src/engines/Cesium/hooks/useExplicitRender.ts +2 -2
  84. package/src/engines/Cesium/hooks/useInstance.ts +1 -1
  85. package/src/engines/Cesium/hooks/useLayerDragDrop.ts +2 -2
  86. package/src/engines/Cesium/hooks/useLayerSelectWithRect.ts +1 -1
  87. package/src/engines/Cesium/hooks/useOverrideGlobeShader/useOverrideGlobeShader.ts +98 -52
  88. package/src/engines/Cesium/hooks/useViewerProperty.ts +1 -1
  89. package/src/engines/Cesium/hooks.ts +52 -10
  90. package/src/engines/Cesium/index.tsx +16 -3
  91. package/src/engines/Cesium/types.ts +1 -1
  92. package/src/mantle/atoms/compute.ts +8 -3
  93. package/src/mantle/data/geojson.ts +53 -22
  94. package/src/mantle/data/shapefile/parseZip.ts +1 -0
  95. package/src/mantle/evaluator/simple/expression/expression.test.ts +72 -0
  96. package/src/mantle/evaluator/simple/expression/node.ts +10 -12
  97. package/src/mantle/types/appearance.ts +4 -2
  98. package/src/mantle/types/index.ts +3 -0
  99. package/src/test/utils.tsx +1 -1
  100. package/src/utils/image.ts +2 -12
  101. package/src/utils/use-delayed-count.ts +1 -1
  102. package/src/utils/use-dnd/drop.ts +1 -1
  103. package/src/utils/util.ts +1 -1
  104. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_0.json +0 -1
  105. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_1.json +0 -1
  106. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_10.json +0 -1
  107. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_11.json +0 -1
  108. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_12.json +0 -1
  109. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_13.json +0 -1
  110. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_14.json +0 -1
  111. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_15.json +0 -1
  112. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_16.json +0 -1
  113. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_17.json +0 -1
  114. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_18.json +0 -1
  115. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_19.json +0 -1
  116. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_2.json +0 -1
  117. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_20.json +0 -1
  118. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_21.json +0 -1
  119. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_22.json +0 -1
  120. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_23.json +0 -1
  121. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_24.json +0 -1
  122. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_25.json +0 -1
  123. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_26.json +0 -1
  124. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_27.json +0 -1
  125. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_3.json +0 -1
  126. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_4.json +0 -1
  127. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_5.json +0 -1
  128. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_6.json +0 -1
  129. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_7.json +0 -1
  130. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_8.json +0 -1
  131. package/dist/cesium/Assets/IAU2006_XYS/IAU2006_XYS_9.json +0 -1
  132. package/dist/cesium/Assets/Images/bing_maps_credit.png +0 -0
  133. package/dist/cesium/Assets/Images/cesium_credit.png +0 -0
  134. package/dist/cesium/Assets/Images/google_earth_credit.png +0 -0
  135. package/dist/cesium/Assets/Images/ion-credit.png +0 -0
  136. package/dist/cesium/Assets/Textures/LensFlare/DirtMask.jpg +0 -0
  137. package/dist/cesium/Assets/Textures/LensFlare/StarBurst.jpg +0 -0
  138. package/dist/cesium/Assets/Textures/NaturalEarthII/0/0/0.jpg +0 -0
  139. package/dist/cesium/Assets/Textures/NaturalEarthII/0/1/0.jpg +0 -0
  140. package/dist/cesium/Assets/Textures/NaturalEarthII/1/0/0.jpg +0 -0
  141. package/dist/cesium/Assets/Textures/NaturalEarthII/1/0/1.jpg +0 -0
  142. package/dist/cesium/Assets/Textures/NaturalEarthII/1/1/0.jpg +0 -0
  143. package/dist/cesium/Assets/Textures/NaturalEarthII/1/1/1.jpg +0 -0
  144. package/dist/cesium/Assets/Textures/NaturalEarthII/1/2/0.jpg +0 -0
  145. package/dist/cesium/Assets/Textures/NaturalEarthII/1/2/1.jpg +0 -0
  146. package/dist/cesium/Assets/Textures/NaturalEarthII/1/3/0.jpg +0 -0
  147. package/dist/cesium/Assets/Textures/NaturalEarthII/1/3/1.jpg +0 -0
  148. package/dist/cesium/Assets/Textures/NaturalEarthII/2/0/0.jpg +0 -0
  149. package/dist/cesium/Assets/Textures/NaturalEarthII/2/0/1.jpg +0 -0
  150. package/dist/cesium/Assets/Textures/NaturalEarthII/2/0/2.jpg +0 -0
  151. package/dist/cesium/Assets/Textures/NaturalEarthII/2/0/3.jpg +0 -0
  152. package/dist/cesium/Assets/Textures/NaturalEarthII/2/1/0.jpg +0 -0
  153. package/dist/cesium/Assets/Textures/NaturalEarthII/2/1/1.jpg +0 -0
  154. package/dist/cesium/Assets/Textures/NaturalEarthII/2/1/2.jpg +0 -0
  155. package/dist/cesium/Assets/Textures/NaturalEarthII/2/1/3.jpg +0 -0
  156. package/dist/cesium/Assets/Textures/NaturalEarthII/2/2/0.jpg +0 -0
  157. package/dist/cesium/Assets/Textures/NaturalEarthII/2/2/1.jpg +0 -0
  158. package/dist/cesium/Assets/Textures/NaturalEarthII/2/2/2.jpg +0 -0
  159. package/dist/cesium/Assets/Textures/NaturalEarthII/2/2/3.jpg +0 -0
  160. package/dist/cesium/Assets/Textures/NaturalEarthII/2/3/0.jpg +0 -0
  161. package/dist/cesium/Assets/Textures/NaturalEarthII/2/3/1.jpg +0 -0
  162. package/dist/cesium/Assets/Textures/NaturalEarthII/2/3/2.jpg +0 -0
  163. package/dist/cesium/Assets/Textures/NaturalEarthII/2/3/3.jpg +0 -0
  164. package/dist/cesium/Assets/Textures/NaturalEarthII/2/4/0.jpg +0 -0
  165. package/dist/cesium/Assets/Textures/NaturalEarthII/2/4/1.jpg +0 -0
  166. package/dist/cesium/Assets/Textures/NaturalEarthII/2/4/2.jpg +0 -0
  167. package/dist/cesium/Assets/Textures/NaturalEarthII/2/4/3.jpg +0 -0
  168. package/dist/cesium/Assets/Textures/NaturalEarthII/2/5/0.jpg +0 -0
  169. package/dist/cesium/Assets/Textures/NaturalEarthII/2/5/1.jpg +0 -0
  170. package/dist/cesium/Assets/Textures/NaturalEarthII/2/5/2.jpg +0 -0
  171. package/dist/cesium/Assets/Textures/NaturalEarthII/2/5/3.jpg +0 -0
  172. package/dist/cesium/Assets/Textures/NaturalEarthII/2/6/0.jpg +0 -0
  173. package/dist/cesium/Assets/Textures/NaturalEarthII/2/6/1.jpg +0 -0
  174. package/dist/cesium/Assets/Textures/NaturalEarthII/2/6/2.jpg +0 -0
  175. package/dist/cesium/Assets/Textures/NaturalEarthII/2/6/3.jpg +0 -0
  176. package/dist/cesium/Assets/Textures/NaturalEarthII/2/7/0.jpg +0 -0
  177. package/dist/cesium/Assets/Textures/NaturalEarthII/2/7/1.jpg +0 -0
  178. package/dist/cesium/Assets/Textures/NaturalEarthII/2/7/2.jpg +0 -0
  179. package/dist/cesium/Assets/Textures/NaturalEarthII/2/7/3.jpg +0 -0
  180. package/dist/cesium/Assets/Textures/NaturalEarthII/tilemapresource.xml +0 -14
  181. package/dist/cesium/Assets/Textures/SkyBox/tycho2t3_80_mx.jpg +0 -0
  182. package/dist/cesium/Assets/Textures/SkyBox/tycho2t3_80_my.jpg +0 -0
  183. package/dist/cesium/Assets/Textures/SkyBox/tycho2t3_80_mz.jpg +0 -0
  184. package/dist/cesium/Assets/Textures/SkyBox/tycho2t3_80_px.jpg +0 -0
  185. package/dist/cesium/Assets/Textures/SkyBox/tycho2t3_80_py.jpg +0 -0
  186. package/dist/cesium/Assets/Textures/SkyBox/tycho2t3_80_pz.jpg +0 -0
  187. package/dist/cesium/Assets/Textures/maki/airfield.png +0 -0
  188. package/dist/cesium/Assets/Textures/maki/airport.png +0 -0
  189. package/dist/cesium/Assets/Textures/maki/alcohol-shop.png +0 -0
  190. package/dist/cesium/Assets/Textures/maki/america-football.png +0 -0
  191. package/dist/cesium/Assets/Textures/maki/art-gallery.png +0 -0
  192. package/dist/cesium/Assets/Textures/maki/bakery.png +0 -0
  193. package/dist/cesium/Assets/Textures/maki/bank.png +0 -0
  194. package/dist/cesium/Assets/Textures/maki/bar.png +0 -0
  195. package/dist/cesium/Assets/Textures/maki/baseball.png +0 -0
  196. package/dist/cesium/Assets/Textures/maki/basketball.png +0 -0
  197. package/dist/cesium/Assets/Textures/maki/beer.png +0 -0
  198. package/dist/cesium/Assets/Textures/maki/bicycle.png +0 -0
  199. package/dist/cesium/Assets/Textures/maki/building.png +0 -0
  200. package/dist/cesium/Assets/Textures/maki/bus.png +0 -0
  201. package/dist/cesium/Assets/Textures/maki/cafe.png +0 -0
  202. package/dist/cesium/Assets/Textures/maki/camera.png +0 -0
  203. package/dist/cesium/Assets/Textures/maki/campsite.png +0 -0
  204. package/dist/cesium/Assets/Textures/maki/car.png +0 -0
  205. package/dist/cesium/Assets/Textures/maki/cemetery.png +0 -0
  206. package/dist/cesium/Assets/Textures/maki/cesium.png +0 -0
  207. package/dist/cesium/Assets/Textures/maki/chemist.png +0 -0
  208. package/dist/cesium/Assets/Textures/maki/cinema.png +0 -0
  209. package/dist/cesium/Assets/Textures/maki/circle-stroked.png +0 -0
  210. package/dist/cesium/Assets/Textures/maki/circle.png +0 -0
  211. package/dist/cesium/Assets/Textures/maki/city.png +0 -0
  212. package/dist/cesium/Assets/Textures/maki/clothing-store.png +0 -0
  213. package/dist/cesium/Assets/Textures/maki/college.png +0 -0
  214. package/dist/cesium/Assets/Textures/maki/commercial.png +0 -0
  215. package/dist/cesium/Assets/Textures/maki/cricket.png +0 -0
  216. package/dist/cesium/Assets/Textures/maki/cross.png +0 -0
  217. package/dist/cesium/Assets/Textures/maki/dam.png +0 -0
  218. package/dist/cesium/Assets/Textures/maki/danger.png +0 -0
  219. package/dist/cesium/Assets/Textures/maki/disability.png +0 -0
  220. package/dist/cesium/Assets/Textures/maki/dog-park.png +0 -0
  221. package/dist/cesium/Assets/Textures/maki/embassy.png +0 -0
  222. package/dist/cesium/Assets/Textures/maki/emergency-telephone.png +0 -0
  223. package/dist/cesium/Assets/Textures/maki/entrance.png +0 -0
  224. package/dist/cesium/Assets/Textures/maki/farm.png +0 -0
  225. package/dist/cesium/Assets/Textures/maki/fast-food.png +0 -0
  226. package/dist/cesium/Assets/Textures/maki/ferry.png +0 -0
  227. package/dist/cesium/Assets/Textures/maki/fire-station.png +0 -0
  228. package/dist/cesium/Assets/Textures/maki/fuel.png +0 -0
  229. package/dist/cesium/Assets/Textures/maki/garden.png +0 -0
  230. package/dist/cesium/Assets/Textures/maki/gift.png +0 -0
  231. package/dist/cesium/Assets/Textures/maki/golf.png +0 -0
  232. package/dist/cesium/Assets/Textures/maki/grocery.png +0 -0
  233. package/dist/cesium/Assets/Textures/maki/hairdresser.png +0 -0
  234. package/dist/cesium/Assets/Textures/maki/harbor.png +0 -0
  235. package/dist/cesium/Assets/Textures/maki/heart.png +0 -0
  236. package/dist/cesium/Assets/Textures/maki/heliport.png +0 -0
  237. package/dist/cesium/Assets/Textures/maki/hospital.png +0 -0
  238. package/dist/cesium/Assets/Textures/maki/ice-cream.png +0 -0
  239. package/dist/cesium/Assets/Textures/maki/industrial.png +0 -0
  240. package/dist/cesium/Assets/Textures/maki/land-use.png +0 -0
  241. package/dist/cesium/Assets/Textures/maki/laundry.png +0 -0
  242. package/dist/cesium/Assets/Textures/maki/library.png +0 -0
  243. package/dist/cesium/Assets/Textures/maki/lighthouse.png +0 -0
  244. package/dist/cesium/Assets/Textures/maki/lodging.png +0 -0
  245. package/dist/cesium/Assets/Textures/maki/logging.png +0 -0
  246. package/dist/cesium/Assets/Textures/maki/london-underground.png +0 -0
  247. package/dist/cesium/Assets/Textures/maki/marker-stroked.png +0 -0
  248. package/dist/cesium/Assets/Textures/maki/marker.png +0 -0
  249. package/dist/cesium/Assets/Textures/maki/minefield.png +0 -0
  250. package/dist/cesium/Assets/Textures/maki/mobilephone.png +0 -0
  251. package/dist/cesium/Assets/Textures/maki/monument.png +0 -0
  252. package/dist/cesium/Assets/Textures/maki/museum.png +0 -0
  253. package/dist/cesium/Assets/Textures/maki/music.png +0 -0
  254. package/dist/cesium/Assets/Textures/maki/oil-well.png +0 -0
  255. package/dist/cesium/Assets/Textures/maki/park.png +0 -0
  256. package/dist/cesium/Assets/Textures/maki/park2.png +0 -0
  257. package/dist/cesium/Assets/Textures/maki/parking-garage.png +0 -0
  258. package/dist/cesium/Assets/Textures/maki/parking.png +0 -0
  259. package/dist/cesium/Assets/Textures/maki/pharmacy.png +0 -0
  260. package/dist/cesium/Assets/Textures/maki/pitch.png +0 -0
  261. package/dist/cesium/Assets/Textures/maki/place-of-worship.png +0 -0
  262. package/dist/cesium/Assets/Textures/maki/playground.png +0 -0
  263. package/dist/cesium/Assets/Textures/maki/police.png +0 -0
  264. package/dist/cesium/Assets/Textures/maki/polling-place.png +0 -0
  265. package/dist/cesium/Assets/Textures/maki/post.png +0 -0
  266. package/dist/cesium/Assets/Textures/maki/prison.png +0 -0
  267. package/dist/cesium/Assets/Textures/maki/rail-above.png +0 -0
  268. package/dist/cesium/Assets/Textures/maki/rail-light.png +0 -0
  269. package/dist/cesium/Assets/Textures/maki/rail-metro.png +0 -0
  270. package/dist/cesium/Assets/Textures/maki/rail-underground.png +0 -0
  271. package/dist/cesium/Assets/Textures/maki/rail.png +0 -0
  272. package/dist/cesium/Assets/Textures/maki/religious-christian.png +0 -0
  273. package/dist/cesium/Assets/Textures/maki/religious-jewish.png +0 -0
  274. package/dist/cesium/Assets/Textures/maki/religious-muslim.png +0 -0
  275. package/dist/cesium/Assets/Textures/maki/restaurant.png +0 -0
  276. package/dist/cesium/Assets/Textures/maki/roadblock.png +0 -0
  277. package/dist/cesium/Assets/Textures/maki/rocket.png +0 -0
  278. package/dist/cesium/Assets/Textures/maki/school.png +0 -0
  279. package/dist/cesium/Assets/Textures/maki/scooter.png +0 -0
  280. package/dist/cesium/Assets/Textures/maki/shop.png +0 -0
  281. package/dist/cesium/Assets/Textures/maki/skiing.png +0 -0
  282. package/dist/cesium/Assets/Textures/maki/slaughterhouse.png +0 -0
  283. package/dist/cesium/Assets/Textures/maki/soccer.png +0 -0
  284. package/dist/cesium/Assets/Textures/maki/square-stroked.png +0 -0
  285. package/dist/cesium/Assets/Textures/maki/square.png +0 -0
  286. package/dist/cesium/Assets/Textures/maki/star-stroked.png +0 -0
  287. package/dist/cesium/Assets/Textures/maki/star.png +0 -0
  288. package/dist/cesium/Assets/Textures/maki/suitcase.png +0 -0
  289. package/dist/cesium/Assets/Textures/maki/swimming.png +0 -0
  290. package/dist/cesium/Assets/Textures/maki/telephone.png +0 -0
  291. package/dist/cesium/Assets/Textures/maki/tennis.png +0 -0
  292. package/dist/cesium/Assets/Textures/maki/theatre.png +0 -0
  293. package/dist/cesium/Assets/Textures/maki/toilets.png +0 -0
  294. package/dist/cesium/Assets/Textures/maki/town-hall.png +0 -0
  295. package/dist/cesium/Assets/Textures/maki/town.png +0 -0
  296. package/dist/cesium/Assets/Textures/maki/triangle-stroked.png +0 -0
  297. package/dist/cesium/Assets/Textures/maki/triangle.png +0 -0
  298. package/dist/cesium/Assets/Textures/maki/village.png +0 -0
  299. package/dist/cesium/Assets/Textures/maki/warehouse.png +0 -0
  300. package/dist/cesium/Assets/Textures/maki/waste-basket.png +0 -0
  301. package/dist/cesium/Assets/Textures/maki/water.png +0 -0
  302. package/dist/cesium/Assets/Textures/maki/wetland.png +0 -0
  303. package/dist/cesium/Assets/Textures/maki/zoo.png +0 -0
  304. package/dist/cesium/Assets/Textures/moonSmall.jpg +0 -0
  305. package/dist/cesium/Assets/Textures/pin.svg +0 -1
  306. package/dist/cesium/Assets/Textures/waterNormals.jpg +0 -0
  307. package/dist/cesium/Assets/Textures/waterNormalsSmall.jpg +0 -0
  308. package/dist/cesium/Assets/approximateTerrainHeights.json +0 -1
  309. package/dist/cesium/ThirdParty/Workers/package.json +0 -1
  310. package/dist/cesium/ThirdParty/Workers/pako_deflate.min.js +0 -1
  311. package/dist/cesium/ThirdParty/Workers/pako_inflate.min.js +0 -1
  312. package/dist/cesium/ThirdParty/Workers/z-worker-pako.js +0 -1
  313. package/dist/cesium/ThirdParty/basis_transcoder.wasm +0 -0
  314. package/dist/cesium/ThirdParty/draco_decoder.wasm +0 -0
  315. package/dist/cesium/ThirdParty/google-earth-dbroot-parser.js +0 -1
  316. package/dist/cesium/Widgets/Animation/Animation.css +0 -127
  317. package/dist/cesium/Widgets/Animation/lighter.css +0 -70
  318. package/dist/cesium/Widgets/BaseLayerPicker/BaseLayerPicker.css +0 -108
  319. package/dist/cesium/Widgets/BaseLayerPicker/lighter.css +0 -22
  320. package/dist/cesium/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspector.css +0 -102
  321. package/dist/cesium/Widgets/CesiumInspector/CesiumInspector.css +0 -113
  322. package/dist/cesium/Widgets/CesiumWidget/CesiumWidget.css +0 -124
  323. package/dist/cesium/Widgets/CesiumWidget/lighter.css +0 -14
  324. package/dist/cesium/Widgets/FullscreenButton/FullscreenButton.css +0 -8
  325. package/dist/cesium/Widgets/Geocoder/Geocoder.css +0 -70
  326. package/dist/cesium/Widgets/Geocoder/lighter.css +0 -17
  327. package/dist/cesium/Widgets/I3SBuildingSceneLayerExplorer/I3SBuildingSceneLayerExplorer.css +0 -27
  328. package/dist/cesium/Widgets/Images/ImageryProviders/ArcGisMapServiceWorldHillshade.png +0 -0
  329. package/dist/cesium/Widgets/Images/ImageryProviders/ArcGisMapServiceWorldImagery.png +0 -0
  330. package/dist/cesium/Widgets/Images/ImageryProviders/ArcGisMapServiceWorldOcean.png +0 -0
  331. package/dist/cesium/Widgets/Images/ImageryProviders/bingAerial.png +0 -0
  332. package/dist/cesium/Widgets/Images/ImageryProviders/bingAerialLabels.png +0 -0
  333. package/dist/cesium/Widgets/Images/ImageryProviders/bingRoads.png +0 -0
  334. package/dist/cesium/Widgets/Images/ImageryProviders/blueMarble.png +0 -0
  335. package/dist/cesium/Widgets/Images/ImageryProviders/earthAtNight.png +0 -0
  336. package/dist/cesium/Widgets/Images/ImageryProviders/mapQuestOpenStreetMap.png +0 -0
  337. package/dist/cesium/Widgets/Images/ImageryProviders/mapboxSatellite.png +0 -0
  338. package/dist/cesium/Widgets/Images/ImageryProviders/mapboxStreets.png +0 -0
  339. package/dist/cesium/Widgets/Images/ImageryProviders/mapboxTerrain.png +0 -0
  340. package/dist/cesium/Widgets/Images/ImageryProviders/naturalEarthII.png +0 -0
  341. package/dist/cesium/Widgets/Images/ImageryProviders/openStreetMap.png +0 -0
  342. package/dist/cesium/Widgets/Images/ImageryProviders/sentinel-2.png +0 -0
  343. package/dist/cesium/Widgets/Images/ImageryProviders/stadiaAlidadeSmooth.png +0 -0
  344. package/dist/cesium/Widgets/Images/ImageryProviders/stadiaAlidadeSmoothDark.png +0 -0
  345. package/dist/cesium/Widgets/Images/ImageryProviders/stamenToner.png +0 -0
  346. package/dist/cesium/Widgets/Images/ImageryProviders/stamenWatercolor.png +0 -0
  347. package/dist/cesium/Widgets/Images/NavigationHelp/Mouse.svg +0 -84
  348. package/dist/cesium/Widgets/Images/NavigationHelp/MouseLeft.svg +0 -76
  349. package/dist/cesium/Widgets/Images/NavigationHelp/MouseMiddle.svg +0 -76
  350. package/dist/cesium/Widgets/Images/NavigationHelp/MouseRight.svg +0 -76
  351. package/dist/cesium/Widgets/Images/NavigationHelp/Touch.svg +0 -120
  352. package/dist/cesium/Widgets/Images/NavigationHelp/TouchDrag.svg +0 -129
  353. package/dist/cesium/Widgets/Images/NavigationHelp/TouchRotate.svg +0 -76
  354. package/dist/cesium/Widgets/Images/NavigationHelp/TouchTilt.svg +0 -135
  355. package/dist/cesium/Widgets/Images/NavigationHelp/TouchZoom.svg +0 -74
  356. package/dist/cesium/Widgets/Images/TerrainProviders/CesiumWorldTerrain.png +0 -0
  357. package/dist/cesium/Widgets/Images/TerrainProviders/Ellipsoid.png +0 -0
  358. package/dist/cesium/Widgets/Images/TimelineIcons.png +0 -0
  359. package/dist/cesium/Widgets/Images/info-loading.gif +0 -0
  360. package/dist/cesium/Widgets/InfoBox/InfoBox.css +0 -92
  361. package/dist/cesium/Widgets/InfoBox/InfoBoxDescription.css +0 -178
  362. package/dist/cesium/Widgets/NavigationHelpButton/NavigationHelpButton.css +0 -93
  363. package/dist/cesium/Widgets/NavigationHelpButton/lighter.css +0 -38
  364. package/dist/cesium/Widgets/PerformanceWatchdog/PerformanceWatchdog.css +0 -15
  365. package/dist/cesium/Widgets/ProjectionPicker/ProjectionPicker.css +0 -38
  366. package/dist/cesium/Widgets/SceneModePicker/SceneModePicker.css +0 -56
  367. package/dist/cesium/Widgets/SelectionIndicator/SelectionIndicator.css +0 -20
  368. package/dist/cesium/Widgets/Timeline/Timeline.css +0 -103
  369. package/dist/cesium/Widgets/Timeline/lighter.css +0 -23
  370. package/dist/cesium/Widgets/VRButton/VRButton.css +0 -8
  371. package/dist/cesium/Widgets/Viewer/Viewer.css +0 -107
  372. package/dist/cesium/Widgets/VoxelInspector/VoxelInspector.css +0 -16
  373. package/dist/cesium/Widgets/lighter.css +0 -237
  374. package/dist/cesium/Widgets/lighterShared.css +0 -46
  375. package/dist/cesium/Widgets/shared.css +0 -103
  376. package/dist/cesium/Widgets/widgets.css +0 -1346
  377. package/dist/cesium/Workers/chunk-2ED5WI77.js +0 -26
  378. package/dist/cesium/Workers/chunk-2MBPFWCP.js +0 -26
  379. package/dist/cesium/Workers/chunk-3C74MLG3.js +0 -26
  380. package/dist/cesium/Workers/chunk-45U7TTT3.js +0 -26
  381. package/dist/cesium/Workers/chunk-4N7SRDH5.js +0 -26
  382. package/dist/cesium/Workers/chunk-4T6AS6BZ.js +0 -26
  383. package/dist/cesium/Workers/chunk-5AG2MVRM.js +0 -26
  384. package/dist/cesium/Workers/chunk-5Z6L2FHX.js +0 -26
  385. package/dist/cesium/Workers/chunk-6AUUBDOF.js +0 -26
  386. package/dist/cesium/Workers/chunk-74N6MC2V.js +0 -26
  387. package/dist/cesium/Workers/chunk-7VJK3KHI.js +0 -26
  388. package/dist/cesium/Workers/chunk-7VZHIB6P.js +0 -26
  389. package/dist/cesium/Workers/chunk-7X2YQ6I4.js +0 -27
  390. package/dist/cesium/Workers/chunk-B2SKQ7LU.js +0 -26
  391. package/dist/cesium/Workers/chunk-B4TQDFIE.js +0 -26
  392. package/dist/cesium/Workers/chunk-B6TRTFAA.js +0 -26
  393. package/dist/cesium/Workers/chunk-BK3HCS7I.js +0 -26
  394. package/dist/cesium/Workers/chunk-BOPB43LN.js +0 -26
  395. package/dist/cesium/Workers/chunk-C6DMEJQ7.js +0 -26
  396. package/dist/cesium/Workers/chunk-CN7UN2OZ.js +0 -26
  397. package/dist/cesium/Workers/chunk-CSISXEG7.js +0 -26
  398. package/dist/cesium/Workers/chunk-CUOR5F7T.js +0 -28
  399. package/dist/cesium/Workers/chunk-DGCK3LD2.js +0 -30
  400. package/dist/cesium/Workers/chunk-DXEZYE3K.js +0 -62
  401. package/dist/cesium/Workers/chunk-EXBFEYPQ.js +0 -26
  402. package/dist/cesium/Workers/chunk-FK5KFB6H.js +0 -26
  403. package/dist/cesium/Workers/chunk-HPBHKP5S.js +0 -26
  404. package/dist/cesium/Workers/chunk-JCJ24DHF.js +0 -26
  405. package/dist/cesium/Workers/chunk-JEWHFDAA.js +0 -26
  406. package/dist/cesium/Workers/chunk-JZLZJJQD.js +0 -26
  407. package/dist/cesium/Workers/chunk-KRZBI2MU.js +0 -26
  408. package/dist/cesium/Workers/chunk-KTTUANTJ.js +0 -26
  409. package/dist/cesium/Workers/chunk-LDCAXLGS.js +0 -26
  410. package/dist/cesium/Workers/chunk-LOPN5R3I.js +0 -26
  411. package/dist/cesium/Workers/chunk-MDLPQIMP.js +0 -26
  412. package/dist/cesium/Workers/chunk-MRR3RGFO.js +0 -26
  413. package/dist/cesium/Workers/chunk-NPBZI5YA.js +0 -26
  414. package/dist/cesium/Workers/chunk-NUSW5B6A.js +0 -26
  415. package/dist/cesium/Workers/chunk-OUXRUXNB.js +0 -26
  416. package/dist/cesium/Workers/chunk-QPOPEH3M.js +0 -26
  417. package/dist/cesium/Workers/chunk-R2AN7EKC.js +0 -26
  418. package/dist/cesium/Workers/chunk-RURL6ZX2.js +0 -26
  419. package/dist/cesium/Workers/chunk-SUQM3OSW.js +0 -28
  420. package/dist/cesium/Workers/chunk-UBIRX2SP.js +0 -26
  421. package/dist/cesium/Workers/chunk-VAKC5J5C.js +0 -26
  422. package/dist/cesium/Workers/chunk-VHNZBQTR.js +0 -27
  423. package/dist/cesium/Workers/chunk-VKV642QV.js +0 -26
  424. package/dist/cesium/Workers/chunk-VMSXG4OA.js +0 -26
  425. package/dist/cesium/Workers/chunk-VQZSIOZW.js +0 -26
  426. package/dist/cesium/Workers/chunk-WZUWQMI7.js +0 -26
  427. package/dist/cesium/Workers/chunk-YBI55DLZ.js +0 -26
  428. package/dist/cesium/Workers/chunk-YEJWCH6C.js +0 -26
  429. package/dist/cesium/Workers/chunk-YPDO7SPO.js +0 -26
  430. package/dist/cesium/Workers/chunk-ZYWD6OQH.js +0 -26
  431. package/dist/cesium/Workers/combineGeometry.js +0 -26
  432. package/dist/cesium/Workers/createBoxGeometry.js +0 -26
  433. package/dist/cesium/Workers/createBoxOutlineGeometry.js +0 -26
  434. package/dist/cesium/Workers/createCircleGeometry.js +0 -26
  435. package/dist/cesium/Workers/createCircleOutlineGeometry.js +0 -26
  436. package/dist/cesium/Workers/createCoplanarPolygonGeometry.js +0 -26
  437. package/dist/cesium/Workers/createCoplanarPolygonOutlineGeometry.js +0 -26
  438. package/dist/cesium/Workers/createCorridorGeometry.js +0 -26
  439. package/dist/cesium/Workers/createCorridorOutlineGeometry.js +0 -26
  440. package/dist/cesium/Workers/createCylinderGeometry.js +0 -26
  441. package/dist/cesium/Workers/createCylinderOutlineGeometry.js +0 -26
  442. package/dist/cesium/Workers/createEllipseGeometry.js +0 -26
  443. package/dist/cesium/Workers/createEllipseOutlineGeometry.js +0 -26
  444. package/dist/cesium/Workers/createEllipsoidGeometry.js +0 -26
  445. package/dist/cesium/Workers/createEllipsoidOutlineGeometry.js +0 -26
  446. package/dist/cesium/Workers/createFrustumGeometry.js +0 -26
  447. package/dist/cesium/Workers/createFrustumOutlineGeometry.js +0 -26
  448. package/dist/cesium/Workers/createGeometry.js +0 -26
  449. package/dist/cesium/Workers/createGroundPolylineGeometry.js +0 -26
  450. package/dist/cesium/Workers/createPlaneGeometry.js +0 -26
  451. package/dist/cesium/Workers/createPlaneOutlineGeometry.js +0 -26
  452. package/dist/cesium/Workers/createPolygonGeometry.js +0 -26
  453. package/dist/cesium/Workers/createPolygonOutlineGeometry.js +0 -26
  454. package/dist/cesium/Workers/createPolylineGeometry.js +0 -26
  455. package/dist/cesium/Workers/createPolylineVolumeGeometry.js +0 -26
  456. package/dist/cesium/Workers/createPolylineVolumeOutlineGeometry.js +0 -26
  457. package/dist/cesium/Workers/createRectangleGeometry.js +0 -26
  458. package/dist/cesium/Workers/createRectangleOutlineGeometry.js +0 -26
  459. package/dist/cesium/Workers/createSimplePolylineGeometry.js +0 -26
  460. package/dist/cesium/Workers/createSphereGeometry.js +0 -26
  461. package/dist/cesium/Workers/createSphereOutlineGeometry.js +0 -26
  462. package/dist/cesium/Workers/createTaskProcessorWorker.js +0 -26
  463. package/dist/cesium/Workers/createVectorTileClampedPolylines.js +0 -26
  464. package/dist/cesium/Workers/createVectorTileGeometries.js +0 -26
  465. package/dist/cesium/Workers/createVectorTilePoints.js +0 -26
  466. package/dist/cesium/Workers/createVectorTilePolygons.js +0 -26
  467. package/dist/cesium/Workers/createVectorTilePolylines.js +0 -26
  468. package/dist/cesium/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +0 -26
  469. package/dist/cesium/Workers/createVerticesFromHeightmap.js +0 -26
  470. package/dist/cesium/Workers/createVerticesFromQuantizedTerrainMesh.js +0 -26
  471. package/dist/cesium/Workers/createWallGeometry.js +0 -26
  472. package/dist/cesium/Workers/createWallOutlineGeometry.js +0 -26
  473. package/dist/cesium/Workers/decodeDraco.js +0 -26
  474. package/dist/cesium/Workers/decodeGoogleEarthEnterprisePacket.js +0 -26
  475. package/dist/cesium/Workers/decodeI3S.js +0 -26
  476. package/dist/cesium/Workers/transcodeKTX2.js +0 -56
  477. package/dist/cesium/Workers/transferTypedArrayTest.js +0 -26
  478. package/dist/cesium/Workers/upsampleQuantizedTerrainMesh.js +0 -26
  479. package/src/engines/Cesium/core/Globe.tsx +0 -104
  480. /package/src/{Map/Sketch/utils.ts → utils/use-window-event.ts} +0 -0
@@ -8,22 +8,17 @@ import {
8
8
  useCallback,
9
9
  useEffect,
10
10
  useImperativeHandle,
11
+ useMemo,
11
12
  useRef,
12
13
  useState,
13
14
  } from "react";
14
- import invariant from "tiny-invariant";
15
15
  import { v4 as uuidv4 } from "uuid";
16
+ import { InterpreterFrom, StateFrom } from "xstate";
16
17
 
18
+ import { ControlPointMouseEventHandler } from "../../engines/Cesium/Sketch";
19
+ import { useWindowEvent } from "../../utils/use-window-event";
17
20
  import { InteractionModeType } from "../../Visualizer/interactionMode";
18
- import { LayerSimple, LazyLayer } from "../Layers";
19
- import {
20
- Feature,
21
- EngineRef,
22
- LayersRef,
23
- MouseEventCallback,
24
- MouseEventProps,
25
- SketchRef,
26
- } from "../types";
21
+ import { Feature, EngineRef, LayersRef, SketchRef } from "../types";
27
22
  import { useGet } from "../utils";
28
23
 
29
24
  import { PRESET_APPEARANCE, PRESET_COLOR } from "./preset";
@@ -34,8 +29,12 @@ import {
34
29
  SketchFeature,
35
30
  SketchEventProps,
36
31
  SketchOptions,
32
+ SketchEditingFeature,
33
+ SketchEditFeatureChangeCb,
37
34
  } from "./types";
38
- import { useWindowEvent } from "./utils";
35
+ import usePluginSketchLayer from "./usePluginSketchLayer";
36
+ import useSketch from "./useSketch";
37
+ import useSketchFeature from "./useSketchFeature";
39
38
 
40
39
  import { OnLayerSelectType } from ".";
41
40
 
@@ -45,35 +44,63 @@ export type SketchFeatureCallback = (
45
44
 
46
45
  type Props = {
47
46
  ref: ForwardedRef<SketchRef>;
48
- layersRef: RefObject<LayersRef>;
49
- engineRef: RefObject<EngineRef>;
47
+ layersRef: RefObject<LayersRef | null>;
48
+ engineRef: RefObject<EngineRef | null>;
50
49
  interactionMode: InteractionModeType;
51
50
  selectedFeature?: Feature;
52
51
  overrideInteractionMode?: (mode: InteractionModeType) => void;
53
52
  onSketchTypeChange?: (type: SketchType | undefined, from?: "editor" | "plugin") => void;
54
53
  onSketchFeatureCreate?: (feature: SketchFeature | null) => void;
55
54
  onSketchPluginFeatureCreate?: (props: SketchEventProps) => void;
55
+ onSketchFeatureUpdate?: (feature: SketchFeature) => void;
56
+ onSketchPluginFeatureUpdate?: (props: SketchEventProps) => void;
57
+ onSketchFeatureDelete?: (layerId: string, featureId: string) => void;
58
+ onSketchPluginFeatureDelete?: (props: { layerId: string; featureId: string }) => void;
56
59
  onLayerSelect?: OnLayerSelectType;
60
+ sketchEditingFeature?: SketchEditingFeature;
61
+ onSketchEditFeature?: (feature: SketchEditingFeature | undefined) => void;
62
+ onMount?: () => void;
57
63
  };
58
64
 
59
- const PLUGIN_LAYER_ID_LENGTH = 36;
60
-
61
65
  const sketchMachine = createSketchMachine();
62
66
 
63
- export default function useHooks({
67
+ export type sketchState = StateFrom<typeof sketchMachine>;
68
+ export type SketchInterpreter = InterpreterFrom<typeof sketchMachine>;
69
+
70
+ export default function ({
64
71
  ref,
65
72
  engineRef,
66
73
  layersRef,
74
+ interactionMode,
67
75
  selectedFeature,
68
76
  overrideInteractionMode,
69
77
  onSketchTypeChange,
70
78
  onSketchFeatureCreate,
71
79
  onSketchPluginFeatureCreate,
80
+ onSketchFeatureUpdate,
81
+ onSketchPluginFeatureUpdate,
82
+ onSketchFeatureDelete,
83
+ onSketchPluginFeatureDelete,
72
84
  onLayerSelect,
85
+ sketchEditingFeature,
86
+ onSketchEditFeature,
87
+ onMount,
73
88
  }: Props) {
74
89
  const [state, send] = useMachine(sketchMachine);
75
90
  const [type, updateType] = useState<SketchType | undefined>();
76
91
  const [from, updateFrom] = useState<"editor" | "plugin">("editor");
92
+
93
+ const setType = useCallback(
94
+ (type: SketchType | undefined, from?: "editor" | "plugin") => {
95
+ updateType(type);
96
+ updateFrom(from ?? "editor");
97
+ if (type) {
98
+ engineRef.current?.setCursor("crosshair");
99
+ }
100
+ },
101
+ [engineRef],
102
+ );
103
+
77
104
  const [disableInteraction, setDisableInteraction] = useState(false);
78
105
 
79
106
  const [sketchOptions, setSketchOptions] = useState<SketchOptions>({
@@ -81,9 +108,10 @@ export default function useHooks({
81
108
  appearance: PRESET_APPEARANCE,
82
109
  dataOnly: false,
83
110
  disableShadow: false,
84
- enableRelativeHeight: false,
85
111
  rightClickToAbort: true,
86
112
  autoResetInteractionMode: true,
113
+ // NOTE: Centroid extrude is not finalized yet
114
+ useCentroidExtrudedHeight: false,
87
115
  });
88
116
 
89
117
  const overrideOptions = useCallback((options: SketchOptions) => {
@@ -96,13 +124,16 @@ export default function useHooks({
96
124
 
97
125
  const [geometryOptions, setGeometryOptions] = useState<GeometryOptionsXYZ | null>(null);
98
126
  const [extrudedHeight, setExtrudedHeight] = useState(0);
127
+ const [extrudedPoint, setExtrudedPoint] = useState<Position3d | undefined>();
128
+
129
+ const [centroidBasePoint, setCentroidBasePoint] = useState<Position3d | undefined>();
130
+ const [centroidExtrudedPoint, setCentroidExtrudedPoint] = useState<Position3d | undefined>();
131
+
132
+ const [selectedControlPointIndex, setSelectedControlPointIndex] = useState<number | undefined>();
99
133
  const markerGeometryRef = useRef<GeometryOptionsXYZ | null>(null);
100
- const pointerLocationRef = useRef<[lng: number, lat: number, height: number]>();
134
+ const pointerLocationRef = useRef<[lng: number, lat: number, height: number]>(undefined);
101
135
 
102
- const setType = useCallback((type: SketchType | undefined, from?: "editor" | "plugin") => {
103
- updateType(type);
104
- updateFrom(from ?? "editor");
105
- }, []);
136
+ const isEditing = useMemo(() => state.matches("editing"), [state]);
106
137
 
107
138
  const createFeature = useCallback(() => {
108
139
  const geoOptions = type === "marker" ? markerGeometryRef.current : geometryOptions;
@@ -121,9 +152,26 @@ export default function useHooks({
121
152
  });
122
153
  }, [extrudedHeight, geometryOptions, markerGeometryRef, type, engineRef]);
123
154
 
155
+ const updateFeature = useCallback(() => {
156
+ if (geometryOptions == null || !selectedFeature?.id) {
157
+ return null;
158
+ }
159
+ const geometry = engineRef.current?.createGeometry(geometryOptions);
160
+ if (geometry == null) {
161
+ return null;
162
+ }
163
+ return feature(geometry, {
164
+ id: selectedFeature?.id,
165
+ type: geometryOptions?.type,
166
+ positions: geometryOptions?.controlPoints,
167
+ extrudedHeight,
168
+ });
169
+ }, [extrudedHeight, geometryOptions, selectedFeature, engineRef]);
170
+
124
171
  const updateGeometryOptions = useCallback(
125
172
  (controlPoint?: Position3d) => {
126
173
  setExtrudedHeight(0);
174
+ setExtrudedPoint(undefined);
127
175
  if (state.context.type == null || state.context.controlPoints == null) {
128
176
  setGeometryOptions(null);
129
177
  return;
@@ -139,396 +187,160 @@ export default function useHooks({
139
187
  [state, setGeometryOptions, setExtrudedHeight],
140
188
  );
141
189
 
142
- const pluginSketchLayerCreate = useCallback(
143
- (feature: SketchFeature) => {
144
- const newLayer = layersRef.current?.add({
145
- type: "simple",
146
- data: {
147
- type: "geojson",
148
- isSketchLayer: true,
149
- value: {
150
- type: "FeatureCollection",
151
- features: [{ ...feature, id: feature.properties.id }],
152
- },
153
- },
154
- ...sketchOptions.appearance,
155
- });
156
- return { layerId: newLayer?.id, featureId: feature.properties.id };
157
- },
158
- [layersRef, sketchOptions.appearance],
159
- );
190
+ const updateGeometryOptionsRef = useRef(updateGeometryOptions);
191
+ updateGeometryOptionsRef.current = updateGeometryOptions;
160
192
 
161
- const pluginSketchLayerFeatureAdd = useCallback(
162
- (layer: LazyLayer, feature: SketchFeature) => {
163
- if (layer.type !== "simple") return {};
164
- layersRef.current?.override(layer.id, {
165
- data: {
166
- ...layer.data,
167
- type: "geojson",
168
- value: {
169
- type: "FeatureCollection",
170
- features: [
171
- ...((layer.computed?.layer as LayerSimple)?.data?.value?.features ?? []),
172
- { ...feature, id: feature.properties.id },
173
- ],
174
- },
175
- },
176
- });
177
- return { layerId: layer.id, featureId: feature.properties.id };
178
- },
179
- [layersRef],
180
- );
193
+ const updateCentroidPoints = useCallback(
194
+ async (controlPoints: Position3d[]) => {
195
+ const newExtrudeBasePoint = await getCentroid(controlPoints, engineRef);
196
+ setCentroidBasePoint(newExtrudeBasePoint);
181
197
 
182
- const pluginSketchLayerFeatureRemove = useCallback(
183
- (layer: LazyLayer, featureId: string) => {
184
- if (layer.type !== "simple" || layer.computed?.layer.type !== "simple") return;
185
- layersRef.current?.override(layer.id, {
186
- data: {
187
- ...layer.data,
188
- type: "geojson",
189
- value: {
190
- type: "FeatureCollection",
191
- features: [
192
- ...(layer.computed?.layer?.data?.value?.features ?? []).filter(
193
- (feature: GeojsonFeature) => feature.id !== featureId,
194
- ),
195
- ],
196
- },
197
- },
198
- });
198
+ if (!newExtrudeBasePoint) return;
199
+ const centroidExtrudedPoint = engineRef.current?.getExtrudedPoint(
200
+ newExtrudeBasePoint,
201
+ extrudedHeight,
202
+ );
203
+ setCentroidExtrudedPoint(centroidExtrudedPoint);
199
204
  },
200
- [layersRef],
205
+ [engineRef, extrudedHeight],
201
206
  );
202
207
 
203
- const handleFeatureCreate = useCallback(
204
- (feature: SketchFeature) => {
205
- updateType(undefined);
206
- if (from === "editor") {
207
- onSketchFeatureCreate?.(feature);
208
- return;
209
- }
208
+ const {
209
+ pluginSketchLayerCreate,
210
+ pluginSketchLayerFeatureAdd,
211
+ pluginSketchLayerFeatureUpdate,
212
+ pluginSketchLayerFeatureRemove,
213
+ } = usePluginSketchLayer({
214
+ layersRef,
215
+ sketchOptions,
216
+ });
210
217
 
211
- if (!sketchOptions.dataOnly) {
212
- const selectedLayer = layersRef.current?.selectedLayer();
213
- const { layerId, featureId } =
214
- selectedLayer?.id?.length !== PLUGIN_LAYER_ID_LENGTH ||
215
- selectedLayer.type !== "simple" ||
216
- selectedLayer.computed?.layer.type !== "simple"
217
- ? pluginSketchLayerCreate(feature)
218
- : pluginSketchLayerFeatureAdd(selectedLayer, feature);
219
-
220
- if (layerId && featureId) {
221
- requestAnimationFrame(() => {
222
- onLayerSelect?.(
223
- layerId,
224
- featureId,
225
- layerId
226
- ? () =>
227
- new Promise(resolve => {
228
- // Wait until computed feature is ready
229
- queueMicrotask(() => {
230
- resolve(layersRef.current?.findById?.(layerId)?.computed);
231
- });
232
- })
233
- : undefined,
234
- undefined,
235
- undefined,
236
- );
237
- });
238
- onSketchPluginFeatureCreate?.({ layerId, featureId, feature });
239
- }
240
- } else {
241
- onSketchPluginFeatureCreate?.({ feature });
242
- }
243
- },
244
- [
245
- layersRef,
246
- from,
247
- sketchOptions.dataOnly,
248
- pluginSketchLayerCreate,
249
- pluginSketchLayerFeatureAdd,
250
- onSketchFeatureCreate,
251
- onSketchPluginFeatureCreate,
252
- onLayerSelect,
253
- ],
254
- );
218
+ const { handleFeatureCreate, handleFeatureUpdate, handleFeatureDelete } = useSketchFeature({
219
+ layersRef,
220
+ sketchOptions,
221
+ from,
222
+ updateType,
223
+ onSketchFeatureCreate,
224
+ pluginSketchLayerCreate,
225
+ pluginSketchLayerFeatureAdd,
226
+ pluginSketchLayerFeatureUpdate,
227
+ pluginSketchLayerFeatureRemove,
228
+ onSketchPluginFeatureCreate,
229
+ onSketchPluginFeatureUpdate,
230
+ onSketchPluginFeatureDelete,
231
+ onSketchFeatureUpdate,
232
+ onSketchFeatureDelete,
233
+ onLayerSelect,
234
+ });
255
235
 
256
- const handleLeftDown = useCallback(
257
- (props: MouseEventProps) => {
258
- if (
259
- disableInteraction ||
260
- !type ||
261
- props.lng === undefined ||
262
- props.lat === undefined ||
263
- props.height === undefined ||
264
- props.x === undefined ||
265
- props.y === undefined
266
- ) {
267
- return;
268
- }
269
- if (!state.matches("idle")) {
270
- return;
271
- }
272
- invariant(state.context.lastControlPoint == null);
273
- const controlPoint = engineRef.current?.toXYZ(props.lng, props.lat, props.height);
274
- if (controlPoint == null) {
275
- return;
276
- }
236
+ const editFeature = useCallback(
237
+ (feature: SketchEditingFeature | undefined) => {
238
+ onSketchEditFeature?.(feature);
277
239
 
240
+ if (!state.matches("idle") || !feature) return;
241
+
242
+ const type = feature?.feature?.properties?.type as SketchType;
278
243
  send({
279
244
  type: {
280
- marker: "MARKER" as const,
281
- polyline: "POLYLINE" as const,
282
- circle: "CIRCLE" as const,
283
- rectangle: "RECTANGLE" as const,
284
- polygon: "POLYGON" as const,
285
- extrudedCircle: "EXTRUDED_CIRCLE" as const,
286
- extrudedRectangle: "EXTRUDED_RECTANGLE" as const,
287
- extrudedPolygon: "EXTRUDED_POLYGON" as const,
245
+ marker: "EDIT_MARKER" as const,
246
+ polyline: "EDIT_POLYLINE" as const,
247
+ circle: "EDIT_CIRCLE" as const,
248
+ rectangle: "EDIT_RECTANGLE" as const,
249
+ polygon: "EDIT_POLYGON" as const,
250
+ extrudedCircle: "EDIT_EXTRUDED_CIRCLE" as const,
251
+ extrudedRectangle: "EDIT_EXTRUDED_RECTANGLE" as const,
252
+ extrudedPolygon: "EDIT_EXTRUDED_POLYGON" as const,
288
253
  }[type],
289
- pointerPosition: [props.x, props.y],
290
- controlPoint,
254
+ controlPoints: feature?.feature?.properties?.positions,
255
+ extrudedHeight: feature?.feature?.properties?.extrudedHeight,
291
256
  });
292
- setGeometryOptions(null);
293
- markerGeometryRef.current = null;
294
- },
295
- [state, disableInteraction, type, engineRef, send],
296
- );
297
-
298
- const handleMouseMove = useCallback(
299
- (props: MouseEventProps) => {
300
- if (
301
- disableInteraction ||
302
- props.lng === undefined ||
303
- props.lat === undefined ||
304
- props.height === undefined ||
305
- props.x === undefined ||
306
- props.y === undefined ||
307
- !engineRef.current
308
- ) {
309
- return;
310
- }
311
- pointerLocationRef.current = [props.lng, props.lat, props.height];
312
- if (state.matches("drawing")) {
313
- invariant(state.context.type != null);
314
- invariant(state.context.controlPoints != null);
315
- const controlPoint = engineRef.current?.toXYZ(props.lng, props.lat, props.height);
316
- if (
317
- controlPoint == null ||
318
- hasDuplicate(engineRef.current.equalsEpsilon3d, controlPoint, state.context.controlPoints)
319
- ) {
320
- return;
321
- }
322
- updateGeometryOptions(controlPoint);
323
- } else if (state.matches("extruding")) {
324
- invariant(state.context.lastControlPoint != null);
325
- const extrudedHeight = engineRef.current?.getExtrudedHeight(
326
- state.context.lastControlPoint,
327
- [props.x, props.y],
257
+ setGeometryOptions({
258
+ type,
259
+ controlPoints: feature?.feature?.properties?.positions,
260
+ });
261
+ if (feature?.feature?.properties?.extrudedHeight) {
262
+ setExtrudedHeight(feature.feature.properties.extrudedHeight);
263
+ setExtrudedPoint(
264
+ engineRef.current?.getExtrudedPoint(
265
+ feature?.feature?.properties?.positions[
266
+ feature?.feature?.properties?.positions.length - 1
267
+ ],
268
+ feature.feature.properties.extrudedHeight,
269
+ ),
328
270
  );
329
- if (extrudedHeight != null) {
330
- setExtrudedHeight(extrudedHeight);
331
- }
332
271
  }
333
272
  },
334
- [disableInteraction, state, engineRef, updateGeometryOptions, setExtrudedHeight],
273
+ [engineRef, state, onSketchEditFeature, send],
335
274
  );
336
275
 
337
- const handleLeftUp = useCallback(
338
- (props: MouseEventProps) => {
339
- if (
340
- disableInteraction ||
341
- props.lng === undefined ||
342
- props.lat === undefined ||
343
- props.height === undefined ||
344
- props.x === undefined ||
345
- props.y === undefined ||
346
- !engineRef.current
347
- ) {
348
- return;
349
- }
350
- if (
351
- state.context.controlPoints?.length === 1 &&
352
- state.context.lastPointerPosition != null &&
353
- state.context.type !== "marker" &&
354
- engineRef.current?.equalsEpsilon2d(
355
- [props.x, props.y],
356
- state.context.lastPointerPosition,
357
- 0,
358
- 5,
359
- )
360
- ) {
361
- return; // Too close to the first position user clicked.
362
- }
363
-
364
- if (state.matches("drawing")) {
365
- const controlPoint = engineRef.current?.toXYZ(props.lng, props.lat, props.height);
366
- if (controlPoint == null) return;
367
-
368
- if (state.context.type === "marker") {
369
- markerGeometryRef.current = {
370
- type: state.context.type,
371
- controlPoints: [controlPoint],
372
- };
373
- const feature = createFeature();
374
- markerGeometryRef.current = null;
375
- if (feature == null) {
376
- return;
377
- }
378
- handleFeatureCreate(feature);
379
- send({ type: "CREATE" });
380
- setGeometryOptions(null);
381
- return;
382
- }
383
- if (
384
- hasDuplicate(
385
- engineRef.current?.equalsEpsilon3d,
386
- controlPoint,
387
- state.context.controlPoints,
388
- )
389
- ) {
390
- return;
391
- }
392
- if (
393
- state.context.type === "circle" ||
394
- (state.context.type === "rectangle" && state.context.controlPoints?.length === 2)
395
- ) {
396
- const feature = createFeature();
397
- if (feature == null) {
398
- return;
399
- }
400
- handleFeatureCreate(feature);
401
- send({ type: "CREATE" });
402
- setGeometryOptions(null);
403
- return;
404
- } else {
405
- if (props.x === undefined || props.y === undefined) return;
406
- send({
407
- type: "NEXT",
408
- pointerPosition: [props.x, props.y],
409
- controlPoint,
410
- });
411
- }
412
- } else if (state.matches("extruding")) {
413
- const feature = createFeature();
414
- if (feature == null) {
415
- return;
416
- }
417
- handleFeatureCreate(feature);
418
- send({ type: "CREATE" });
419
- setGeometryOptions(null);
276
+ const cancelEdit = useCallback(
277
+ (ignoreAutoReSelect?: boolean) => {
278
+ send({ type: "EXIT_EDIT" });
279
+ updateGeometryOptions(undefined);
280
+ onSketchEditFeature?.(undefined);
281
+ if (ignoreAutoReSelect) {
282
+ ignoreAutoReSelectRef.current = true;
420
283
  }
421
284
  },
422
- [
423
- disableInteraction,
424
- state,
425
- engineRef,
426
- send,
427
- setGeometryOptions,
428
- createFeature,
429
- handleFeatureCreate,
430
- ],
285
+ [onSketchEditFeature, send, updateGeometryOptions],
431
286
  );
432
287
 
433
- const handleDoubleClick = useCallback(
434
- (props: MouseEventProps) => {
435
- if (
436
- disableInteraction ||
437
- props.lng === undefined ||
438
- props.lat === undefined ||
439
- props.height === undefined ||
440
- props.x === undefined ||
441
- props.y === undefined
442
- ) {
443
- return;
444
- }
445
- if (state.matches("drawing.extrudedPolygon")) {
446
- const controlPoint = engineRef.current?.toXYZ(props.lng, props.lat, props.height);
447
- if (controlPoint == null) return;
448
- send({
449
- type: "EXTRUDE",
450
- pointerPosition: [props.x, props.y],
451
- controlPoint,
452
- });
453
- } else if (state.matches("drawing.polyline") || state.matches("drawing.polygon")) {
454
- const feature = createFeature();
455
- if (feature == null) {
456
- return;
457
- }
458
- handleFeatureCreate(feature);
459
- send({ type: "CREATE" });
460
- setGeometryOptions(null);
288
+ const applyEdit = useCallback(() => {
289
+ if (sketchEditingFeature) {
290
+ const feature = updateFeature();
291
+ if (feature) {
292
+ handleFeatureUpdate({ ...feature, id: feature.properties.id });
461
293
  }
462
- },
463
- [disableInteraction, state, engineRef, send, handleFeatureCreate, createFeature],
464
- );
465
-
466
- const handleRightClick = useCallback(() => {
467
- if (!sketchOptions.rightClickToAbort) {
468
- return;
469
- }
470
- if (type !== undefined) {
471
- updateType(undefined);
472
294
  }
473
- if (state.matches("idle")) return;
474
- send({ type: "ABORT" });
295
+ send({ type: "EXIT_EDIT" });
475
296
  updateGeometryOptions(undefined);
476
- }, [type, state, sketchOptions.rightClickToAbort, send, updateGeometryOptions]);
477
-
478
- const mouseDownEventRef = useRef<MouseEventCallback>(handleLeftDown);
479
- mouseDownEventRef.current = handleLeftDown;
480
- const mouseMoveEventRef = useRef<MouseEventCallback>(handleMouseMove);
481
- mouseMoveEventRef.current = handleMouseMove;
482
- const mouseUpEventRef = useRef<MouseEventCallback>(handleLeftUp);
483
- mouseUpEventRef.current = handleLeftUp;
484
- const mouseDoubleClickEventRef = useRef<MouseEventCallback>(handleDoubleClick);
485
- mouseDoubleClickEventRef.current = handleDoubleClick;
486
- const mouseRightClickEventRef = useRef<() => void>(handleRightClick);
487
- mouseRightClickEventRef.current = handleRightClick;
488
-
489
- const onMouseDown = useCallback(
490
- (props: MouseEventProps) => {
491
- mouseDownEventRef.current?.(props);
492
- },
493
- [mouseDownEventRef],
494
- );
495
-
496
- const onMouseMove = useCallback(
497
- (props: MouseEventProps) => {
498
- mouseMoveEventRef.current?.(props);
499
- },
500
- [mouseMoveEventRef],
501
- );
502
-
503
- const onMouseUp = useCallback(
504
- (props: MouseEventProps) => {
505
- mouseUpEventRef.current?.(props);
506
- },
507
- [mouseUpEventRef],
508
- );
297
+ onSketchEditFeature?.(undefined);
298
+ }, [
299
+ sketchEditingFeature,
300
+ send,
301
+ updateGeometryOptions,
302
+ handleFeatureUpdate,
303
+ updateFeature,
304
+ onSketchEditFeature,
305
+ ]);
509
306
 
510
- const onMouseDoubleClick = useCallback(
511
- (props: MouseEventProps) => {
512
- mouseDoubleClickEventRef.current?.(props);
307
+ const deleteFeature = useCallback(
308
+ (layerId: string, featureId: string) => {
309
+ handleFeatureDelete(layerId, featureId);
513
310
  },
514
- [mouseDoubleClickEventRef],
311
+ [handleFeatureDelete],
515
312
  );
516
313
 
517
- const onMouseRightClick = useCallback(() => {
518
- mouseRightClickEventRef.current?.();
519
- }, [mouseRightClickEventRef]);
520
-
521
- useEffect(() => {
522
- engineRef.current?.onMouseDown(onMouseDown);
523
- engineRef.current?.onMouseMove(onMouseMove);
524
- engineRef.current?.onMouseUp(onMouseUp);
525
- engineRef.current?.onDoubleClick(onMouseDoubleClick);
526
- engineRef.current?.onRightClick(onMouseRightClick);
527
- }, [engineRef, onMouseDown, onMouseMove, onMouseUp, onMouseDoubleClick, onMouseRightClick]);
314
+ useSketch({
315
+ state,
316
+ engineRef,
317
+ disableInteraction,
318
+ type,
319
+ updateType,
320
+ sketchEditingFeature,
321
+ setSelectedControlPointIndex,
322
+ send,
323
+ setGeometryOptions,
324
+ markerGeometryRef,
325
+ pointerLocationRef,
326
+ geometryOptions,
327
+ updateGeometryOptions,
328
+ extrudedHeight,
329
+ setExtrudedHeight,
330
+ setExtrudedPoint,
331
+ updateCentroidPoints,
332
+ createFeature,
333
+ handleFeatureCreate,
334
+ applyEdit,
335
+ cancelEdit,
336
+ isEditing,
337
+ sketchOptions,
338
+ });
528
339
 
529
340
  useWindowEvent("keydown", event => {
530
341
  if (type === undefined) return;
531
342
  if (event.code === "Space") {
343
+ tempSwitchToMoveMode.current = true;
532
344
  setDisableInteraction(true);
533
345
  overrideInteractionMode?.("move");
534
346
  } else {
@@ -544,7 +356,7 @@ export default function useHooks({
544
356
  updateGeometryOptions(controlPoint);
545
357
  } else if (event.key === "Delete" && state.matches("idle") && selectedFeature?.id) {
546
358
  const selectedLayer = layersRef.current?.selectedLayer();
547
- if (selectedLayer?.id?.length === PLUGIN_LAYER_ID_LENGTH) {
359
+ if (selectedLayer && layersRef.current?.isTempLayer(selectedLayer?.id)) {
548
360
  pluginSketchLayerFeatureRemove(selectedLayer, selectedFeature.id);
549
361
  }
550
362
  }
@@ -556,31 +368,148 @@ export default function useHooks({
556
368
  if (event.code === "Space") {
557
369
  overrideInteractionMode?.("sketch");
558
370
  setDisableInteraction(false);
371
+ if (tempSwitchToMoveMode.current) {
372
+ tempSwitchToMoveMode.current = false;
373
+ }
559
374
  }
560
375
  });
561
376
 
562
377
  useEffect(() => {
563
- if (type === undefined) {
378
+ if (type === undefined && !sketchEditingFeature) {
564
379
  send({ type: "ABORT" });
565
- updateGeometryOptions(undefined);
380
+ updateGeometryOptionsRef.current?.(undefined);
566
381
  }
567
- }, [type, send, updateGeometryOptions]);
382
+ }, [type, sketchEditingFeature, send]);
383
+
384
+ const fromRef = useRef(from);
385
+ fromRef.current = from;
386
+ const overrideInteractionModeRef = useRef(overrideInteractionMode);
387
+ overrideInteractionModeRef.current = overrideInteractionMode;
388
+ const onSketchTypeChangeRef = useRef(onSketchTypeChange);
389
+ onSketchTypeChangeRef.current = onSketchTypeChange;
390
+ const interactionModeRef = useRef(interactionMode);
391
+ interactionModeRef.current = interactionMode;
568
392
 
569
393
  useEffect(() => {
570
- if (type) {
571
- overrideInteractionMode?.("sketch");
572
- } else if (sketchOptions.autoResetInteractionMode) {
573
- overrideInteractionMode?.("default");
394
+ if ((sketchEditingFeature || type) && interactionModeRef.current !== "sketch") {
395
+ overrideInteractionModeRef.current?.("sketch");
574
396
  }
397
+ }, [type, sketchEditingFeature]);
575
398
 
576
- onSketchTypeChange?.(type, from);
577
- }, [
578
- type,
579
- from,
580
- sketchOptions.autoResetInteractionMode,
581
- overrideInteractionMode,
582
- onSketchTypeChange,
583
- ]);
399
+ const isEditingRef = useRef(isEditing);
400
+ isEditingRef.current = isEditing;
401
+ const cancelEditRef = useRef(cancelEdit);
402
+ cancelEditRef.current = cancelEdit;
403
+
404
+ useEffect(() => {
405
+ onSketchTypeChangeRef.current?.(type, fromRef.current);
406
+ if (isEditingRef.current) {
407
+ cancelEditRef.current();
408
+ }
409
+ if (type === undefined) {
410
+ overrideInteractionModeRef.current?.(
411
+ interactionModeRef.current === "sketch" ? "default" : interactionModeRef.current,
412
+ );
413
+ }
414
+ }, [type]);
415
+
416
+ const typeRef = useRef(type);
417
+ typeRef.current = type;
418
+ useEffect(() => {
419
+ if (tempSwitchToMoveMode.current) return;
420
+ if (interactionMode !== "sketch") {
421
+ if (isEditingRef.current) {
422
+ cancelEditRef.current();
423
+ }
424
+ }
425
+ }, [interactionMode, updateType]);
426
+
427
+ // Edit
428
+ const onEditFeatureChangeCbs = useRef<SketchEditFeatureChangeCb[]>([]);
429
+ const onEditFeatureChange = useCallback((cb: SketchEditFeatureChangeCb) => {
430
+ onEditFeatureChangeCbs.current.push(cb);
431
+ }, []);
432
+ const onEditFeatureChangeRef = useRef(onEditFeatureChange);
433
+ onEditFeatureChangeRef.current = onEditFeatureChange;
434
+
435
+ const lastSketchEditingFeature = useRef<SketchEditingFeature | undefined>(undefined);
436
+
437
+ const catchedControlPointIndex = useMemo(
438
+ () => state.context.catchedControlPointIndex,
439
+ [state.context.catchedControlPointIndex],
440
+ );
441
+
442
+ const catchedExtrudedPoint = useMemo(
443
+ () => !!state.context.catchedExtrudedPoint,
444
+ [state.context.catchedExtrudedPoint],
445
+ );
446
+
447
+ const ignoreAutoReSelectRef = useRef(false);
448
+
449
+ useEffect(() => {
450
+ onEditFeatureChangeCbs.current.forEach(cb => {
451
+ cb(sketchEditingFeature);
452
+ });
453
+ if (sketchEditingFeature) lastSketchEditingFeature.current = sketchEditingFeature;
454
+ else {
455
+ // Select the feature after editing
456
+ if (ignoreAutoReSelectRef.current) {
457
+ ignoreAutoReSelectRef.current = false;
458
+ return;
459
+ }
460
+ layersRef.current?.selectFeatures([
461
+ {
462
+ layerId: undefined,
463
+ featureId: [],
464
+ },
465
+ ]);
466
+ setTimeout(() => {
467
+ if (lastSketchEditingFeature.current) {
468
+ layersRef.current?.selectFeatures([
469
+ {
470
+ layerId: lastSketchEditingFeature.current?.layerId,
471
+ featureId: [lastSketchEditingFeature.current?.feature.id],
472
+ },
473
+ ]);
474
+ }
475
+ lastSketchEditingFeature.current = undefined;
476
+ }, 50);
477
+ }
478
+ }, [layersRef, sketchEditingFeature, onEditFeatureChangeCbs]);
479
+
480
+ const handleControlPointMouseEvent: ControlPointMouseEventHandler = useCallback(
481
+ (index, isExtrudedPoint, eventType) => {
482
+ if (!state.matches("editing") || !state.context.controlPoints) return;
483
+
484
+ if (eventType === "mousedown") {
485
+ if (isExtrudedPoint) {
486
+ send({
487
+ type: "CATCH",
488
+ catchedControlPointIndex: -1,
489
+ controlPoints: state.context.controlPoints,
490
+ catchedExtrudedPoint: true,
491
+ });
492
+ } else {
493
+ send({
494
+ type: "CATCH",
495
+ catchedControlPointIndex: index,
496
+ controlPoints: state.context.controlPoints,
497
+ catchedExtrudedPoint: false,
498
+ });
499
+ }
500
+ } else {
501
+ if (
502
+ !isExtrudedPoint &&
503
+ (((state.context.type === "polygon" || state.context.type === "extrudedPolygon") &&
504
+ state.context.controlPoints.length > 3) ||
505
+ (state.context.type === "polyline" && state.context.controlPoints.length > 2))
506
+ ) {
507
+ setSelectedControlPointIndex(index);
508
+ }
509
+ }
510
+ },
511
+ [state, send],
512
+ );
584
513
 
585
514
  // API
586
515
  const getType = useGet(type);
@@ -593,29 +522,143 @@ export default function useHooks({
593
522
  setType,
594
523
  getOptions,
595
524
  overrideOptions,
525
+ editFeature,
526
+ cancelEdit,
527
+ applyEdit,
528
+ deleteFeature,
529
+ onEditFeatureChange: onEditFeatureChangeRef.current,
596
530
  }),
597
- [getType, setType, getOptions, overrideOptions],
531
+ [
532
+ getType,
533
+ setType,
534
+ getOptions,
535
+ overrideOptions,
536
+ editFeature,
537
+ deleteFeature,
538
+ cancelEdit,
539
+ applyEdit,
540
+ ],
598
541
  );
599
542
 
543
+ useEffect(() => {
544
+ onMount?.();
545
+ }, [onMount]);
546
+
547
+ const handleDeleteControlPoint = useCallback(() => {
548
+ if (selectedControlPointIndex !== undefined) {
549
+ const newControlPoints = state.context.controlPoints?.toSpliced(selectedControlPointIndex, 1);
550
+ if (!newControlPoints) return;
551
+ send({
552
+ type: "UPDATE",
553
+ controlPoints: newControlPoints,
554
+ });
555
+ setGeometryOptions(op =>
556
+ op
557
+ ? {
558
+ type: op.type,
559
+ controlPoints: newControlPoints,
560
+ }
561
+ : null,
562
+ );
563
+ setSelectedControlPointIndex(undefined);
564
+ }
565
+ }, [selectedControlPointIndex, state.context.controlPoints, send, setGeometryOptions]);
566
+
567
+ const handleDeleteControlPointRef = useRef(handleDeleteControlPoint);
568
+ handleDeleteControlPointRef.current = handleDeleteControlPoint;
569
+
570
+ const handleAddControlPoint = useCallback(
571
+ (controlPoint: Position3d, index: number) => {
572
+ if (state.context.controlPoints == null) return;
573
+ const insertPosition = index + 1;
574
+ const newControlPoints = state.context.controlPoints.toSpliced(
575
+ insertPosition,
576
+ 0,
577
+ controlPoint,
578
+ );
579
+ send({
580
+ type: "UPDATE",
581
+ controlPoints: newControlPoints,
582
+ });
583
+ setGeometryOptions(op =>
584
+ op
585
+ ? {
586
+ type: op.type,
587
+ controlPoints: newControlPoints,
588
+ }
589
+ : null,
590
+ );
591
+ },
592
+ [state.context.controlPoints, send, setGeometryOptions],
593
+ );
594
+
595
+ //
596
+ const tempSwitchToMoveMode = useRef(false);
597
+ const stateRef = useRef(state);
598
+ stateRef.current = state;
599
+
600
+ useEffect(() => {
601
+ return window.addEventListener("keydown", event => {
602
+ if (event.code === "Space" && stateRef.current.matches("editing")) {
603
+ tempSwitchToMoveMode.current = true;
604
+ overrideInteractionMode?.("move");
605
+ } else if (event.code === "Delete" && stateRef.current.matches("editing")) {
606
+ handleDeleteControlPointRef.current();
607
+ }
608
+ });
609
+ }, [overrideInteractionMode]);
610
+
611
+ useEffect(() => {
612
+ return window.addEventListener("keyup", event => {
613
+ if (event.code === "Space" && tempSwitchToMoveMode.current) {
614
+ overrideInteractionMode?.("sketch");
615
+ tempSwitchToMoveMode.current = false;
616
+ }
617
+ });
618
+ }, [overrideInteractionMode]);
619
+
620
+ useEffect(() => {
621
+ if (!isEditing) {
622
+ overrideInteractionModeRef.current?.("default");
623
+ }
624
+ }, [isEditing]);
625
+
600
626
  return {
601
627
  state,
628
+ isEditing,
629
+ catchedControlPointIndex,
630
+ catchedExtrudedPoint,
602
631
  extrudedHeight,
632
+ extrudedPoint,
633
+ centroidBasePoint,
634
+ centroidExtrudedPoint,
603
635
  geometryOptions,
604
636
  color: sketchOptions.color,
605
637
  disableShadow: sketchOptions.disableShadow,
606
- enableRelativeHeight: sketchOptions.enableRelativeHeight,
607
- } as any;
638
+ selectedControlPointIndex,
639
+ handleControlPointMouseEvent,
640
+ handleAddControlPoint,
641
+ };
608
642
  }
609
643
 
610
- function hasDuplicate(
611
- equalFunction: (
612
- point1: Position3d,
613
- point2: Position3d,
614
- relativeEpsilon: number | undefined,
615
- absoluteEpsilon: number | undefined,
616
- ) => boolean,
617
- controlPoint: Position3d,
618
- controlPoints?: readonly Position3d[],
619
- ): boolean {
620
- return controlPoints?.some(another => equalFunction(controlPoint, another, 0, 1e-7)) === true;
644
+ async function getCentroid(
645
+ controlPoints: readonly Position3d[],
646
+ engineRef: RefObject<EngineRef | null>,
647
+ ): Promise<Position3d | undefined> {
648
+ let totalLat = 0;
649
+ let totalLng = 0;
650
+
651
+ controlPoints.forEach(controlPoint => {
652
+ const p = engineRef.current?.toLngLatHeight(...controlPoint);
653
+ if (!p) return;
654
+ totalLng += p[0];
655
+ totalLat += p[1];
656
+ });
657
+
658
+ const centroidLat = totalLat / controlPoints.length;
659
+ const centroidLng = totalLng / controlPoints.length;
660
+ const centroidHeight =
661
+ (await engineRef.current?.sampleTerrainHeight(centroidLng, centroidLat)) ?? 0;
662
+
663
+ return engineRef.current?.toXYZ(centroidLng, centroidLat, centroidHeight);
621
664
  }