xieb
2023-11-21 5f35a4891178ece4fc611ecb515610841abe0f43
src/hooks/use-cesium-tsa.ts
@@ -146,12 +146,12 @@
    }
  }
  function removeAllDataSource() {
    viewer.dataSources.removeAll()
  function removeAllDataSource () {
    viewer?.dataSources.removeAll()
  }
  // 清除所有标记点
  function removeAllPoint() {
  function removeAllPoint () {
    if (viewer) {
      viewer?.entities?.removeAll()
    }
@@ -185,15 +185,23 @@
    })
  }
  let leftClickHandler: Cesium.ScreenSpaceEventHandler
  // 添加点击事件
  const addClickEvent = (sid: string, cb: Function) => {
    const handler = new Cesium.ScreenSpaceEventHandler(viewer?.scene.canvas)
    handler.setInputAction(function (click: { position: Cesium.Cartesian2 }) {
    if (leftClickHandler) {
      removeClickEvent()
    }
    leftClickHandler = new Cesium.ScreenSpaceEventHandler(viewer?.scene.canvas)
    leftClickHandler.setInputAction(function (click: { position: Cesium.Cartesian2 }) {
      const pick = viewer?.scene.pick(click.position)
      if (pick && pick.id._id === sid) {
        cb(click, pick, viewer)
        cb(click, pick, viewer, handler)
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
  }
  // 移除事件
  const removeClickEvent = () => {
    leftClickHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
  }
  // 添加线段
@@ -290,8 +298,8 @@
  // 加载json文件
  const loadGeoJson = (url: string) => {
    const option = {
      stroke: Cesium.Color.HOTPINK,
      fill: Cesium.Color.PINK,
      stroke: Cesium.Color.HOTPINK.withAlpha(0.5),
      fill: Cesium.Color.PINK.withAlpha(0.3),
      strokeWidth: 3,
    }
    const promise = Cesium.GeoJsonDataSource.load(url, option)
@@ -348,6 +356,7 @@
    addEllipse,
    loadGeoJson,
    removeAllDataSource,
    addClickEvent
    addClickEvent,
    removeClickEvent
  }
}