在线人员,箭头指向的分别是一级是镇的整体在线人员,二级菜单指的的村的在线人员 有区域划分、自定义弹窗信息 <template> <div class="contentHome"> <div class="forest" @click="froest"><img class="forestImg" src="@/assets/img/森林.png" alt=""></div> <div v-if="trueList" class="left"> <el-table :data="treeList" :row-style="tableRowStyle" :header-cell-style="tableHeaderColor" :show-header="false" style="width: 100%;background-color: transparent;" height="98%" row-key="id" @row-click="submitForm"> <el-table-column prop="name" label="名称" sortable /> </el-table> </div> <div class="right"> <baidu-map :center="center" :zoom="zoom" :double-click-zoom="false" :scroll-wheel-zoom="true" style="margin: 20px 20px 20px 0;height: 100%;width: 100%; border-style: solid ;border-width:1px; border-color: #8c939d" @ready="handler" > <!-- v-for="(value,index) in points" :key="index" --> <bm-marker v-for="(value,index) in points" :key="index" :position="value" :icon="{url: img3, size: {width: 35, height: 65}}" @mouseover="overTag(value)"> <bm-label :content="value.realName" :label-style="{color: '#000', fontSize : '12px',border:'1px solid #000'}" :offset="{width: 0, height: 40}"/> </bm-marker> <!-- <bm-point-collection :points="points" color="" shape="BMAP_POINT_SHAPE_WATERDROP" size="BMAP_POINT_SIZE_SMALL" @mouseover="overTag" /> --> <bm-polygon v-for="(item,index) in mpoints" :key="index" :path="item.riverTrack" :stroke-color="mColor" :stroke-weight="mwidth" :fill-color="fColor" :fill-opacity="fopacity" :stroke-opacity="mopacity" @mouseover="overTag1(item)" /> <bm-info-window :position="infoPosition" :show="infoOff" title="人员信息:" class="windowbm" style="display:block" @close="infoWindowClose" @open="infoWindowOpen"> <div class="message" style="display:block"> <div v-if="infoCont.date" style="display:block; background-color:#89C477;padding-left:5px;width:102%;color:#fff;font-weight: bold;padding-top:5px;padding-bottom:5px"> 人员信息:</div> <div v-if="infoCont.riverName" style="display:block; background-color:#fff;padding-left:5px;width:102%;color:#fff;font-weight: bold;padding-top:5px;padding-bottom:5px"/> <div class="blackFamily" style="display:block;padding-left:5px;padding-bottom:10px"> <el-row v-if="infoCont.riverName" style="display:block"> <!-- <el-col :span="5" style="display:block"> <span class="silverFamily">区域:</span></el-col> --> <el-col :span="19" style="display:block"> {{ infoCont.riverName }}</el-col> </el-row> <el-row v-if="infoCont.date" style="display:block"> <el-col :span="5" style="display:block"> <span class="silverFamily">时间:</span></el-col> <el-col :span="19" style="display:block"> {{ infoCont.date | parseTime('{y}-{m}-{d} {h}:{i}') }}</el-col> </el-row> <el-row v-if="infoCont.realName" style="display:block"> <el-col :span="5" style="display:block"> <span class="silverFamily">姓名:</span></el-col> <el-col :span="19" style="display:block"> {{ infoCont.realName }}</el-col> </el-row> <el-row v-if="infoCont.officeName" style="display:block"> <el-col :span="5" style="display:block"><span class="silverFamily">部门:</span></el-col> <el-col :span="19" style="display:block"> {{ infoCont.officeName }}</el-col> </el-row> <el-row v-if="infoCont.address" style="display:block"> <el-col :span="5" style="display:block"><span class="silverFamily">地址:</span></el-col> <el-col :span="19" style="display:block"> {{ infoCont.address }}</el-col> </el-row> <el-row v-if="infoCont.lng" style="display:block"> <el-col :span="5" style="display:block"><span class="silverFamily">经度:</span></el-col> <el-col :span="7" style="display:block"> {{ infoCont.lng }}</el-col> <el-col :span="5" style="display:block"><span class="silverFamily">纬度:</span></el-col> <el-col :span="7" style="display:block"> {{ infoCont.lat }}</el-col> </el-row> <!-- <el-row v-if="infoCont.lng" style="display:block"> <el-col :span="5" style="display:block"><span class="silverFamily">纬度:</span></el-col> <el-col :span="19" style="display:block"> {{ infoCont.lat }}</el-col> </el-row> --> </div> </div> </bm-info-window> </baidu-map> </div> </div> </template> <script> import { organization, peopleMap, allRiver, userOnlineCoun } from '@/api/index' import { unescape } from '@/utils/index' export default { data() { return { img3: require('@/assets/img/person.png'), points: [], treeList: [], treeProps: { value: 'id', label: 'name' }, fullscreenLoading: false, // 地图加载动画 // 地图初始化的位置 center: { lng: 109.15374, lat: 33.42366 }, // 地图内的大小 zoom: 12, // 这个是搜索下的东西 location: '', // 这个是选择搜索列表中数据的title以及经纬度 locationdata: { title: '', center: '', addr: ''// 地址 }, geolocation: '', BMap: '', textMap: { map: '地图' }, dialogStatus: 'map', mapCPM: false, inputaddr: '', organizationId: null, show: false, isShowInfo: false, infoOff: false, // 信息窗口显示 // infoCont: '', // 信息窗口内容 infoPosition: { lng: 0, lat: 0 }, // 信息窗口位置 contAddrList: [], trueList: false, mpoints: [], infoCont: { 'officeId': undefined, 'date': undefined, 'realName': undefined, 'officeName': undefined, 'address': undefined, 'lng': undefined, 'parentIds': undefined, 'label': undefined, 'userId': undefined, 'lat': undefined } } }, computed: { mColor() { return 'blue' }, fColor() { return 'transparent' }, mwidth() { return 4 }, mopacity() { return 0.5 }, fopacity() { return 0 } }, created() { this.getTreeList() }, mounted() { var organizationNum = this.organizationId === null ? '' : this.organizationId window.setInterval(() => { console.log(organizationNum) setTimeout(this.peopleMap(organizationNum), 0) }, 5000) }, methods: { // 由于百度地图 JS API 只有 JSONP 一种加载方式,因此 BaiduMap 组件及其所有子组件的渲染只能是异步的。因此,请使用在组件的 ready 事件来执行地图 API 加载完毕后才能执行的代码,不要试图在 vue 自身的生命周期中调用 BMap 类,更不要在这些时机修改 model 层。 // var map = new BMap.Map('container', { mapType: BMAP_HYBRID_MAP }) // 设置卫星图为底图 handler({ BMap, map }) { console.log('1111', BMap) console.log('2222', map) map.addControl(new BMap.MapTypeControl({ mapType: ['BMAP_HYBRID_MAP'] })) map.setMapType(BMAP_HYBRID_MAP) // window.map = map // 注册为全局 var geolocation = new BMap.Geolocation() this.geolocation = geolocation geolocation.getCurrentPosition(() => { }) geolocation.enableSDKLocation() geolocation.getCurrentPosition(function(r) { console.log(r) // eslint-disable-next-line no-undef,eqeqeq if (this.getStatus() == BMAP_STATUS_SUCCESS) { // 把得到的经纬度传给map,就实现了第一步我们的定位 if (r.accuracy == null) { return } } else { console.log('failed' + this.getStatus()) } }, { enableHighAccuracy: true }) this.BMap = BMap console.log(this.BMap) // loading.close() this.peopleMap('') this.allRiver() }, // 删除覆盖物 clearOverlays() { window.map.clearOverlays() }, getTreeList() { this.listLoading = true organization().then(response => { const fetchOrganizationList = response.data // console.log('response', response.data[0]) for (var i = 0; i < fetchOrganizationList.length; i++) { this.treeList.push({ id: fetchOrganizationList[i].id, name: fetchOrganizationList[i].name, children: fetchOrganizationList[i].children }) } this.listLoading = false }) }, froest() { this.trueList = !this.trueList }, // 数据接口 peopleMap(organizationId) { peopleMap(organizationId).then(response => { this.points = [] var positionList = response.data.data this.contAddrList = response.data.data const points = [] for (var i = 0; i < positionList.length; i++) { const position = { lng: positionList[i].lng, lat: positionList[i].lat, id: positionList[i].officeId, realName: positionList[i].realName } points.push(position) } this.points = points if (this.points.length != '0') { this.center = { lng: this.points[0].lng, lat: this.points[0].lat } } // console.log('this.points', this.points) }) }, allRiver() { allRiver().then(res => { console.log('allRiver', res.data.data) this.mpoints = res.data.data this.mpoints.forEach(item => { // 获取滑过标点窗体信息 // item.riverTrack = JSON.parse(unescape(item.riverTrack)) item.riverTrack = JSON.parse(item.riverTrack) console.log(item.riverTrack) }) console.log('this.mpoints', this.mpoints) }) }, // 显示标点 submitForm(data) { console.log('dian', data) this.organizationId = data.id this.peopleMap(this.organizationId) }, // 滑过标点显示窗体 overTag1(value) { console.log('value', value) this.infoOff = true this.infoPosition.lng = value.riverTrack[0].lng this.infoPosition.lat = value.riverTrack[0].lat this.infoCont = { riverName: undefined } this.infoCont.riverName = value.riverName }, overTag(value) { console.log('overTag的value', value) console.log('contAddrList', this.contAddrList) // console.log('this.contAddrList', this.contAddrList) this.infoOff = true this.infoPosition.lng = value.lng this.infoPosition.lat = value.lat this.infoCont = { 'officeId': undefined, 'date': undefined, 'realName': undefined, 'officeName': undefined, 'address': undefined, 'lng': undefined, 'parentIds': undefined, 'label': undefined, 'userId': undefined, 'lat': undefined } this.contAddrList.forEach(item => { // 获取滑过标点窗体信息 // console.log('item',item) if (item.officeId === value.id) { // this.infoCont = '名称:' + item.realName this.infoCont = item } }) }, // 窗体打开和关闭 infoWindowClose(e) { this.infoOff = false }, infoWindowOpen(e) { this.infoOff = true }, tableRowStyle({ row, rowIndex }) { return 'background-color: pink' }, // 修改table header的背景色 tableHeaderColor({ row, column, rowIndex, columnIndex }) { if (rowIndex === 0) { return 'background-color: lightblue;color: #fff;font-weight: 500;' } } } } </script> <style> .left .el-table td, .el-table th{ background-color: #fff!important; color:#000!important; } .left .el-table th, .el-table tr, .el-table td { border: 0; } .left .el-table__empty-block{ background-color: #fff!important; color:#000!important; } .left .topBorder{ border-top:1px solid #fff; } .left .el-table__body tr:hover > td { background-color: #409EFF !important; color:#fff!important; } /*地图标题*/ .BMap_bubble_title { color:#fff; font-size:13px; font-weight:bold; text-align:left; padding-left:5px; padding-top:5px; background-color:#89C477; } /* 消息内容 */ .BMap_bubble_content { background-color:white; width:96%; /* padding-left:5px; padding-top:5px; padding-bottom:10px; */ margin-right:0; /* background-color: green; */ } /* 内容 */ .BMap_pop div:nth-child(9) { top:35px !important; border-radius:7px; background-color: #fff; } /* 左上角删除按键 */ .BMap_pop img { top:43px !important; left:330px !important; } .BMap_top { display:none; } .BMap_bottom { display:none; } .BMap_center { display:none; } .BMap_pop div:nth-child(1) { display:none; } .windowbm{ display: block!important; width:335px; } .BMap_pop div:nth-child(5) { display:none; } .BMap_pop div:nth-child(3) { display:none; } .BMap_pop div:nth-child(7) { display:none; } .blackFamily .el-row{ margin-bottom:10px!important; } </style> <style scoped> .contentHome{ width:100%; height:100%; display: flex; flex-direction: row; justify-content: space-between; overflow: hidden; } .left{ position: absolute; left:2%; top:15%; z-index: 3; width:13%; height:85%; padding:20px 0 20px 20px; overflow: hidden; } .right{ width:100%; height:100%; overflow: hidden; } .windowbm{ width:335px; } .list{ width:300px; height:300px; } .forest{ position: fixed; left:1%; top:15%; z-index: 4; } .forestImg{ width:32px; height:32px; } .message{ font-size: 14px; width:98%; /* line-height: 25px; */ } .silverFamily{ font-weight: 500; color:rgb(112, 111, 111); } .blackFamily{ font-weight: bold; } .BMap_bubble_title{ background-color: springgreen!important; } </style>
百度地图之 区域划分、在线人员点标记、点每个标记点,弹出对应的信息
最新推荐文章于 2023-02-21 16:59:59 发布