You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.4 KiB

2 years ago
<template>
<div>
<div class="map" id="map" :style="{'height':mapHeight+'px'}"></div>
2 years ago
<div ref='infoWindow' id="infoWindow">
2 years ago
<i @click='closeWin' class="el-icon-close"></i>
2 years ago
<div v-for="item in openData">
<template v-if="item.type=='teams'">
<p>名称<span>{{item.mingcheng}}</span></p>
<p>队长<span>{{item.duizhang?item.duizhang:''}}</span></p>
<p>联系电话<span>{{item.lianxidianhua?item.lianxidianhua:''}}</span></p>
<p>人数<span>{{item.renshu?item.renshu:''}}</span></p>
</template>
<template v-if="item.type=='storages'">
<p>名称<span>{{item.cangkumingcheng}}</span></p>
<p>所在区域<span>{{item.suozaiquyu?item.suozaiquyu:''}}</span></p>
<p>建设年代<span>{{item.jiansheniandai?item.jiansheniandai:''}}</span></p>
<p>仓库面积<span>{{item.cangkumianji?item.cangkumianji:''}}</span></p>
<p>负责人<span>{{item.fuzeren?item.fuzeren:''}}</span></p>
<p>联系电话<span>{{item.lianxidianhua?item.lianxidianhua:''}}</span></p>
</template>
2 years ago
</div>
</div>
</div>
</template>
<script>
import {
index,
destroy
} from "@/api/system/baseForm.js"
export default {
data() {
return {
zoom: 10,
center: [120.585294, 31.299758],
mapHeight: 0,
map: null,
makerList: [],
infoWindow: null,
openData: [],
mapList:[]
}
},
created() {
this.initHeight()
this.$nextTick(function() {
this.mapInit()
})
},
methods: {
initHeight() {
let winHeight = document.body.clientHeight
this.mapHeight = winHeight - 50 - 20
},
mapInit() {
this.map = new AMap.Map("map", {
center: this.center,
mapStyle: "amap://styles/bfb1bb3feb0db7082367abca96b8d214", // 设置地图的显示样式
zoom: this.zoom
});
this.infoWindow = new AMap.InfoWindow({
isCustom: true,
autoMove: true,
avoid: [20, 20, 20, 20],
content: this.$refs.infoWindow,
closeWhenClickMap: true,
offset: new AMap.Pixel(-10, -10)
})
2 years ago
this.getTeams()
this.getStorages()
// this.setMapMarker()
2 years ago
},
2 years ago
async getTeams() {
await index({
2 years ago
page: 1,
page_size: 9999,
table_name: 'teams'
}).then(res => {
let markers = []
if(res.data.length<1){
return
2 years ago
}
res.data.map(item=>{
this.mapList.push({
type:'teams',
name:item.mingcheng,
...item
})
})
this.setMapMarker()
// this.mapList = res.data
2 years ago
})
// this.list = res.data
},
2 years ago
async getStorages() {
await index({
page: 1,
page_size: 9999,
table_name: 'flood_storages'
}).then(res => {
let markers = []
if(res.data.length<1){
return
}
res.data.map(item=>{
this.mapList.push({
type:'storages',
name:item.cangkumingcheng,
...item
})
})
this.setMapMarker()
})
// this.list = res.data
},
2 years ago
// 增加点位
setMapMarker() {
var that = this
2 years ago
// that.map.remove(that.makerList)
// that.makerList = []
console.log("this.mapList",this.mapList)
// let list = this.mapList.map((m) => {
// return {
// id: m.id, //数据id
// name: m.name, //数据名称
// // reside: m.reside,
// // lnglat: [m.lon, m.lat],//经纬度数据
// lnglat: [parseFloat(m.jingdu), m.weidu],
// style: 0, //渲染的样式下标,关联第一步创建的样式对象数组的数据
// };
// });
2 years ago
this.mapList.forEach((item, index) => {
// 遍历生成多个标记点
2 years ago
console.log("item",item)
2 years ago
if (!item.jingdu || !item.weidu) {
return
}
2 years ago
2 years ago
let marker = new AMap.Text({
map: this.map,
2 years ago
text: item.name,
2 years ago
zIndex: 9999999,
offset: new AMap.Pixel(-13, -30),
2 years ago
position: [parseFloat(item.jingdu), parseFloat(item.weidu)],
2 years ago
clickable: true,
extData: item.id,
style: {
2 years ago
'border': item.type==='teams'?'1px solid red':'1px solid blue',
2 years ago
'padding': '0px 5px'
}
})
2 years ago
marker.on('click', (e) => {
2 years ago
this.openData = []
if (e.target.w.extData === item.id) {
this.openData.push(item)
}
this.infoWindow.open(this.map, e.target.getPosition())
}),
this.makerList.push(marker)
});
2 years ago
console.log("this.makerList",this.makerList)
2 years ago
this.map.add(this.makerList)
},
closeWin() {
this.infoWindow.close()
},
},
}
</script>
<style>
#infoWindow {
position: relative;
}
#infoWindow>div {
background: #fff;
border: 1px solid red;
padding: 10px;
width: 180px;
}
/deep/ #infoWindow .el-icon-close {
position: absolute;
top: 5px;
right: 5px;
cursor: pointer;
}
</style>