import * as Cesium from 'cesium'
|
import aggregationImg from '@/assets/images/home/useUavHome/aggregation.png'
|
|
/**
|
* 地图标注
|
* @param {*} viewer
|
* @param {*} options
|
* @returns
|
*/
|
export function useMapMarkers (viewer, options = {
|
dronePosition: {},
|
eventLoadType: 'data',
|
eventPositions: [],
|
eventApi: null,
|
eventApiParams: {}
|
}) {
|
const { dronePosition, eventLoadType, eventPositions, eventApi, eventApiParams } = options
|
|
const initDroneEntity = () => {
|
const featuresList = item.gJson.features.map(item1 => {
|
// const {lng,lat} = getCenterPoint(item1.geometry.coordinates[0][0])
|
return {
|
name: item1.properties.name,
|
position: item1.properties.centroid,
|
data: item1.data,
|
id: item1.region_code,
|
}
|
})
|
// 遍历特征并添加实体
|
featuresList.forEach((feature, index) => {
|
if (!feature.position) return
|
const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1], 0)
|
viewer.entities.add({
|
position: position,
|
id: `aggregation-name-${index}`,
|
label: {
|
text: feature.name,
|
font: '14pt Source Han Sans CN',
|
fillColor: Cesium.Color.WHITE,
|
outlineColor: Cesium.Color.BLACK,
|
outlineWidth: 2,
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
pixelOffset: new Cesium.Cartesian2(0, -9),
|
},
|
})
|
viewer.entities.add({
|
id: `aggregation-count-${index}`,
|
position: position,
|
label: {
|
text: (feature.data.total_device_count || 0).toString(),
|
font: '12pt Source Han Sans CN',
|
fillColor: Cesium.Color.BLACK,
|
outlineColor: Cesium.Color.BLACK,
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
eyeOffset: new Cesium.Cartesian3(0, 0, -10), // 让label "浮" 在广告牌前面
|
},
|
billboard: {
|
image: new Cesium.ConstantProperty(aggregationImg),
|
width: 35,
|
height: 35,
|
},
|
properties: {
|
id: feature.id,
|
customData: {
|
data: feature.data,
|
},
|
},
|
})
|
})
|
}
|
|
const initDroneEventEntity = () => {
|
// 遍历特征并添加实体
|
eventPositions.forEach((feature, index) => {
|
if (!feature.position) return
|
const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1], 0)
|
viewer.entities.add({
|
position: position,
|
id: `aggregation-name-${index}`,
|
label: {
|
text: feature.name,
|
font: '14pt Source Han Sans CN',
|
fillColor: Cesium.Color.WHITE,
|
outlineColor: Cesium.Color.BLACK,
|
outlineWidth: 2,
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
pixelOffset: new Cesium.Cartesian2(0, -9),
|
},
|
})
|
viewer.entities.add({
|
id: `aggregation-count-${index}`,
|
position: position,
|
label: {
|
text: (feature.data.total_device_count || 0).toString(),
|
font: '12pt Source Han Sans CN',
|
fillColor: Cesium.Color.BLACK,
|
outlineColor: Cesium.Color.BLACK,
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
eyeOffset: new Cesium.Cartesian3(0, 0, -10), // 让label "浮" 在广告牌前面
|
},
|
billboard: {
|
image: new Cesium.ConstantProperty(aggregationImg),
|
width: 35,
|
height: 35,
|
},
|
properties: {
|
id: feature.id,
|
customData: {
|
data: feature.data,
|
},
|
},
|
})
|
})
|
}
|
|
const initEventApiEntity = () => {
|
eventApi(eventApiParams).then(res => {
|
console.log(res)
|
})
|
}
|
|
// 移除 点 和 gjson 实体
|
const removeEntities = () => {
|
// entities移除
|
const entitiesIDs = viewer.entities.values.map(i => i.id)
|
entitiesIDs.forEach(item => {
|
item.includes('aggregation-') && viewer.entities.removeById(item)
|
})
|
}
|
|
const initLayer = () => {
|
initDroneEntity()
|
|
eventLoadType === 'data' ? initDroneEventEntity() : initEventApiEntity()
|
}
|
|
const removeLayer = () => {
|
removeEntities()
|
}
|
|
return {
|
initLayer,
|
removeLayer
|
}
|
}
|