弹框盒子
<template>
<div id="popup" class="ol-popup">
<div class="pophead">
<!-- position: absolute;top: 5px;left: 8px; -->
<div id="popup-title" class="popup-title"></div>
<p id="popup-closer" class="ol-popup-closer" style="color:#8e908c;">
<img src="../../assets/img/image/ic_guanbi.png" alt srcset />
</p>
</div>
<div class="popup-info" id="popup-info"></div>
<div id="popup-content" style="padding: 10px"></div>
</div>
</template>
弹框样式
<style lang="scss" scoped>
/*设置弹出框样式*/
.ol-popup {
position: absolute;
background-color: rgba(249, 252, 255, 0.95);
-webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
// padding: 15px;
// border-radius: 10px;
border: 1px solid #cccccc;
bottom: 12px;
left: -50px;
min-width: 280px;
.pophead {
display: flex;
background: url('../../assets/img/image/bg_title_tucengkongzhi.png')
no-repeat;
// background-size: 601px 43px;
width: 100%;
height: 43px;
line-height: 43px;
justify-content: space-between;
.popup-title {
font: bold 15px sans-serif;
color: #000000;
display: flex;
justify-content: space-between;
width: 90%;
height: 43px;
line-height: 43px;
padding-left: 38px;
p {
width: 43px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
}
.popup-info {
display: flex;
align-items: center;
}
.ol-popup:after,
.ol-popup:before {
top: 100%;
border: solid transparent;
content: ' ';
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.ol-popup:after {
border-top-color: #eeeeee;
border-width: 10px;
left: 48px;
margin-left: -10px;
}
.ol-popup:before {
border-top-color: #cccccc;
border-width: 11px;
left: 48px;
margin-left: -11px;
}
.ol-popup-closer {
width: 10%;
text-align: right;
text-decoration: none;
cursor: pointer;
font-style: normal;
img {
width: 20px;
height: 20px;
vertical-align: middle;
margin-right: 5px;
}
}
// .ol-popup-closer:after {
// content: "✖";
// }
</style>
鼠标点击显示弹框内容
<script>
mapOnclick() {
let _this = this
//拿到弹出框元素
var container = document.getElementById("popup");
//拿到弹出框内容元素
var content = document.getElementById("popup-content");
var contentTitle = document.getElementById("popup-title");
var contentInfo = document.getElementById("popup-info");
//拿到弹出框关闭元素
var popupCloser = document.getElementById("popup-closer");
//创建弹出框容器
var overlay1 = new Overlay({
//设置弹出框的容器
element: container,
//是否自动平移,即假如标记在屏幕边缘,弹出时自动平移地图使弹出框完全可见
autoPan: true,
autoPanAnimation: {
duration: 250
//当Popup超出地图边界时,为了Popup全部可见,地图移动的速度.
}
});
_this.map.on('click', (e) => {
var pixel = _this.map.getEventPixel(e.originalEvent);
_this.map.forEachFeatureAtPixel(pixel, function (feature) {
var attr = feature.getProperties().properties;
if(feature && attr){
if(attr.valueName === 'shuiku1' || attr.valueName === 'shuiku2'){
const params = {
geoId: attr.id
}
let info = '信息介绍'
getMapRsrDetail(params).then(res => {
if (res.code === 1) {
tMessager.$emit('reservoir', res)
let title = `
<p style="font-size: 18px;color: #FFFFFF;">${res.data.rsnm ? res.data.rsnm : ''}</p>
<p>${res.data.address ? res.data.address : ''}</p>
`
let contentInfos = `
<img src="${infoImg}" alt="" srcset="" style=" margin: 0 5px 0 30px;width: 20px;height: 20px;">
<p style="height: 40px;line-height: 40px;font-size: 16px;font-family: PingFangSC-Medium, PingFang SC;font-weight: 500;color: #333333;">${info}</p>
`
let contentData = `
<div style="display: flex;justify-content: space-between;height: 176px;width: 100%;">
<p style="height: 100%;overflow-y: auto;width: 336px;line-height: 30px;text-indent: 25px;">${res.data.rsov ? res.data.rsov : ''}</p>
<img src="${res.data.previewUrl ? res.data.previewUrl : ''}" style="width:244px;height:176px">
</div>
<div style="display: flex;flex-wrap: wrap;margin-top: 14px;">
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:336px;line-height:30px;color: #666666;">中文名</p>
<p style="width:224px;line-height:30px;color: #000000;">${res.data.rsnm ? res.data.rsnm : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:336px;line-height:30px;color: #666666;">总库容</p>
<p style="width:224px;line-height:30px;color: #000000;">${res.data.ttstcp ? res.data.ttstcp : ''}亿m3</p>
</div>
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:336px;line-height:30px;color: #666666;">主坝坝型</p>
<p style="width:224px;line-height:30px;color: #000000;">${res.data.dmtpNm ? res.data.dmtpNm : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:336px;line-height:30px;color: #666666;">主坝最大坝高</p>
<p style="width:224px;line-height:30px;color: #000000;">${res.data.maxdmhg ? res.data.maxdmhg : ''}m</p>
</div>
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:336px;line-height:30px;color: #666666;">行政区划类型</p>
<p style="width:224px;line-height:30px;color: #000000;">${res.data.rsnm ? res.data.rsnm : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:336px;line-height:30px;color: #666666;">工程规模</p>
<p style="width:224px;line-height:30px;color: #000000;">${res.data.prscNm ? res.data.prscNm : ''}</p>
</div>
</div>
`
var coodinate = e.coordinate;
contentTitle.innerHTML = title
contentInfo.innerHTML = contentInfos
contentInfo.style = "display:flex"
content.innerHTML = contentData
overlay1.setPosition(coodinate);
_this.map.addOverlay(overlay1);
}
})
}
if (attr.valueName === 'shuizha') {
const params = {
geoId: attr.id
}
getMapSluDetail(params).then(res => {
tMessager.$emit('reservoir', res)
let title = `
<p style="font-size: 18px;color: #FFFFFF;">${res.data.slnm ? res.data.slnm : ''}</p>
<p>${res.data.address ? res.data.address : ''}</p>
`
let contentData = `
<div style="display: flex;">
<div style="width: 253px;height: 190px;margin-right: 10px;">
<img src="${res.data.previewUrl ? res.data.previewUrl : ''}" style="width:100%;height:100%">
</div>
<div style="display: flex;flex-wrap: wrap;flex:1">
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="水闸名称">水闸名称</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.slnm ? res.data.slnm : ''}">${res.data.slnm ? res.data.slnm : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="行政区划">行政区划</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.countyNm ? res.data.countyNm : ''}">${res.data.countyNm ? res.data.countyNm : ''}</p>
</div>
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="所在河流(蓄滞洪区)名称">所在河流(蓄滞洪区)名称</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.rvrnm ? res.data.rvrnm : ''}">${res.data.rvrnm ? res.data.rvrnm : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="水闸类型">水闸类型</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.sltpNm ? res.data.sltpNm : ''}">${res.data.sltpNm ? res.data.sltpNm : ''}</p>
</div>
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="过闸流量(m3/s)">过闸流量(m3/s)</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.dslcfl ? res.data.dslcfl : ''}">${res.data.dslcfl ? res.data.dslcfl : ''}m3/s</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="管理单位">管理单位</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.mnun ? res.data.mnun : ''}">${res.data.mnun ? res.data.mnun : ''}</p>
</div>
</div>
</div>
`
var coodinate = e.coordinate;
contentTitle.innerHTML = title
contentInfo.style = "display:none"
content.innerHTML = contentData
overlay1.setPosition(coodinate);
_this.map.addOverlay(overlay1);
})
}
if (attr.valueName === 'difang') {
const params = {
geoId: attr.id
}
getMapLevDetail(params).then(res => {
let title = `
<p style="font-size: 18px;color: #FFFFFF;">${res.data.lvnm ? res.data.lvnm : ''}</p>
`
let contentData = `
<div style="display: flex;">
<div style="width: 253px;height: 190px;margin-right: 10px;">
<img src="${res.data.previewUrl ? res.data.previewUrl : ''}" style="width:100%;height:100%">
</div>
<div style="display: flex;flex-wrap: wrap;flex:1">
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="堤防名称">堤防名称</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.lvnm ? res.data.lvnm : ''}">${res.data.lvnm ? res.data.lvnm : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="堤防长度(m)">堤防长度(m)</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.lvlen ? res.data.lvlen : ''}">${res.data.lvlen ? res.data.lvlen : ''}m</p>
</div>
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="起点">起点</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.startAddress ? res.data.startAddress : ''}">${res.data.startAddress ? res.data.startAddress : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="终点">终点</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.endAddress ? res.data.endAddress : ''}">${res.data.endAddress ? res.data.endAddress : ''}</p>
</div>
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="起点桩号">起点桩号</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.lvinch ? res.data.lvinch : ''}">${res.data.lvinch ? res.data.lvinch : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #666666;" title="终点桩号">终点桩号</p>
<p style="width:280px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;line-height:30px;color: #000000;" title="${res.data.lvtrch ? res.data.lvtrch : ''}">${res.data.lvtrch ? res.data.lvtrch : ''}</p>
</div>
</div>
</div>
`
var coodinate = e.coordinate;
contentTitle.innerHTML = title
content.innerHTML = contentData
contentInfo.style = "display:none"
overlay1.setPosition(coodinate);
_this.map.addOverlay(overlay1);
})
}
if (attr.valueName === 'xingbian') {
console.log(attr);
const params = {
stcd: attr.stcd
}
_this.getTotalInfoData(params, e, contentTitle, content, overlay1, attr, '', contentInfo)
}
if (attr.valueName === 'shenya') {
let info = '监测信息'
pressureList().then(res => {
if (res.code === 1) {
let dataJson = JSON.parse(res.data[0].jsonData)
const colors = ['#5470C6', '#91CC75', '#EE6666'];
let contentInfos = `
<img src="${infoImg}" alt="" srcset="" style=" margin: 0 5px 0 20px;width: 20px;height: 20px;">
<p style="height: 40px;line-height: 40px;font-size: 16px;font-family: PingFangSC-Medium, PingFang SC;font-weight: 500;color: #333333;">${info}</p>
`
let title = `
<p style="font-size: 18px;color: #FFFFFF;">${res.data[0].stnm ? res.data[0].stnm : ''}</p>
`
let contentData = `
<div style="display: flex;flex-wrap: wrap;">
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:300px;line-height:30px;color: #666666;">闸坝名称</p>
<p style="width:274px;line-height:30px;color: #000000;">${res.data[0].stnm ? res.data[0].stnm : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:300px;line-height:30px;color: #666666;">监控时间</p>
<p style="width:274px;line-height:30px;color: #000000;">${res.data[0].tm ? res.data[0].tm : ''}</p>
</div>
<div style="display: flex;width: 48%;margin-right: 10px;justify-content: space-between;">
<p style="width:300px;line-height:30px;color: #666666;">桩号</p>
<p style="width:274px;line-height:30px;color: #000000;">${res.data[0].stationNumber ? res.data[0].stationNumber : ''}</p>
</div>
<div style="display: flex;width: 48%;justify-content: space-between;">
<p style="width:300px;line-height:30px;color: #666666;">断面名称</p>
<p style="width:274px;line-height:30px;color: #000000;">${res.data[0].sectionName ? res.data[0].sectionName : ''}</p>
</div>
<div id="shenYaEcharts" style="width:100%;height:200px">
</div>
`
var coodinate = e.coordinate;
contentTitle.innerHTML = title
content.innerHTML = contentData
contentInfo.innerHTML = contentInfos
contentInfo.style = "display:flex"
overlay1.setPosition(coodinate);
_this.map.addOverlay(overlay1);
var myChart = _this.$echarts.init(document.getElementById("shenYaEcharts"));
myChart.setOption({
color: ['#5470C6', '#91CC75', '#EE6666'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
}
},
grid: {
right: '20%',
bottom: '10%',
right: '10%'
},
legend: {
data: ['设计浸润线', '监测值']
},
xAxis: [
{
type: 'category',
axisTick: {
alignWithLabel: true
},
// prettier-ignore
data: dataJson.section
}
],
yAxis: [
{
type: 'value',
name: '高程',
position: 'right',
alignTicks: true,
offset: -133,
axisLine: {
show: true,
lineStyle: {
color: colors[1]
}
},
axisLabel: {
formatter: '{value} ml'
}
},
{
type: 'value'
},
{
type: 'value',
// name: '温度',
position: 'left',
alignTicks: true,
axisLine: {
show: true
},
}
],
series: [
{
name: '1',
type: 'bar',
yAxisIndex: 2,
data: dataJson.bar
},
{
name: '设计浸润线',
type: 'line',
yAxisIndex: 2,
data: dataJson.devise
},
{
name: '3',
type: 'line',
yAxisIndex: 2,
data: dataJson.level
},
{
name: '监测值',
type: 'line',
yAxisIndex: 2,
data: dataJson.monitor
}
]
})
window.addEventListener('resize', () => {
myChart.resize()
})
}
})
}
}
});
})
//关闭弹出框操作
popupCloser.addEventListener('click', function () {
overlay1.setPosition(undefined);
});
},
</script>
鼠标移入标记上,鼠标变手型
<script>
mapMouse() {
let _this = this
_this.map.on('pointermove', e => {
//鼠标经过箭头变手势,,可以在if的条件中加入指定的图层layerId即可
let pixel = _this.map.getEventPixel(e.originalEvent);
let feature = _this.map.forEachFeatureAtPixel(pixel, (feature) => {
return feature
})
if (feature) {
_this.map.getTargetElement().style.cursor = 'pointer'
} else {
_this.map.getTargetElement().style.cursor = ''
}
});
},
</script>