| | |
| | | } |
| | | } |
| | | |
| | | function removeAllDataSource() { |
| | | viewer.dataSources.removeAll() |
| | | function removeAllDataSource () { |
| | | viewer?.dataSources.removeAll() |
| | | } |
| | | |
| | | // 清除所有标记点 |
| | | function removeAllPoint() { |
| | | function removeAllPoint () { |
| | | if (viewer) { |
| | | viewer?.entities?.removeAll() |
| | | } |
| | |
| | | }) |
| | | } |
| | | |
| | | 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) |
| | | } |
| | | |
| | | // 添加线段 |
| | |
| | | // 加载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) |
| | |
| | | addEllipse, |
| | | loadGeoJson, |
| | | removeAllDataSource, |
| | | addClickEvent |
| | | addClickEvent, |
| | | removeClickEvent |
| | | } |
| | | } |