【vue baidu-map】实现百度地图展示基地,鼠标悬浮标注点展示详细信息

实现效果如下:

自用代码记录

<template><div class="map" style="position: relative;"><baidu-mapid="bjmap":scroll-wheel-zoom="true":auto-resize="true"@ready="handler"><bm-markerv-for="(item, index) in markerList":key="index":position="item.position":icon="item.icon"@click="handlerinfoWindowOpen(index)"><bm-info-window:position="item":show="item.show"@close="infoWindowClose(index)"@open="infoWindowOpen(index, item)":auto-pan="true":close-on-click="false"><div>视频箭头</div><!-- <div><ahref="#/internet"style="font-size: 15px;border-bottom: 1px #0464a4 solid;color: #0464a4;">视频监控名称:{{ item.name }}</a> --><!-- <video-playerstyle="width: 200px; height: 100px":ref="videoId"class="myPlayer"muted="true":options="videoOptions"/> --><!-- <span>企业名称:</span><span>{{current }}testt</span> --><!-- </div> --></bm-info-window></bm-marker><bm-polygon v-for="(markers, index) in planBaseMassifs" :key="index" :path="markers" :stroke-color="drawColor" :stroke-opacity="1" :stroke-weight="4" :fillColor="drawColors" :fillOpacity="1" /><div class="equipmentBox" v-if="equipmentType"><div:class="current == key ? 'item current' : 'item'"v-for="(value, key) in equipmentType":key="key"@click="changeType(key)"><div>{{ key }}</div><div>({{ value }})</div></div></div><div v-show="current == '视频监控'" class="equipmentBox1"><video-playerstyle="width: 100%; height: 100%;position:absolute;":ref="videoId"class="myPlayer"muted="true":options="videoOptions"/></div></baidu-map></div>
</template><script>
// var echarts = require('echarts')
import { getPlantBases } from '@/api/table'
import { getUserEquipments ,getPageList} from '@/api/equipment'
// import { setServers } from 'dns';
// import { sumRpt } from '@/api/equipment'
import { staticResourceLocation } from '@/settings'
import defaultSettings from '@/settings'
import initData from '../../../mixins/initData'
import VideoPlayer from '@/views/components/videoPlayer.vue'
import { log } from 'video.js'export default {props: {childrenData: {type: Object,default: function () {return {}},},},data() {return {staticResourceLocation,plantBaseList: [],screenHeight: window.innerHeight - 84, // 屏幕高度screenWidth: window.innerWidth,systitle: '',map: null,BMap: null,NavigationControl: null,MapTypeControl: null,// 设备列表equipmentList: [],planBaseMassifs:[],equipmentType: [],current: 'LED',markerList: [],videoOptions: {autoplay: false,controls: true,},videoId: '',drawColors: '#e9d99b',videoList: [],markers:[],drawColor: "#ff0000",}},components: { VideoPlayer },mounted() {var _this = thiswindow.onresize = function () {// 定义窗口大小变更通知事件_this.screenHeight = document.documentElement.clientHeight - 84 // 窗口高度_this.screenWidth = document.documentElement.clientWidth // 窗口宽度//map.removeControl(NavigationControl)   //删除比例尺控件_this.map.removeControl(_this.NavigationControl)_this.map.removeControl(_this.MapTypeControl)_this.NavigationControl = new BMap.NavigationControl({// 地图平移缩放控件anchor: BMAP_ANCHOR_TOP_LEFT,type: BMAP_NAVIGATION_CONTROL_LARGE,offset: new BMap.Size(_this.screenWidth / 4 + 5, 10),})_this.MapTypeControl = new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP],offset: new BMap.Size(_this.screenWidth / 4 + 5, 10),})_this.map.addControl(_this.NavigationControl)_this.map.addControl(_this.MapTypeControl)}console.log(this.childrenData, 'childrenData--->statistics')this.equipmentType = this.childrenData.withCategory// sumRpt().then((res) => {//   if (res.body) {//     let { withCategory } = res.body//     this.equipmentType = withCategory//   }// })getUserEquipments().then((res) => {console.log('百度地图传的接口',res)this.equipmentList = res.bodythis.equipmentList.forEach((item) => {if (item.category === 1 && item.point) {var obj = {position: {lng: item.point.split(',')[0],lat: item.point.split(',')[1],},icon: {url: this.staticResourceLocation + 'static/LED.png',size: { width: 33, height: 33 },opts: {imageSize: { width: 33, height: 33 },},},}this.markerList.push(obj)} else if (item.category === 2) {var obj1 = {hdAddress: item.videoUrl,id: item.videoId,}this.videoList.push(obj1)let indexId = 0this.videoId = this.videoList[indexId].idthis.$nextTick(function () {var _thisVideoRefs = this.$refs[this.videoList[indexId].id]if (_thisVideoRefs) {var player = _thisVideoRefs.playerplayer.src(this.videoList[indexId].hdAddress)//player.play();}})}})})},beforeDestroy() {if (this.timer) {clearInterval(this.timer) // 在Vue实例销毁前,清除我们的定时器}},created() {},mixins: [initData],methods: {changeType(key) {this.markerList = []this.current = keyvar index =key == 'LED'? 1: key == '视频监控'? 2: key == '环境监测'? 3: key == '水肥机'? 4: key == '虫情测报灯'? 5: key == '杀虫灯'? 6: key == '智能控制柜'? 7: 0// console.log(index)var iconPath = ''if (index == 1) {iconPath = this.staticResourceLocation + 'static/led.png'} else if (index == 2) {iconPath = this.staticResourceLocation + 'static/video.png'} else if (index == 3) {iconPath = this.staticResourceLocation + 'static/qxjc.png'} else if (index == 4) {iconPath = this.staticResourceLocation + 'static/jsgg.png'} else if (index == 5) {iconPath = this.staticResourceLocation + 'static/Insecticidal.png'} else if (index == 6) {iconPath = this.staticResourceLocation + 'static/scd.png'} else if (index == 7) {iconPath = this.staticResourceLocation + 'static/znkzk.png'}this.equipmentList.forEach((item) => {if (item.category === index && item.point) {var obj = {position: {lng: item.point.split(',')[0],lat: item.point.split(',')[1],},show: false,name: item.name,icon: {url: iconPath,size: { width: 33, height: 33 },opts: {imageSize: { width: 33, height: 33 },},},}this.markerList.push(obj)}})// console.log(this.markerList, 'kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk')},// gohome() {//   console.log('666')//   var user = this.$store.state.user.user//   if (user.homeUrl && user.homeUrl != '') {//     this.$router.push(user.homeUrl)//   } else {//     this.$router.push('/')//   }// },// redirectMonitor: function () {//   this.$router.push('/monitor/tine')// },handler({ BMap, map }) {this.map = mapthis.BMap = BMapgetPlantBases().then((res) => {console.log(res.body, '百度地图')this.plantBaseList = res.bodyvar point = ''this.plantBaseList.forEach((item) => {if (item.position) {point = new BMap.Point(item.position.split(',')[0],item.position.split(',')[1])}})if (point === '') {point = new BMap.Point(107.034026, 33.073558)}map.centerAndZoom(point, 8) // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true) // 启用滚轮放大缩小var myIcon = new BMap.Icon('http://lyds.fengyuniot.com/content/upload/mappoint.png',new BMap.Size(40, 52),{anchor: new BMap.Size(10, 10),})// var marker = new BMap.Marker(point) // 创建标注// map.addOverlay(marker) // 将标注添加到地图中var NavigationControl = new BMap.NavigationControl({// 地图平移缩放控件anchor: BMAP_ANCHOR_TOP_LEFT,type: BMAP_NAVIGATION_CONTROL_LARGE,offset: new BMap.Size(this.screenWidth / 4 + 5, 10),})this.NavigationControl = NavigationControl// 添加地图类型控件var MapTypeControl = new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP],offset: new BMap.Size(this.screenWidth / 4 + 5, 10),})this.MapTypeControl = MapTypeControlmap.addControl(NavigationControl)map.setMapType(BMAP_HYBRID_MAP) // 调取地图类型混合型map.addControl(MapTypeControl)var markerArr = this.plantBaseList// console.log(this.plantBaseList, 'this.plantBaseList11111')markerArr.forEach((e, i) => {var positionArr = e.position.split(',')// console.log(e, 'errrrr')// console.log(e.plantBasePictures[0].pictureUrl, 'rrrrr')var background = ''if (e.plantBasePictures != null && e.plantBasePictures.length > 0) {background =defaultSettings.staticResourceLocation +e.plantBasePictures[0].pictureUrl}// console.log(background, 'background')let opts = {width: 200,height: 100,}// 创建point, 将x,y值传入const pointNumber = new BMap.Point(positionArr[0], positionArr[1])const infoWindow = new window.BMap.InfoWindow("<div class='maptipsinfo'style='color:white;' ><a href='#/nutrientManagement'  style='font-size:15px;border-bottom:1px #0464A4 solid;color:#00fe8f;'><span>" +e.baseName +'</span></a>' +"<p style='font-size:14px;'><span>地址:</span>" +e.address +'</p>' +'<img  style="width:100%;height:80%;" src="' +background +'"/>' +'</div>',opts)// infoWindow.setStyle({// color: '#fff', // 字体颜色为白色// background: '#000', // 背景颜色为黑色// border: 'none', // 去掉边框// borderRadius: '5px', // 圆角半径// padding: '10px', // 内边距// fontSize: '14px', // 字体大小// lineHeight: '20px', // 行高// })var label = new BMap.Label(e.baseName, {offset: new BMap.Size(25, 5),})this.markerFun(map, pointNumber, infoWindow, label, myIcon)})})const params = {pageIndex: this.pageIndex,pageSize: this.pageSize,enterPriseId: this.enterPriseId,}getPageList(params).then((res)=>{console.log(res,'你好555555555555');// planBaseMassifsif(res.errorCode == 20000){const  array  = res.body.listconst innerObjects = [];for (let i = 0; i < array .length; i++) {const innerObject  = array [i].planBaseMassifs;innerObjects.push(innerObject)}this.planBaseMassifs = innerObjectsconsole.log(this.planBaseMassifs,'this.planBaseMassifs');// 使用map()方法遍历嵌套数组let modifiedArray = innerObjects.map((subArray) => {// 检查子数组是否为nullif (subArray === null) {return [];}// 使用map()方法遍历子数组中的每个对象return subArray.map((obj) => {// 替换属性名obj.lat = obj.latitude;obj.lng = obj.longitude;delete obj.latitude;delete obj.longitude;// 处理null值if (obj === null) {return {};} else {return obj;}});}).filter((subArray) => subArray.length > 0);for (let i = 0; i < modifiedArray.length; i++) {// 获取每个子数组的第一行内容let firstRow = modifiedArray[i][0];// modifiedArraymodifiedArray[i].push(firstRow);}this.planBaseMassifs = modifiedArray}})},markerFun: function (map, points, infoWindows, label, myIcon) {console.log('1111a',map,points, infoWindows, label, myIcon,)const markers = new BMap.Marker(points, { icon: myIcon })map.addOverlay(markers) // 将标注添加到地图中// markers.setLabel(label);  // 将data中的name添加到地图中// 标注的点击事件markers.addEventListener('mouseover', function (event) {map.openInfoWindow(infoWindows, points) // 参数:窗口、点  根据点击的点出现对应的窗口})// console.log('1a')},infoWindowOpen(index, item) {if (this.current == '视频监控') {this.markerList[index].show = truelet indexId = indexthis.videoId = this.videoList[indexId].idthis.$nextTick(function () {var _thisVideoRefs = this.$refs[this.videoList[indexId].id]// console.log(this.videos,_thisVideoRefs,'_thisVideoRefs_thisVideoRefs')if (_thisVideoRefs) {var player = _thisVideoRefs.player// console.log(player.src,'_thisVideoRefs11')player.src(this.videoList[indexId].hdAddress)//player.play();}})}},infoWindowClose(index) {this.markerList[index].show = false},handlerinfoWindowOpen(index) {this.markerList[index].show = trueconsole.log('点击标记点',index)this.show = trueif (this.current == '视频监控') {this.markerList[index].show = truelet indexId = indexthis.videoId = this.videoList[indexId].idthis.$nextTick(function () {var _thisVideoRefs = this.$refs[this.videoList[indexId].id]if (_thisVideoRefs) {var player = _thisVideoRefs.playerplayer.src(this.videoList[indexId].hdAddress)//player.play();}})}},// handlerinfoWindowOpen(index) {//   this.markerList[index].show = true//   console.log('点击标记点',this.markerList[index].show)//   this.show = true//   if (this.current == '视频监控') {//     this.markerList[index].show = true//     let indexId = index//     this.videoId = this.videoList[indexId].id//     this.$nextTick(function () {//       var _thisVideoRefs = this.$refs[this.videoList[indexId].id]//       if (_thisVideoRefs) {//         var player = _thisVideoRefs.player//         player.src(this.videoList[indexId].hdAddress)//         //player.play();//       }//     })//   }// },// 异步调用百度jsmap_load() {var load = document.createElement('script')load.src = 'http://api.map.baidu.com/api?v=1.4&callback=map_init'document.body.appendChild(load)},},
}
</script><style scoped lang="scss">
/*地图提示*/.equipmentBox {/* width: 240px; */// position: absolute;// top: 70px;// right: calc(25vw + 5px);position: absolute;top: 70px;right: 5px;
}
.equipmentBox1 {width: 260px;position: absolute;bottom: 35%;right: calc(25vw + 5px);
}.equipmentBox .item {display: flex;justify-content: space-around;align-items: center;width: 108px;height: 27px;border-radius: 14px;background-color: #fff;color: #010101;font-size: 12px;font-weight: bold;cursor: pointer;margin-bottom: 5px;text-align: right;
}.equipmentBox .current {background-color: #00b065;color: #fff;
}
// 地图
.map{width:100%;height: 100%;
}
.map .maptipsinfo p {font-size: 14px;line-height: 14px;height: 14px;color: #777;
}
.maptipsinfo a:hover {color: #0696f9;border-color: #0696f9;
}
.maptipsinfo span {color: #333;
}
.maptipsinfo {background: url();
}
.map #bjmap {width: 100%;height: 100%;display: inline-block;vertical-align: baseline;/* position: fixed; */div:first-of-type{border-radius: 15px !important;
}
}
.map #bjmap>div:first-of-type{border-radius: 15px !important;
}
.map .nowdatatime {border: 1px solid #00c7dd;background: rgba(0, 0, 0, 0.6);box-shadow: 0 0 10px rgba(1, 129, 143, 0.8);position: relative;top: -97%;padding: 10px;width: 240px;margin: 0 auto;text-align: center;border-radius: 5px;font-size: 1.5rem;
}
.imgss {height: 30px;width: 30px;
}
/*.map .el-loading-spinner .circular{width: 80px;height: 80px;animation: loading-rotate 2s linear infinite;} */
/*.map  .el-loading-spinner{background: url(../../assets/img/default_img.gif) no-repeat;background-size: 80px 80px;width: 100%;height: 100%;position: relative;top: 45%;left: calc(50% - 40px);
} */// /deep/.BMap_pop img,
// /deep/.BMap_top,
// /deep/.BMap_center,
// /deep/.BMap_bottom,
// /deep/.BMap_pop > div {
//   &:not(:nth-child(9)) {
//     display: none;
//   }
// }// /deep/.BMap_pop div:nth-child(9) {
//   // top: 30px !important;
// }
// /deep/.BMap_bubble_content {
//   // border-top: 3px solid #377abd;
//   border-top: 3px solid rgba(44, 55, 47, 0.3);
//   // border-bottom: 3px solid #377abd;
//   border-bottom: 3px solid rgba(44, 55, 47, 0.3);
//   border-radius: 8px;
//   // background-color: rgba(36, 105, 137, 0.8);
//   background-color: rgba(44, 55, 47, 0.4);
//   overflow: hidden;
//   color: #ffffff;
//   padding: 8px 5px;
//   font-size: 14;
// }
.baidu-map-con {background-color: #043f31;// width: 100%;// height: 100%;
}
::v-deep #bjmap .BMap_stdMpCtrl{inset: 30px auto auto 10px !important;
}
// ::v-deep #bjmap .BMap_noprint {
//   inset: 10px 90% auto auto !important;
// }
::v-deep #bjmap .anchorTR{inset: 5px 91% auto auto !important;
}
::v-deep #bjmap .BMap_stdMpCtrl{//inset: 40px auto auto 30px !important;
}
// marker颜色
::v-deep .BMap_bubble_title{color:#fff;font-size:18px;/*font-weight: bold;*/text-align:left;background:transparent !important;
}::v-deep .BMap_pop .BMap_top{background:#043f31 !important;border:0 !important;
}
::v-deep .BMap_pop .BMap_center{width:251px !important;// height: 300px !important;border:0 !important;background:#043f31 !important;
}
::v-deep .BMap_pop .BMap_bottom{border:0 !important;background:#043f31 !important;
}::v-deep .BMap_pop div:nth-child(3){background:transparent !important;
}
::v-deep .BMap_pop div:nth-child(3) div{border-radius:7px;background:#043f31 !important;border:0 !important;
}
::v-deep .BMap_pop div:nth-child(1){border-radius:7px 0 0 0;background:transparent !important;border:0 !important;
}
::v-deep .BMap_pop div:nth-child(1) div{background:#043f31 !important;
}
::v-deep .BMap_pop div:nth-child(5){border-radius:0 0 0 7px;background:transparent !important;border:0 !important;
}
::v-deep .BMap_pop div:nth-child(5) div{border-radius:7px;background:#043f31 !important;
}
::v-deep .BMap_pop div:nth-child(7){background:transparent !important;
}
::v-deep .BMap_pop div:nth-child(7) div{border-radius:7px;background:#043f31 !important;
}::v-deep .BMap_pop div:nth-child(8) div{/*border-radius:7px;*/background:#043f31 !important;
}
/*窗体阴影*/
::v-deep .BMap_shadow div:nth-child(5) img{margin-left: -1100px !important;
}::v-deep .BMap_shadow div:nth-child(4){width: 262px !important;
}
::v-deep img[src="http://api0.map.bdimg.com/images/iw3.png"] {content: url('../../../assets/mapMarker.png');
}
::v-deep img[src="https://api.map.baidu.com/images/iw3.png"] {margin-top: -692px !important;filter: alpha(opacity=70);content: url('../../../assets/mapMarker.png');
}</style>
<style>
#bjmap>div:first-of-type{
/* border-radius: 15px; */
}</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/543397.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

