@reearth/core 0.0.7-alpha.2 → 0.0.7-alpha.21

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