修复地图定位bug
This commit is contained in:
@@ -19,15 +19,12 @@
|
||||
<cover-view class="map-side-controls" v-if="!props.hideControls && !props.hideMapOverlays">
|
||||
<cover-view class="side-btn locate" @tap="handleRelocate">
|
||||
<cover-image class="side-icon" src="/static/location.png"></cover-image>
|
||||
<!-- <cover-view class="side-text">定位</cover-view> -->
|
||||
</cover-view>
|
||||
<cover-view class="side-btn service" @tap="handleService">
|
||||
<cover-image class="side-icon" src="/static/customer-service.png"></cover-image>
|
||||
<!-- <cover-view class="side-text">客服</cover-view> -->
|
||||
</cover-view>
|
||||
<cover-view class="side-btn search" @tap="handleSearch">
|
||||
<cover-image class="side-icon" src="/static/other_device.png"></cover-image>
|
||||
<!-- <cover-view class="side-text">搜索</cover-view> -->
|
||||
</cover-view>
|
||||
|
||||
</cover-view>
|
||||
@@ -180,7 +177,6 @@
|
||||
// 移动地图到指定位置(直接更新地图中心坐标)
|
||||
const moveToLocation = (location) => {
|
||||
if (!location || !location.longitude || !location.latitude) {
|
||||
console.warn('moveToLocation: 无效的位置参数', location)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -188,9 +184,7 @@
|
||||
longitude: Number(location.longitude),
|
||||
latitude: Number(location.latitude)
|
||||
}
|
||||
|
||||
console.log('移动地图到:', newCenter)
|
||||
|
||||
|
||||
// 直接更新地图中心,触发地图组件的视图更新
|
||||
mapCenter.value = newCenter
|
||||
|
||||
@@ -207,7 +201,6 @@
|
||||
oldLocation.latitude !== newLocation.latitude
|
||||
|
||||
if (isChanged) {
|
||||
console.log('用户位置变化:', newLocation)
|
||||
mapCenter.value = {
|
||||
longitude: newLocation.longitude,
|
||||
latitude: newLocation.latitude
|
||||
@@ -234,25 +227,15 @@
|
||||
|
||||
// 地图区域变化事件(带防抖优化)
|
||||
const onMapRegionChange = (e) => {
|
||||
console.log('regionchange事件:', e)
|
||||
|
||||
// 只处理结束事件
|
||||
if (!e || e.type !== 'end') {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取事件原因
|
||||
// 微信小程序:e.causedBy 可能的值:
|
||||
// - 'gesture': 手势拖动
|
||||
// - 'scale': 缩放
|
||||
// - 'update': 调用更新接口(如 setCenterOffset 等)
|
||||
const causedBy = e.causedBy || e.detail?.causedBy
|
||||
|
||||
console.log('地图变化原因:', causedBy, '完整事件:', e)
|
||||
|
||||
// 只在用户手动操作(拖动或缩放)结束时触发查询
|
||||
// 排除程序调用(update)导致的变化,避免定位按钮触发多余查询
|
||||
if (causedBy === 'gesture' || causedBy === 'scale' || causedBy === 'drag') {
|
||||
if (causedBy === 'gesture' || causedBy === 'scale' || causedBy === 'drag'||causedBy==='update') {
|
||||
// 清除之前的定时器
|
||||
if (regionChangeTimer) {
|
||||
clearTimeout(regionChangeTimer)
|
||||
@@ -269,14 +252,13 @@
|
||||
latitude: Number(centerLocation.latitude)
|
||||
}
|
||||
|
||||
mapCenter.value = newCenter
|
||||
console.log('地图中心变化,触发查询:', newCenter, '原因:', causedBy)
|
||||
mapCenter.value = newCenter;
|
||||
|
||||
|
||||
// 触发父组件查询新位置的场地
|
||||
emit('mapCenterChange', newCenter)
|
||||
}, 500)
|
||||
} else {
|
||||
console.warn('未能从事件中获取中心点位置,尝试使用API获取')
|
||||
// 兜底方案:如果事件中没有centerLocation,才使用API获取
|
||||
regionChangeTimer = setTimeout(() => {
|
||||
if (mapContext.value) {
|
||||
@@ -288,7 +270,6 @@
|
||||
latitude: res.latitude
|
||||
}
|
||||
mapCenter.value = newCenter
|
||||
console.log('地图中心变化(API获取):', newCenter, '原因:', causedBy)
|
||||
emit('mapCenterChange', newCenter)
|
||||
}
|
||||
},
|
||||
@@ -299,9 +280,7 @@
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
} else {
|
||||
console.log('跳过查询,原因:', causedBy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 标记点点击事件
|
||||
@@ -505,7 +484,7 @@ const handleSearch = () => {
|
||||
|
||||
.center-marker-icon {
|
||||
width: 60rpx;
|
||||
height: 80rpx;
|
||||
height: 60rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user