hookehuyr

fix 完善步行导航功能-可以关闭导航,自动定位到当前位置

<!--
* @Date: 2023-05-19 14:54:27
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-06 12:14:54
* @LastEditTime: 2025-03-06 12:47:35
* @FilePath: /map-demo/src/views/by/map.vue
* @Description: 公众地图主体页面
-->
......@@ -55,6 +55,12 @@
关闭步行导航
</div>
<!-- 新增关闭导航按钮 -->
<div v-if="walking && !show_walk_route" class="walk-nav-text" @click="closeWalkingRoute">
关闭步行导航
</div>
<van-dialog v-model:show="dialog_show" title="温馨提示">
<div style="padding: 1rem; text-align: center;">{{ dialog_text }}</div>
</van-dialog>
......@@ -1021,6 +1027,11 @@ export default {
this.walking.search(start, end, (status, result) => {
if (status === 'complete') {
console.log('步行路线规划成功');
setTimeout(() =>{
// 定位到当前位置中心
this.getLocation();
this.show_walk_route = false;
},500)
} else {
console.error('步行路线规划失败:', status, result);
ElMessage.error('步行路线规划失败,请稍后重试');
......@@ -1043,6 +1054,21 @@ export default {
this.current_lat = '';
this.map.remove(this.location_marker); // 删除当前定位标记
},
closeWalkingRoute() {
if (this.walking) {
this.walking.clear(); // 清除路线
this.show_walk_route = true; // 恢复状态
// 可选:移除面板内容
document.getElementById('walking-panel').innerHTML = '';
// 显示提示
this.show_toast = true;
this.toast_text = '已关闭步行导航';
// 可选:重新定位到当前位置
this.getLocation();
}
},
}
}
</script>
......