力扣78. 子集

Problem: 78. 子集 文章目录 题目描述思路及解法复杂度Code 题目描述 思路及解法 1.定义一维数组track用于记录决策路径&#xff0c;二维数组res用于存储所有的子集&#xff1b; 2.决策阶段&#xff1a;从0阶段起来&#xff08;0阶段决策路径中为空集&#xff09;&#xff0c;每…

力扣每日一题 卖木头块 线性DP

Problem: 2312. 卖木头块 文章目录 思路复杂度Code 思路 &#x1f468;‍&#x1f3eb; 灵神题解 复杂度 时间复杂度: O ( n m ( m n ) ) O(nm(mn)) O(nm(mn)) 空间复杂度: O ( n m ) O(nm) O(nm) Code class Solution {public long sellingWood(int n, int m, int…

“城市绿肺诊断:集成GIS、RS、VORS模型、CCDM模型、geodetecto、GWR模型技术深入解析生态系统与城镇化协调发展“

基于GIS、RS、VORS模型、CCDM模型、geodetecto、GWR模型集成的生态系统健康的耦合协调分析 城市群是一国经济发展水平的象征&#xff0c;也是一国经济发展到一定阶段的标志&#xff0c;我国城市群建设体量不断增加&#xff0c;将成为全球经济的核心&#xff0c;中国城市群的建…

