Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
map-demo
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-03-06 12:17:22 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bde36ff89351218d9861062b1a920609ef115ea3
bde36ff8
1 parent
bddf4af7
fix 步行导航功能优化
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
74 deletions
.env
.eslintrc-auto-import.json
src/auto-imports.d.ts
src/views/by/info.vue
src/views/by/map.vue
.env
View file @
bde36ff
...
...
@@ -3,8 +3,8 @@ VITE_PORT = 8006
# 反向代理服务器地址
# VITE_PROXY_TARGET = https://oa-dev.onwall.cn
VITE_PROXY_TARGET = https://bm.jiqun.com
#
VITE_PROXY_TARGET = https://oa.onwall.cn
#
VITE_PROXY_TARGET = https://bm.jiqun.com
VITE_PROXY_TARGET = https://oa.onwall.cn
# API请求前缀
VITE_PROXY_PREFIX = /srv/
...
...
.eslintrc-auto-import.json
View file @
bde36ff
{
"globals"
:
{
"EffectScope"
:
true
,
"ElMessage"
:
true
,
"computed"
:
true
,
"createApp"
:
true
,
"customRef"
:
true
,
...
...
src/auto-imports.d.ts
View file @
bde36ff
...
...
@@ -2,6 +2,7 @@
export
{}
declare
global
{
const
EffectScope
:
typeof
import
(
'vue'
)[
'EffectScope'
]
const
ElMessage
:
typeof
import
(
'element-plus/es'
)[
'ElMessage'
]
const
computed
:
typeof
import
(
'vue'
)[
'computed'
]
const
createApp
:
typeof
import
(
'vue'
)[
'createApp'
]
const
customRef
:
typeof
import
(
'vue'
)[
'customRef'
]
...
...
src/views/by/info.vue
View file @
bde36ff
<!--
* @Date: 2024-09-15 22:08:49
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-06
09:50:03
* @LastEditTime: 2025-03-06
12:12:52
* @FilePath: /map-demo/src/views/by/info.vue
* @Description: 文件描述
-->
...
...
@@ -256,7 +256,7 @@ onMounted(async () => {
link: location.origin + location.pathname + location.hash, // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
imgUrl: '', // 分享图标
success: function () {
console.warn('设置成功');
//
console.warn('设置成功');
}
}
// 分享好友(微信好友或qq好友)
...
...
@@ -314,18 +314,6 @@ const goTo = () => { // 打开标记地图显示
}
const goToWalk = async () => { // 打开步行导航地图显示
// 没有关联导航提示
try {
const isLocationEnabled = await checkWxLocation();
if (!isLocationEnabled) {
// 提示用户开启定位
show_toast.value = true;
toast_text.value = '请开启手机定位功能';
return;
}
} catch (err) {
console.error('获取定位状态失败:', err);
}
//
if ($router.currentRoute.value.path === '/by/info') { // 详情页
$router.push({
...
...
@@ -483,24 +471,6 @@ const onStatusAudioList = (status) => { // 音频列表组件,状态改变
// show_audio.value = false;
// }
}
const checkWxLocation = () => {
return new Promise((resolve, reject) => {
wx.getLocation({
type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: (res) => {
resolve(true); // 已开启定位
},
fail: (err) => {
if (err.errMsg.indexOf('deny') > -1) {
resolve(false); // 未开启定位
} else {
reject(err); // 其他错误
}
}
});
});
}
</script>
<style lang="less">
...
...
src/views/by/map.vue
View file @
bde36ff
<!--
* @Date: 2023-05-19 14:54:27
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-06 1
0:36:30
* @LastEditTime: 2025-03-06 1
2:14:54
* @FilePath: /map-demo/src/views/by/map.vue
* @Description: 公众地图主体页面
-->
...
...
@@ -322,7 +322,7 @@ export default {
link: location.origin + location.pathname + location.hash, // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
imgUrl: '', // 分享图标
success: function () {
console.warn('设置成功');
//
console.warn('设置成功');
}
}
// 分享好友(微信好友或qq好友)
...
...
@@ -335,17 +335,17 @@ export default {
this.initMap();
// this.setMapBoundary();
// 使用之前获取当前地址,判断当前是否能够获取经纬度
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: (res) => {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
this.current_lng = GPS.gcj_encrypt(latitude, longitude).lon;
this.current_lat = GPS.gcj_encrypt(latitude, longitude).lat;
},
});
//
wx.getLocation({
//
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
//
success: (res) => {
//
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
//
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
//
var speed = res.speed; // 速度,以米/每秒计
//
var accuracy = res.accuracy; // 位置精度
//
this.current_lng = GPS.gcj_encrypt(latitude, longitude).lon;
//
this.current_lat = GPS.gcj_encrypt(latitude, longitude).lat;
//
},
//
});
// 设置贴片地图
this.setTitleLayer();
// 地图标题
...
...
@@ -548,8 +548,23 @@ export default {
if (marker_id) {
this.$nextTick(() => {
let marker = this.navBarList[0]['list'].filter(item => item.id == marker_id)
let path = marker[0].path;
this.addSafeRoute({name: '参观路径', path});
// let path = marker[0].path;
// this.addSafeRoute({name: '参观路径', path});
// TAG: 新增步行导航
let position = marker[0].position;
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: (res) => {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
this.current_lng = GPS.gcj_encrypt(latitude, longitude).lon;
this.current_lat = GPS.gcj_encrypt(latitude, longitude).lat;
this.onWalkRoute({point: position});
},
});
// 获取当前 URL 的查询参数
let query = { ...this.$route.query };
...
...
@@ -971,35 +986,47 @@ export default {
// panel: "panel"
// });
// 确保参数格式正确
const startPoint = [this.current_lng, this.current_lat]; // 起点
const endPoint = position.point; // 终点
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: (res) => {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
this.current_lng = GPS.gcj_encrypt(latitude, longitude).lon;
this.current_lat = GPS.gcj_encrypt(latitude, longitude).lat;
// 参数检查
if (!startPoint[0] || !startPoint[1]) {
this.show_toast = true;
this.toast_text = '无法获取当前位置,请确保已开启定位功能';
return;
}
// 确保参数格式正确
const startPoint = [this.current_lng, this.current_lat]; // 起点
const endPoint = position.point; // 终点
if (!endPoint[0] || !endPoint[1]) {
this.show_toast = true;
this.toast_text = '目的地坐标不完整';
return;
}
// 参数检查
if (!startPoint[0] || !startPoint[1]) {
this.show_toast = true;
this.toast_text = '无法获取当前位置,请确保已开启定位功能';
return;
}
// 转换为 LngLat 对象
const start = new AMap.LngLat(startPoint[0], startPoint[1]);
const end = new AMap.LngLat(endPoint[0], endPoint[1]);
if (!endPoint[0] || !endPoint[1]) {
this.show_toast = true;
this.toast_text = '目的地坐标不完整';
return;
}
// 规划步行路线
this.walking.search(start, end, (status, result) => {
if (status === 'complete') {
console.log('步行路线规划成功');
} else {
console.error('步行路线规划失败:', status, result);
ElMessage.error('步行路线规划失败,请稍后重试');
}
// 转换为 LngLat 对象
const start = new AMap.LngLat(startPoint[0], startPoint[1]);
const end = new AMap.LngLat(endPoint[0], endPoint[1]);
// 规划步行路线
this.walking.search(start, end, (status, result) => {
if (status === 'complete') {
console.log('步行路线规划成功');
} else {
console.error('步行路线规划失败:', status, result);
ElMessage.error('步行路线规划失败,请稍后重试');
}
});
},
});
},
handleLocation(status) { // 打开/关闭 当前定位
...
...
Please
register
or
login
to post a comment