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

微信小程序map组件所有markers展示在视野范围内

 注意:使用include-points属性不生效,要通过createMapContext实现

<template><view class="map-box"><map id="map" class="map" :markers="markers" :enable-traffic="true" :enable-poi="true"></map><view class="bottom"><view @click="choose" style="text-align: center;">选择位置</view></view></view>
</template><script>export default {name: "ty-wx-map",data() {return {markers: [{id: 1,callout: {content: '北湖湿地',padding: 10,borderRadius: 2,display: 'ALWAYS'},latitude: 43.983281,longitude: 125.368689,iconPath: '../../static/Marker1_Activated@3x.png',width: '68rpx',height: '68rpx',rotate: 0,alpha: 1}, {id: 2,callout: {content: '南溪湿地',padding: 10,borderRadius: 2,display: 'ALWAYS'},latitude: 43.810332,longitude: 125.354891,iconPath: '../../static/Marker1_Activated@3x.png',width: '68rpx',height: '68rpx',rotate: 0,alpha: 1}, {id: 3,callout: {content: '西湖公园',padding: 10,borderRadius: 2,display: 'ALWAYS'},latitude: 43.873167,longitude: 125.162295,iconPath: '../../static/Marker1_Activated@3x.png',width: '68rpx',height: '68rpx',rotate: 0,alpha: 1}]};},mounted() {this.setMap()},methods: {choose() {const that = thisuni.chooseLocation({success: function(res) {console.log('位置名称:' + res.name);console.log('详细地址:' + res.address);console.log('纬度:' + res.latitude);console.log('经度:' + res.longitude);that.markers.push({id: that.markers.length + 1,callout: {content: res.name,padding: 10,borderRadius: 2,display: 'ALWAYS'},latitude: res.latitude,longitude: res.longitude,iconPath: '../../static/Marker1_Activated@3x.png',width: '68rpx',height: '68rpx',rotate: 0,alpha: 1})that.setMap()}});},setMap() {const mapCtx = wx.createMapContext('map', this);mapCtx.includePoints({points: this.markers,padding: [36, 36, 10, 36]})}}}
</script><style scoped lang="scss">.map-box {position: absolute;width: 100%;z-index: 1;background-color: #fff;.map {width: 100%;height: 60vh;position: fixed;}.bottom {position: relative;z-index: 2;margin-top: calc(60vh - 24rpx);width: 100%;background-color: #fff;border-radius: 24rpx 24rpx 0 0;padding-bottom: env(safe-area-inset-bottom);}}
</style>

展示效果

点击选择位置,会把新选择的位置追加到地图markers并显示在视野范围内

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

相关文章:

  • 深度解析 tanh ⁡ tanh 激活函数
  • 嵌入式入门Day38
  • 探索Rancher服务发现机制:容器世界的“导航仪”
  • 【ROS2】Qt事件循环和ROS2订阅机制一起使用有什么注意事项?
  • donet (MVC)webAPI 的接受json 的操作
  • Qt 界面外观
  • aws(学习笔记第二十二课) 复杂的lambda应用程序(python zip打包)
  • HTML课堂之搜索工具箱/讲师duluo
  • 当歌 - RSS 订阅分发平台开发
  • 学习threejs,导入wrl格式的模型
  • 使用GitLab+Jenkins搭建CICD执行环境
  • 使用vue-pdf预览pdf和解决pdf电子签章显示问题
  • 【Rust自学】11.3. 自定义错误信息
  • 05、Docker学习,常用安装:Mysql、Redis、Nginx、Nacos
  • RabbitMQ高级篇之MQ可靠性 数据持久化
  • leetcode 2274. 不含特殊楼层的最大连续楼层数 中等
  • Tauri教程-基础篇-第二节 Tauri的核心概念上篇
  • 大风车excel:怎么把题库导入excel?题库导入excel
  • Java 兼容读取WPS和Office图片,结合EasyExcel读取单元格信息
  • 电脑硬盘系统迁移及问题处理
  • 网关 + Nacos配置管理
  • 《Spring Framework实战》6:核心技术 4.1.IoC 容器
  • ModuleNotFoundError: No module named ‘audioop‘
  • STM32-笔记38-I2C-oled实验
  • 人大金仓实现主键自增.
  • h264之多视点mvc编码及解码过程(JMVC平台举例)
  • 小程序学习08—— 系统参数获取和navBar组件样式动态设置
  • 数据库环境安装(day1)
  • 网络安全-web渗透环境搭建-BWAPP(基础篇)
  • 当算法遇到线性代数(三):实对称矩阵