除了「au revoir」,「再见」还能怎么说?柯桥成人学外语来银泰附近

1. Je dois y alle#15857575376r I have to go there Y there&#xff0c;意思是“我要走了”。 例如&#xff0c;”Moi, je dois y aller.” 对不起&#xff0c;我该走了。 如果你和同伴都要离开&#xff0c;那就可以说"On y va"&#xff0c;它相当于英语里…

应用程序开发教学:医保购药系统源码搭建实战

医保购药系统作为医疗服务的重要组成部分&#xff0c;其开发不仅能够为患者提供更加便捷的购药服务&#xff0c;还能够提高医疗机构的管理效率。接下来&#xff0c;小编将为您讲解医保购药系统的源码搭建过程&#xff0c;介绍应用程序开发的基本步骤和技巧。 一、系统设计 我…

一键批量瘦身:高效图片像素压缩,解放你的生产力

在快节奏的工作环境中&#xff0c;我们时常需要处理大量的图片文件。这些图片不仅占据了大量的存储空间&#xff0c;而且在传输和加载时也会耗费大量的时间。如何高效、批量地处理这些图片&#xff0c;成为了提升工作效率的关键。今天&#xff0c;我要为大家介绍一款能够一键批…

maven私服搭建详细教程

1、为什么需要私服 如果在公司中多个项目模块中的的公共类用的都是一样的&#xff0c;那么不可能将这些一样的代码写两遍。所以将其中一个项目中的代码打包成私服&#xff0c;然后在另外一个模块中去进行引用。 除此之外&#xff0c;如果大公司中开发人员较多&#xff0c;大家同…

