| | |
| | | let viewer = null |
| | | let active = null |
| | | let handler = null |
| | | let positionC3 = null |
| | | let currentEntity = null |
| | | |
| | | const store = useStore() |
| | |
| | | entity.polygon.outline = false // 显示边框 |
| | | } |
| | | |
| | | let curEntity = viewer.entities.add({ |
| | | viewer.entities.add({ |
| | | id: `aggregation-outline-${index}`, |
| | | polyline: { |
| | | positions: positions, |
| | |
| | | }, |
| | | |
| | | polygon |
| | | }) |
| | | |
| | | item.name == '县' && viewer.flyTo(curEntity, { |
| | | offset: new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-60), 0), |
| | | duration: 0.5, |
| | | }) |
| | | }) |
| | | }) |
| | |
| | | // 遍历特征并添加实体 |
| | | featuresList.forEach((feature, index) => { |
| | | if (!feature.position) return |
| | | const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1], 12000) |
| | | const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1], 0) |
| | | viewer.entities.add({ |
| | | position: position, |
| | | id: `aggregation-name-${index}`, |
| | |
| | | |
| | | // 弹框位置刷新 |
| | | const labelBoxRender = () => { |
| | | if (!currentEntity) return |
| | | let dom = document.querySelector('#mapPopUpBox') |
| | | if (!dom) { |
| | | dom = getLabelDom(currentEntity.properties.customData._value.data) |
| | | } |
| | | const screenPosition = viewer.scene.cartesianToCanvasCoordinates(positionC3) |
| | | const screenPosition = viewer.scene.cartesianToCanvasCoordinates(currentEntity?.position?._value) |
| | | if (screenPosition) { |
| | | dom.style.left = `${screenPosition.x}px` |
| | | dom.style.top = `${screenPosition.y}px` |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据条件获取项 |
| | | * @param {Array} arr 数据源 |
| | | * @param {Function} condition 条件 |
| | | * @returns |
| | | */ |
| | | const findTypeItem = (arr, condition) => { |
| | | return arr.find(item => condition(item)) |
| | | } |
| | | |
| | | // 左键单机事件 |
| | | const singleMachineEvent = async click => { |
| | | const pickedObject = viewer.scene.pick(click.position) |
| | | if (!(Cesium.defined(pickedObject) && pickedObject.id)) return |
| | | const entity = pickedObject.id |
| | | currentEntity = entity |
| | | const entityPosition = entity?.position?._value |
| | | if (!entityPosition) return |
| | | if (entityPosition) { |
| | | positionC3 = entityPosition |
| | | } |
| | | let clickTargets = viewer.scene.drillPick(click.position).map(item => item.id) |
| | | if (!clickTargets.length) return |
| | | |
| | | let deviceAggregationFind = findTypeItem(clickTargets, (item) => item?.properties?.customData?._value?.data?.type === 'deviceAggregation') |
| | | let deviceFind = findTypeItem(clickTargets, (item) => item?.properties?.customData?._value?.data?.type === 'device') |
| | | let eventFind = findTypeItem(clickTargets, (item) => item?.properties?.customData?._value?.data?.type === 'event') |
| | | currentEntity = deviceAggregationFind || deviceFind || eventFind |
| | | if (!currentEntity) return |
| | | if (!currentEntity?.position?._value) return |
| | | // 一定要移除 |
| | | removeLabel() |
| | | const customData = entity?.properties?.customData?._value?.data |
| | | if (!customData) return |
| | | console.log('customData', customData) |
| | | switch (customData.type) { |
| | | case 'deviceAggregation': |
| | | viewer.scene.postRender.addEventListener(labelBoxRender) |
| | | break |
| | | // todo 待对接 |
| | | case 'device': |
| | | store.commit('setSingleUavHome', { id: '123' }) |
| | | break |
| | | case 'eventAggregation': |
| | | break |
| | | case 'event': |
| | | viewer.scene.postRender.addEventListener(labelBoxRender) |
| | | break |
| | | default: |
| | | break |
| | | if (deviceAggregationFind || eventFind) { |
| | | viewer.scene.postRender.addEventListener(labelBoxRender) |
| | | } |
| | | if (deviceFind) { |
| | | store.commit('setSingleUavHome', { id: '123' }) |
| | | } |
| | | } |
| | | |
| | |
| | | viewer = null |
| | | active = null |
| | | handler = null |
| | | positionC3 = null |
| | | currentEntity = null |
| | | } |
| | | const init = () => { |