uniapp地图组件拖拽生成圆形区域,返回中心点和半径,适配微信小程序
1条回答 默认 最新
- 桃宝护卫队 2023-04-09 11:27关注
有用的话,请采纳哇,这对我很重要!!!
<template> <div class="map"> <map :scale="scale" :markers="markers" @tap="onTap" @regionchange="onRegionChange"></map> </div> </template> <script> export default { data() { return { scale: 16, // 地图缩放级别 markers: [], // 地图标记 centerLatitude: '', // 圆心纬度 centerLongitude: '', // 圆心经度 radius: '', // 圆半径 circleMarker: null // 圆形标记 } }, methods: { onTap(event) { // 生成圆形标记 this.generateCircle(event) }, onRegionChange(event) { // 拖拽地图时更新圆形标记 this.updateCircle(event) }, generateCircle(event) { // 获取点击位置的经纬度 const latitude = event.detail.latitude const longitude = event.detail.longitude // 设置圆心坐标 this.centerLatitude = latitude this.centerLongitude = longitude // 创建圆形标记 const circleMarker = { id: 1, latitude: latitude, longitude: longitude, iconPath: '/static/images/circle.png', // 圆形图标路径 width: 30, height: 30 } this.circleMarker = circleMarker // 添加圆形标记 const markers = [...this.markers, circleMarker] this.markers = markers }, updateCircle(event) { // 获取拖拽后的地图中心坐标 const latitude = event.detail.latitude const longitude = event.detail.longitude // 计算圆半径 const radius = this.calculateRadius() // 更新圆形标记 const circleMarker = { ...this.circleMarker, latitude: latitude, longitude: longitude, width: radius * 2, height: radius * 2 } this.circleMarker = circleMarker // 更新圆半径 this.radius = radius }, calculateRadius() { // 计算圆半径 const pixelRatio = uni.getSystemInfoSync().pixelRatio // 设备像素比 const mapWidth = uni.getSystemInfoSync().windowWidth * pixelRatio // 地图宽度 const circleWidth = this.circleMarker.width // 圆形图标宽度 const ratio = circleWidth / mapWidth const radius = (1 / ratio) / 2 return radius } } } </script> <style> .map { width: 100%; height: 100%; } </style>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥16 mybatis的代理对象无法通过@Autowired装填
- ¥15 可见光定位matlab仿真
- ¥15 arduino 四自由度机械臂
- ¥15 wordpress 产品图片 GIF 没法显示
- ¥15 求三国群英传pl国战时间的修改方法
- ¥15 matlab代码代写,需写出详细代码,代价私
- ¥15 ROS系统搭建请教(跨境电商用途)
- ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。