| | |
| | | // 定义全局的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 |
| | | // 天地图地图 |
| | | const TDT_IMG_C = 'https://{s}.tianditu.gov.cn/img_c/wmts?service=wmts&request=GetTile&version=1.0.0' + |
| | | '&LAYER=img&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}' + |
| | | '&style=default&format=tiles&tk=' + TDT_Token |
| | | '&LAYER=img&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}' + |
| | | '&style=default&format=tiles&tk=' + TDT_Token |
| | | // 天地图注记 |
| | | const TDT_ZJ = 'https://{s}.tianditu.gov.cn/cia_c/wmts?service=wmts&request=GetTile&version=1.0.0' + |
| | | '&LAYER=cia&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}' + |
| | | '&style=default&format=tiles&tk=' + TDT_Token |
| | | '&LAYER=cia&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}' + |
| | | '&style=default&format=tiles&tk=' + TDT_Token |
| | | // 标准地图注记 |
| | | const TID_STAND = 'https://{s}.tianditu.gov.cn/vec_w/wmts?service=wmts&request=GetTile&version=1.0.0' + |
| | | '&LAYER=img&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}' + |
| | |
| | | } |
| | | |
| | | // 清除所有标记点 |
| | | function removeAllPoint () { |
| | | function removeAllPoint() { |
| | | if (viewer) { |
| | | viewer?.entities?.removeAll() |
| | | } |
| | |
| | | } |
| | | |
| | | // 通过点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) |
| | |
| | | } |
| | | } |
| | | // 飞行 flyto |
| | | const flyTo = (pointOption: pointOption, time: number = 4, height:number = 3000) => { |
| | | const flyTo = (pointOption: pointOption, time: number = 4, height: number = 3000) => { |
| | | if (!pointOption.longitude && !pointOption.latitude) return |
| | | const destination = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude, height) |
| | | const duration = time |
| | |
| | | } |
| | | |
| | | // 地图放大 |
| | | const zoonIn = (range:number) => { |
| | | const zoonIn = (range: number) => { |
| | | // 获取当前视角的高度 |
| | | const cameraHeight = viewer?.camera.positionCartographic.height |
| | | const amout = Cesium.Math.sign(range) * cameraHeight / Math.log(cameraHeight) |
| | | viewer?.camera.zoomIn(amout) |
| | | } |
| | | // 地图缩小 |
| | | const zoonOut = (range:number) => { |
| | | const zoonOut = (range: number) => { |
| | | const cameraHeight = viewer?.camera.positionCartographic.height |
| | | const amout = Cesium.Math.sign(range) * cameraHeight / Math.log(cameraHeight) |
| | | viewer?.camera.zoomOut(amout) |
| | | } |
| | | // 生成或删除路网图层 |
| | | const roadPattern = (flag:boolean) => { |
| | | const roadPattern = (flag: boolean) => { |
| | | if (store.state.common.mapSetting.mode === 0) return |
| | | const imageryLayers = viewer?.scene.imageryLayers |
| | | const tdtZwImg_c = imageryLayers?._layers.find(v => v.imageryProvider._layer === 'tdtZwImg_c') |
| | |
| | | getEntityById, |
| | | updateEntityPosition, |
| | | addPolyline, |
| | | addEllipse, |
| | | loadGeoJson, |
| | | removeAllDataSource |
| | | addPolyline, |
| | | addEllipse |
| | | } |
| | | } |