| | |
| | | // 定义全局的viewer变量防止重复生成 |
| | | // eslint-disable-next-line no-var |
| | | var viewer: Cesium.Viewer | null = null |
| | | export function cesiumOperation() { |
| | | export function cesiumOperation () { |
| | | let handler: Cesium.ScreenSpaceEventHandler |
| | | const TDT_Token = 'c6eea7dad4fa1e2d1e32ec0e7c9735db' |
| | | // 天地图Key |
| | |
| | | } |
| | | }) |
| | | } |
| | | |
| | | let leftClickHandler: Cesium.ScreenSpaceEventHandler |
| | | // 添加点击事件 |
| | | let leftClickHandler: Cesium.ScreenSpaceEventHandler |
| | | const addClickEvent = (sid: string, cb: Function) => { |
| | | 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) { |
| | | if (pick && (pick.id._id === sid || pick.id._id.includes(sid))) { |
| | | cb(click, pick, viewer, handler) |
| | | } |
| | | }, Cesium.ScreenSpaceEventType.LEFT_CLICK) |
| | |
| | | } |
| | | |
| | | // 通过点ID删除 |
| | | function removeById(id: string) { |
| | | function removeById (id: string) { |
| | | viewer?.entities.removeById(id) |
| | | const pointEntity = viewer?.entities.getById(id) |
| | | if (pointEntity && pointEntity !== undefined) { |
| | |
| | | } |
| | | } |
| | | // 通过点ID获取实体 |
| | | function getEntityById(id: string) { |
| | | function getEntityById (id: string) { |
| | | const pointEntity = viewer?.entities.getById(id) |
| | | return pointEntity |
| | | } |
| | | // 更新图片实体位置 |
| | | function updateEntityPosition(longitude: number, latitude: number, id: string, params?: any) { |
| | | function updateEntityPosition (longitude: number, latitude: number, id: string, params?: any) { |
| | | const entity = getEntityById(id) as Cesium.Entity |
| | | const position = Cesium.Cartesian3.fromDegrees(longitude, latitude) |
| | | const heading = Cesium.Math.toRadians(-params.heading) |