C语言葵花宝典之——文件操作

前言&#xff1a; 在之前的学习中&#xff0c;我们所写的C语言程序总是在运行结束之后&#xff0c;就会自动销毁&#xff0c;那如果我们想将一个结果进行长期存储应该如何操作呢&#xff1f;这时候就需要我们用文件来操作。 目录 1、什么是文件&#xff1f; 1.1 程序文件 1.2…

《ARM汇编与逆向工程 蓝狐卷 基础知识》

大家好&#xff0c;我是爱编程的喵喵。双985硕士毕业&#xff0c;现担任全栈工程师一职&#xff0c;热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。…

docker的常用指令

docker的常用指令 从docker镜像仓库&#xff0c;搜索所有和mysql有关的镜像 docker search mysql 从docker仓库拉取mysql docker pull mysql这里的mysql是指使用search搜索出来的所有容器的NAME 如果和我一样遇到以下问题&#xff1a; 我可以登录阿里云的官网&#xff0c;找…

[嵌入式系统-39]:龙芯1B 开发学习套件 -10-PMON启动过程Sstart.S详解

目录 一、龙芯向量表与启动程序的入口&#xff08;复位向量&#xff09; 1.1 复位向量&#xff1a; 1.2 代码执行流程 1.3 计算机的南桥 VS 北桥 二、PMON代码执行流程 三、Start.S详解 3.1 CPU初始化时所需要的宏定义 &#xff08;1&#xff09;与CPU相关的一些宏定义…

【商业|数据科学主题会议推荐】2024年商业分析与数据科学国际学术会议(ICBADS 2024)

【商业|数据科学主题会议推荐】2024年商业分析与数据科学国际学术会议&#xff08;ICBADS 2024) 征稿主题 &#xff08;以下主题包括但不限于&#xff09; 多媒体决策 决策理论与决策科学 数字市场设计与运营 降维 电子商务 道德决策 财务分析 群体决策与软件 医疗保…