当前位置: 首页 > news >正文

uniapp移动端地图,点击气泡弹窗并实现精准定位

记录移动端地图map组件的使用

需求记录:

移动端地图部分需要展示两个定位点,上报点及人员定位点。通过右上角的两个按钮实现地图定位。点击对应定位气泡,弹出定位点的信息。

效果图如下:

map在nvue中的使用。直接用nvue可以直接调整层级,可以覆盖住map组件。在map组件上添加按钮控制,实现交互。map组件内添加按钮使用cover-image如下:

<view><map id="map" class="map" :scale="15" ref="map" style="width:320px;height:500px;margin-left: 30px;":latitude="latitude" :longitude="longitude" :markers="cover"><view class="btnStyle"><cover-image src="../../static/images/people.png" class="removeToReal" @tap="removeToReal"></cover-image><cover-image src="../../static/images/gaodeMap.png" style="margin-top: 18px;" class="removeToMap" @tap="removeToMap"></cover-image></view></map>
</view>

js部分:

<script>export default {data() {return {// 地图mapContext: null,latitude: null,longitude: null,latitudeReal: null,longitudeReal: null,cover: [],}},methods: {//  移动到对应点坐标removeToReal() {this.mapContext.moveToLocation({latitude: this.latitudeReal,longitude: this.longitudeReal});},//  移动到对应点坐标removeToMap() {this.mapContext.moveToLocation({latitude: this.latitude,longitude: this.longitude});},// 关键代码:// 加载坐标点及气泡。(data参数中包含了所需的所有数据,以下仅为气泡弹窗的代码示例参考)async setMarkers(data) {let latlng = JSON.parse(data.inspectorLocation)let reallatlngTurn = this.wgs84_gcj02(latlng[0],latlng[1])let realatlng = JSON.parse(data.inspectorRealsite)let realTurn = this.wgs84_gcj02(realatlng[0],realatlng[1])this.longitude = reallatlngTurn[0]this.latitude = reallatlngTurn[1]this.longitudeReal = realTurn[0]this.latitudeReal = realTurn[1]let markers = []let markerInspector = {id: 'id_' + 'inspectorLocation',latitude: reallatlngTurn[1],longitude: reallatlngTurn[0],width: 30,height: 35,iconPath: '../../static/images/position2.png',callout:{//自定义标记点上方的气泡窗口 点击有效  content: `                     上报点任务单号:${data.taskSn}任务类型:外部任务派发时间:${data.dispatchTime.slice(0,10)}上报人:    ${data.inspectorName}经度:       ${latlng[0].toFixed(6)}纬度:       ${latlng[1].toFixed(6)}`,//文本color: '#ffffff',//文字颜色fontSize: 14,//文本大小borderRadius: 15,//边框圆角borderWidth: '10',padding: '10',textAlign: 'left',bgColor: '#e51860',//背景颜色display: 'BYCLICK',//常显}}markers.push(markerInspector)let markerReal = {id: 'id_' + 'realLocation',latitude: realTurn[1],longitude: realTurn[0],callout:{//自定义标记点上方的气泡窗口 点击有效content: `                     定位点任务单号:${data.taskSn}任务类型:外部任务上报人:    ${data.inspectorName}角色:       ${people}派发时间:${data.dispatchTime.slice(0,10)}经度:       ${realatlng[0]}纬度:       ${realatlng[1]}`,//文本color: '#ffffff',//文字颜色fontSize: 14,//文本大小borderRadius: 15,//边框圆角borderWidth: '10',padding: '10',textAlign: 'left',bgColor: '#e51860',//背景颜色display: 'BYCLICK',//常显}}markers.push(markerReal)this.cover=markers},onLoad(options) {this.mapContext = uni.createMapContext("map", this);}
</scritpt>

 

http://www.lryc.cn/news/154577.html

相关文章:

  • 2023牛客暑期多校训练营7 CI「位运算」「根号分治+容斥」
  • YOLOv5算法改进(10)— 替换主干网络之GhostNet
  • Android Canvas的使用
  • AI批量写文章伪原创:基于ChatGPT长文本模型,实现批量改写文章、批量回答问题(长期更新)
  • git常用场景记录 | 拉取远程分支A合并到本地分支B - 删除上一次的commit
  • 源码角度解析SpringBoot 自动配置
  • 【原创】H3C路由器OSPF测试
  • 计算机视觉:轨迹预测综述
  • 三维跨孔电磁波CT数据可视化框架搭建
  • OC和Swift混编,导入头文件‘xxx-Swift.h‘ file not found
  • 一文读懂HOOPS Native平台:快速开发桌面端、移动端3D应用程序!
  • Scrum工作模式及Scrum工具
  • [ros][ubuntu]ros在ubuntu18.04上工作空间创建和发布一个话题
  • 我的区块链笔记
  • Spring事务(ACID特性、隔离级别、传播机制、失效场景)
  • 机器学习笔记之最优化理论与方法(六)无约束优化问题——最优性条件
  • E5061B/是德科技keysight E5061B网络分析仪
  • 2.4 PE结构:节表详细解析
  • Vue2项目练手——通用后台管理项目第五节
  • 软件工程学术顶会——ESEC/FSE 2022 议题(网络安全方向)清单、摘要与总结
  • 从C语言到C++_36(智能指针RAII)auto_ptr+unique_ptr+shared_ptr+weak_ptr
  • C++信息学奥赛1187:统计字符数
  • 计算机毕设 大数据商城人流数据分析与可视化 - python 大数据分析
  • vscode上搭建go开发环境
  • 10.(Python数模)(预测模型二)LSTM回归网络(1→1)
  • mac常见问题(五) Mac 无法开机
  • WebSocket与SSE区别
  • Qt鼠标点击事件处理:显示鼠标点击位置(完整示例)
  • OpenCV:实现图像的负片
  • HZOJ#237. 递归实现排列型枚举