diff --git a/ln_jq_app/assets/html/map.html b/ln_jq_app/assets/html/map.html
index 4765faf..a4d16d3 100644
--- a/ln_jq_app/assets/html/map.html
+++ b/ln_jq_app/assets/html/map.html
@@ -195,10 +195,10 @@
@@ -244,6 +244,11 @@
}
});
+ // 点击地图空白处重置状态
+ map.on('click', function() {
+ resetSearchState();
+ });
+
// 添加基础控件
map.addControl(new AMap.Scale());
map.addControl(new AMap.ToolBar({
@@ -285,6 +290,19 @@
});
}
+ /**
+ * 重置搜索状态,隐藏面板和路线
+ */
+ function resetSearchState() {
+ if (document.body.classList.contains('panel-active')) {
+ console.log("JS->: 重置地图状态");
+ document.body.classList.remove('panel-active');
+ var panel = document.getElementById('panel');
+ panel.style.display = 'none';
+ if (driving) driving.clear();
+ }
+ }
+
/**
* 核心功能 1: 接收 Flutter 传来的定位数据
* Flutter 端调用: webViewController.evaluateJavascript("updateMyLocation(...)")
@@ -481,24 +499,30 @@
offset: new AMap.Pixel(-16, -32),
title: station.name,
label: {
- content: '' + station.name + '
',
+ content: '' + station.name +
+ '
',
direction: 'top'
}
});
// 3. 绑定点击事件:选中即为目的地,并开始规划
- sMarker.on('click', function() {
- document.getElementById('endInput').value = station.address || station.name;
- // 更新当前的 destMarker (如果需要)
- if (destMarker) destMarker.setMap(null);
+ sMarker.on('click', function () {
+ var stationName = station.name || "目的地";
+ document.getElementById('endInput').value = station.address ||
+ stationName;
+
+ // 更新当前的 destMarker
+ if (destMarker && destMarker !== sMarker) destMarker.setMap(null);
destMarker = sMarker;
- startRouteSearch();
+ // 直接传入坐标对象,避免关键字搜索失败
+ var loc = new AMap.LngLat(station.longitude, station.latitude);
+ startRouteSearch(loc);
});
stationMarkers.push(sMarker);
});
-
+
} else {
console.log("JS->: 业务报错或无数据:", res.message);
}
@@ -554,11 +578,12 @@
}
}
+
/**
- * 路径规划
+ * 路径规划
+ * @param {AMap.LngLat} [destLoc] 可选的终点坐标
*/
- function startRouteSearch() {
- // 获取输入框的文字
+ function startRouteSearch(destLoc) {
var startKw = document.getElementById('startInput').value;
var endKw = document.getElementById('endInput').value;
@@ -566,28 +591,21 @@
alert("请输入起点");
return;
}
-
if (!endKw) {
alert("请输入终点");
return;
}
- // 清除旧路线
if (driving) driving.clear();
-
- // 收起键盘
document.getElementById('startInput').blur();
document.getElementById('endInput').blur();
- // --- 构造路径规划的点 ---
var points = [];
- // 1. 处理起点逻辑
+ // 1. 起点逻辑
if (!startKw || startKw === '我的位置' || startKw.includes('当前位置')) {
if (!currentLng || !currentLat) {
- if (window.flutter_inappwebview) {
- window.flutter_inappwebview.callHandler('requestLocation');
- }
+ if (window.flutter_inappwebview) window.flutter_inappwebview.callHandler('requestLocation');
alert("正在获取定位,请稍后...");
return;
}
@@ -601,10 +619,17 @@
});
}
- // 2. 处理终点逻辑
- points.push({
- keyword: endKw
- });
+ // 2. 终点逻辑:如果有传入坐标,则直接使用坐标导航,成功率最高
+ if (destLoc) {
+ points.push({
+ keyword: endKw,
+ location: destLoc // 关键:使用精确坐标
+ });
+ } else {
+ points.push({
+ keyword: endKw
+ });
+ }
// 3. 发起搜索
driving.search(points, function (status, result) {
@@ -613,10 +638,12 @@
var panel = document.getElementById('panel');
panel.style.display = 'block';
document.body.classList.add('panel-active');
- } else {
- console.log('JS: 规划失败', result);
- alert("规划失败,请检查起终点名称");
}
+ // else {
+ // console.error('JS: 规划失败', result);
+ // // 如果坐标规划都失败了,通常是由于起终点距离过近或政策限制(如货车禁行)
+ // alert("路径规划未成功,请尝试微调起终点");
+ // }
});
}
@@ -641,4 +668,4 @@