import { useMyStore } from '../store'
|
import * as Cesium from 'cesium'
|
// 绘制项目所有中心点
|
export function pointCenter (viewer: any, longitudeList: any) {
|
// 删除地图中所有标识点
|
viewer.entities.removeAll()
|
if (longitudeList.length === 0) return
|
longitudeList.forEach((item: { id: string, longitude: number; latitude: number, label: string }) => {
|
addPoint(viewer, item.id, item.longitude, item.latitude, item.label)
|
})
|
}
|
// 绘制点
|
export function addPoint (viewer: any, id: string, longitude: number, latitude: number) {
|
const entity = viewer.entities.add({
|
position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
|
id,
|
// label: {
|
// text: label,
|
// heightReference: 80,
|
// pixelOffset: new Cesium.Cartesian2(0, -25),
|
// font: '40px'
|
// },
|
point: {
|
pixelSize: 24,
|
color: Cesium.Color.GREEN,
|
outlineColor: Cesium.Color.WHITE,
|
outlineWidth: 2,
|
}
|
})
|
// const label = virw
|
}
|
|
// 点击当前点的事件
|
export function clickPoint (viewer: any, longitudeList: any) {
|
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
|
handler.setInputAction(function (click: any) {
|
const pickedObject = viewer.scene.pick(click.position)
|
if (Cesium.defined(pickedObject)) {
|
const list = longitudeList.filter((v: { id: string, longitude: number; latitude: number; }) => v.id === pickedObject.id.id)
|
if (pickedObject.id.label) {
|
pickedObject.id.label = null
|
} else {
|
pickedObject.id.label = {
|
text: list[0].label,
|
pixelOffset: new Cesium.Cartesian2(0, -25),
|
font: '40px'
|
}
|
}
|
|
// const point = pickedObject.id.point
|
//
|
}
|
}
|
, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
// handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
}
|
|
// 飞到项目中心点
|
export function flyTo (viewer: any, longitude: number, latitude: number, height: number = 5000) {
|
const targetPosition = { longitude, latitude, height }
|
viewer.camera.flyTo({
|
destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height),
|
duration: 2
|
})
|
}
|
|
// 通过经纬度判断当前地图上是否有实体
|
export function isEntityExist (viewer: any, longitude: number, latitude: number) {
|
const position = Cesium.Cartesian3.fromDegrees(longitude, latitude)
|
const pickedObject = viewer.scene.pick(position)
|
console.log(pickedObject, 'pickedObject')
|
if (Cesium.defined(pickedObject)) {
|
return true
|
} else {
|
return false
|
}
|
}
|
// 清除地图上的点
|
export function clearAllPoint (viewer:any) {
|
// 获取Cesium场景对象
|
const scene = viewer.scene
|
|
// 获取场景中的所有图元
|
const primitives = scene.primitives
|
|
// 遍历图元数组
|
primitives.forEach(function (primitive: any) {
|
// 判断图元是否为点集合
|
if (primitive instanceof Cesium.PointPrimitiveCollection) {
|
// 移除所有点
|
primitive.removeAll()
|
}
|
})
|
}
|