| | |
| | | let viewer = null |
| | | let active = null |
| | | let handler = null |
| | | let positionC3 = null |
| | | let currentEntity = null |
| | | |
| | | const store = useStore() |
| | |
| | | |
| | | // 弹框位置刷新 |
| | | 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 |
| | | * @returns |
| | | */ |
| | | const findTypeItem = (arr, condition) => { |
| | | return arr.find(item => condition(item)) |
| | |
| | | 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') |
| | | |
| | | const curEntity = deviceAggregationFind || deviceFind || eventFind |
| | | |
| | | if (!curEntity) return |
| | | |
| | | currentEntity = curEntity |
| | | const entityPosition = curEntity?.position?._value |
| | | if (!entityPosition) return |
| | | if (entityPosition) { |
| | | positionC3 = entityPosition |
| | | } |
| | | |
| | | 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() |
| | | if (deviceAggregationFind || eventFind) { |
| | | viewer.scene.postRender.addEventListener(labelBoxRender) |
| | | } |
| | |
| | | viewer = null |
| | | active = null |
| | | handler = null |
| | | positionC3 = null |
| | | currentEntity = null |
| | | } |
| | | const init = () => { |