2023-06-09 18:50:47 +08:00
|
|
|
<template>
|
2023-06-14 20:05:12 +08:00
|
|
|
<div ref="mapPopupRef" class="popover">
|
2023-06-09 18:50:47 +08:00
|
|
|
这是弹窗
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
import Overlay from 'ol/Overlay'
|
|
|
|
|
import MarkerImg from './markerImage'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
props: {
|
|
|
|
|
list: {
|
|
|
|
|
type: Array,
|
|
|
|
|
required: true
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-06-14 20:05:12 +08:00
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
currStationInfo: {}
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-06-09 18:50:47 +08:00
|
|
|
mounted() {
|
|
|
|
|
this.map = this.$parent.getMapInstance()
|
|
|
|
|
this.initMapClick()
|
|
|
|
|
this.initMapPopup()
|
2023-06-14 20:05:12 +08:00
|
|
|
this.initMarkers()
|
2023-06-09 18:50:47 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
// 初始化marker
|
|
|
|
|
initMarkers() {
|
2023-06-14 20:05:12 +08:00
|
|
|
this.list.forEach(eventItem => {
|
|
|
|
|
this.map.addOverlay(this.getMarker(eventItem))
|
2023-06-09 18:50:47 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 初始化地图点击事件
|
|
|
|
|
initMapClick() {
|
2023-06-14 20:05:12 +08:00
|
|
|
this.map.on('click', () => {
|
|
|
|
|
this.closeMapPopup()
|
2023-06-09 18:50:47 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 初始化地图弹窗
|
|
|
|
|
initMapPopup() {
|
|
|
|
|
this.popupOverlay = new Overlay({
|
|
|
|
|
element: this.$refs.mapPopupRef,
|
|
|
|
|
autoPan: true,
|
|
|
|
|
autoPanAnimation: {
|
|
|
|
|
duration: 250
|
2023-06-14 20:05:12 +08:00
|
|
|
},
|
|
|
|
|
positioning: 'bottom-center'
|
2023-06-09 18:50:47 +08:00
|
|
|
})
|
|
|
|
|
this.map.addOverlay(this.popupOverlay)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 显示地图弹窗
|
|
|
|
|
showMapPopup(stationInfo) {
|
|
|
|
|
this.popupOverlay.setPosition([stationInfo.lon, stationInfo.lat])
|
2023-06-14 20:05:12 +08:00
|
|
|
this.currStationInfo = stationInfo // 填充基本信息
|
2023-06-09 18:50:47 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//关闭地图弹窗
|
|
|
|
|
closeMapPopup() {
|
|
|
|
|
this.popupOverlay.setPosition(null)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取marker图标
|
|
|
|
|
getMarker(stationInfo) {
|
|
|
|
|
const { lon, lat } = stationInfo
|
2023-06-14 20:05:12 +08:00
|
|
|
const img = document.createElement('img')
|
|
|
|
|
img.src =
|
|
|
|
|
MarkerImg[
|
|
|
|
|
['Car', 'GroudMonitoringStation', 'ImsRnStation', 'NuclearFacility', 'Ship'][parseInt(Math.random() * 5)]
|
|
|
|
|
]
|
|
|
|
|
img.style.width = '30px'
|
|
|
|
|
img.style.height = '30px'
|
|
|
|
|
img.style.cursor = 'pointer'
|
|
|
|
|
img.addEventListener('click', () => {
|
|
|
|
|
this.showMapPopup(stationInfo)
|
2023-06-09 18:50:47 +08:00
|
|
|
})
|
2023-06-14 20:05:12 +08:00
|
|
|
return new Overlay({
|
|
|
|
|
position: [lon, lat],
|
|
|
|
|
element: img,
|
|
|
|
|
id: stationInfo.stationId,
|
|
|
|
|
positioning: 'top-center'
|
2023-06-09 18:50:47 +08:00
|
|
|
})
|
|
|
|
|
},
|
2023-06-14 20:05:12 +08:00
|
|
|
|
|
|
|
|
// 设置marker位置
|
|
|
|
|
setMarkerPosition(markerId, position) {
|
|
|
|
|
const overlay = this.map.getOverlayById(markerId)
|
|
|
|
|
overlay.setPosition(position)
|
2023-06-09 18:50:47 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2023-06-14 20:05:12 +08:00
|
|
|
<style lang="less" scoped>
|
|
|
|
|
.popover {
|
|
|
|
|
width: 200px;
|
|
|
|
|
height: 300px;
|
|
|
|
|
background-color: rgba(2, 26, 29, 0.9);
|
|
|
|
|
box-shadow: 0 0 5px rgba(2, 26, 29, 0.9);
|
|
|
|
|
}
|
|
|
|
|
</style>
|