vue中使用高德地图,根据类型显示不同点,点击出现弹框居中显示,并在可视化区域显示所有点

效果图
在这里插入图片描述

一、安装 vue-amap 插件

npm install vue-amap --save

二、vue页面

<template>
<div><ul style='display:flex;'><liv-for="(item, index) in checkList":key="index"@click="onClick(item)":class="item.checked ? 'active' : ''"><span class="name">{{ item.label }}</span></li></ul>
<div ref='map' id='map' style='width:500px;height:500px'></div></div>
</template>
<script>
import AMapLoader from '@amap/amap-jsapi-loader';//引入
import point1 from '@/assets/images/point1.png'
import point2 from '@/assets/images/point2.png'
import point3 from '@/assets/images/point3.png'
export default {data() {return {checkList: [{ label: '类型1', checked: false, value: 1 },{ label: '类型2', checked: false, value: 2 },{ label: '类型3', checked: false, value: 3 },],_map:null}},mounted(){this.initMap()
},methods: {initMap(){AMapLoader.load({key: "你的key", // 申请好的Web端开发者Key,首次调用 load 时必填version: "1.4.15", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15plugins: ["AMap.Scale", "AMap.ToolBar", "AMap.ControlBar", 'AMap.Geocoder', 'AMap.Marker',  'Map3D','AMap.Geolocation', 'AMap.InfoWindow'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等}).then((AMap) => {// 获取到作为地图容器的DOM元素,创建地图实例this._map = new AMap.Map(this.$refs['map'], { //设置地图容器idresizeEnable: true,viewMode: "3D", // 使用3D视图zoomEnable: true, // 地图是否可缩放,默认值为truedragEnable: true, // 地图是否可通过鼠标拖拽平移,默认为truedoubleClickZoom: true, // 地图是否可通过双击鼠标放大地图,默认为truezoom: 12, //初始化地图级别center: [118.77,32.03], // 初始化中心点坐标pitch: 50, //倾斜视角})this._map.setMapStyle("amap://styles/darkblue");}).catch(e => {console.log(e)})},// 关闭弹框closeDialog() {if (this._infoWindow) {this._infoWindow.close(this._map)}},onClick(item) {item.checked = !item.checkedif (this._infoWindow) {this._infoWindow.close(this._map)}if (item.value ==1) {if (item.checked) {const data = [{icon: point1,position: [118.79,32.00],content: ` <div class="map-info-dlg"><div class="map-info-head"><div class="tit"><span>自定义标题</span></div></div><div class="map-info-content"><div class="content-wxy"><div class='row'>自定义内容:<span class='row-value'>123</span></div></div></div></div>`,},]this.setMarkers(data,1)} else {this.removeMarkers(1)}}if (item.value == 2) {if (item.checked) {const data = [{icon: point2,position: [118.77,32.00],content: ` <div class="map-info-dlg"><div class="map-info-head"><div class="tit"><span>自定义标题</span></div></div><div class="map-info-content"><div class="content-wxy"><div class='row'>自定义内容:<span class='row-value'>123</span></div></div></div></div>`,},]this.setMarkers(data,2)} else {this.removeMarkers(2)}}},setMarkers(data,type){for (let i = 0; i < data.length; i++) {const img = new AMap.Icon({size: new AMap.Size(60, 80),image: data[i].icon,imageSize: new AMap.Size(60, 80),})const icon = { ...data[i], icon: img }this._marker = new AMap.Marker({position: icon.position,icon: icon.icon,//   offset: new AMap.Pixel(-12, -36),extData: { content: icon.content,type },})this._markers.setMap( this._map)if (this._markers) {this._markers.push(this._marker)} else {this._markers = []this._markers.push(this._marker)}this._marker.on('click', (e) => {this.closeDialog()const marker = e.targetconst content = marker.getExtData().contentthis._map.panTo(marker.getPosition())this.showInfoWindow(content, marker.getPosition())})}this._map.setFitView(this._markers, true)//可视化区域显示所有点},removeMarkers(type){if (this._markers) {for (let i = 0; i < this._markers.length; i++) {const content = this._markers[i].getExtData().contentif(content.type == type){this._map.remove(this._markers[i])}}if (this._infoWindow) {this._infoWindow.close( this._map)}}},showInfoWindow(content, position) {console.log('position: ', position);this._infoWindow = new AMap.InfoWindow({content: content,position: position,offset: new AMap.Pixel(10, -30),autoMove: true,zIndex:400})this._infoWindow.open(this._map)},// toggleMarkers(type, visible) {//   if (this._markers) {//    for (let i = 0; i < this._markers.length; i++) {//      const marker = this._markers[i]//      const icon = marker.getIcon()//       if (icon.indexOf(type) !== -1) {//       marker.setVisible(visible)//     }//     }//   }//  },},
}
</script>
<style scoped lang="scss">li {width: 177px;height: 40px;cursor: pointer;.name {color:#000;}}.active {.name {color:red !important;}}
</style>
<style lang="scss">
.amap-info-contentContainer,
.amap-info-content {overflow: hidden;padding: 0;margin: 0;background: transparent;
}
.amap-info-sharp {border-top: 8px solid #2c4e79 !important;display: none;
}
.map-info-dlg {background: url('../../../assets/images/yjzh/common/tc-bg.png') no-repeat;background-size: 100% 100%;.map-info-head {width: 300px;display: flex;align-items: center;justify-content: space-between;height: 32px;background: url('../../../assets/images/yjzh/common/tc-title.png') no-repeat;background-size: 100% 100%;margin: 6px 0 0 0px;.tit {font-size: 16px;width: 100%;margin-left: 12px;background-image: -webkit-linear-gradient(bottom, #fff, #98deff);-webkit-background-clip: text;-webkit-text-fill-color: transparent;font-family: Alimama;}.c-img {width: 20px;height: 20px;margin: 0 12px 4px 0;cursor: pointer;}}.map-info-content {width: 300px;padding-left:  16px;.content-wxy,.content-bns {color: #fff;font-size: 12px;word-break: break-all;line-height: 26px;height: 100px;overflow-y: auto;padding:8px 12px 10px 0;.row {font-size: 12px;.row-value {color: #1fe2f3;word-break: break-all;}}&::-webkit-scrollbar {width: 8px;border-radius: 10px;background: #1fe2f3;}&::-webkit-scrollbar-track {border-radius: 10px;background-color: #091b32;border: 1px solid #091b32;}&::-webkit-scrollbar-thumb {border-radius: 10px;background-color: #1fe2f3;}}.content-bns {height: 160px;}}
}
.amap-info-close {top: 14px;right: 10px !important;font-size: 18px;color: #4ba9ef;
}
.amap-layers,.amap-overlays{z-index: 5;
}
</style>

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

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

相关文章

Vue加载序列帧动图

解读方法 使用<img :src"currentFrame" alt"加载中" /> 加载图片动态更改src的值使用 requestAnimationFrame 定时更新在需要的页面调用封装的组件 <LoadToast v-if"showLoading" /> 封装组件 <template><div class"…

python flask学生管理系统

预览 前端 jquery css html bootstrap: 4.x 后端 python: 3.6.x flask: 2.0.x 数据库 mysql: 5.7 学生管理模块 登录、退出查看个人信息、修改个人信息成绩查询查看已选课程选课、取消选课搜索课程课程列表分页功能 教师模块 登录、退出查看个人信息、修改个人信息录入…

论文笔记:信息融合的门控多模态单元(GMU)

整理了GMU&#xff08;ICLR2017 GATED MULTIMODAL UNITS FOR INFORMATION FUSION&#xff09;论文的阅读笔记 背景模型实验 论文地址&#xff1a; GMU 背景 多模态指的是同一个现实世界的概念可以用不同的视图或数据类型来描述。比如维基百科有时会用音频的混合来描述一个名人…

数据结构04附录01:字符串大写转小写[C++]

图源&#xff1a;文心一言 上机题目练习整理~&#x1f95d;&#x1f95d; 本篇作为字符串的代码补充&#xff0c;提供了3种&#xff08;差别并不大&#xff09;解法以及函数的详细解释&#xff0c;供小伙伴们参考~&#x1f95d;&#x1f95d; 前文&#xff1a;&#x1f338;…

WSL2 git clone命令无法克隆远程仓库

问题描述 最近在往WSL2里拉取git仓库的时候&#xff0c;突然出现了这个问题&#xff0c;WSL2无法连接到git服务器&#xff0c;导致代码无法拉取下来&#xff0c;可能是因为我最近不小心修改了windows的防火墙设置&#xff0c;导致出现了这个问题。 解决办法 在查阅了很多篇…

Angular系列教程之路由守卫

文章目录 前言路由守卫的类型CanLoadCanActivateCanActivateChildCanDeactivateResolve总结 前言 在Angular中&#xff0c;路由守卫是一个非常有用的功能&#xff0c;可以帮助我们控制用户在导航过程中的权限和访问限制。通过使用路由守卫&#xff0c;我们可以拦截导航并根据需…

2023年第十四届蓝桥杯软件赛省赛总评

报名明年4月蓝桥杯软件赛的同学们&#xff0c;如果你是大一零基础&#xff0c;目前懵懂中&#xff0c;不知该怎么办&#xff0c;可以看看本博客系列&#xff1a;备赛20周合集 20周的完整安排请点击&#xff1a;20周计划 每周发1个博客&#xff0c;共20周。 在QQ群上交流答疑&am…

python爬虫小练习——爬取豆瓣电影top250

爬取豆瓣电影top250 需求分析 将爬取的数据导入到表格中&#xff0c;方便人为查看。 实现方法 三大功能 1&#xff0c;下载所有网页内容。 2&#xff0c;处理网页中的内容提取自己想要的数据 3&#xff0c;导入到表格中 分析网站结构需要提取的内容 代码 import requests…

探索Python数据结构与算法:解锁编程的无限可能

文章目录 一、引言1.1 数据结构与算法对于编程的重要性1.2 Python作为实现数据结构与算法的强大工具 二、列表和元组2.1 列表&#xff1a;创建列表、索引、切片和常用操作2.2 元组&#xff1a;不可变序列的特性和使用场景 三、字符串操作和正则表达式3.1 字符串的常见操作和方法…

C++_模板的特化

目录 一、非类型模板参数 二、模板的特化 1、特化的概念 2、函数模板的特化 3、类模板的特化 3.1 偏特化 3.2 全特化 3.3 部分特化 结语&#xff1a; 前言&#xff1a; 大多数情况下模板可以解决许多重复性工作&#xff0c;因为把不同的类型传给模板参数后&#xff0…

散列函数,哈希表hash table

附上一句话&#xff1a;我知道大家可能曾经了解过这个散列表了&#xff0c;我发现&#xff0c;如果多看几个相关的视频&#xff0c;从不同的表述方式和不同的理解角度来理解这个问题&#xff0c;我会明白的更透彻&#xff0c;也有更多新的收获&#xff0c;尤其是对这个算法的应…

linux-nfc neard 编译与安装

项目github地址&#xff1a; https://github.com/linux-nfc/neard git clone地址&#xff1a; https://github.com/linux-nfc/neard.git clone完源码切换到目录neard里。这个项目需要依赖一下库&#xff1a; - GCC compiler - D-Bus library - GLib library - Netlink (lib…