|
|
@@ -827,7 +827,8 @@ export default {
|
|
|
if (!this.infoWindow) {
|
|
|
this.infoWindow = new this.AMap.InfoWindow({
|
|
|
isCustom: true,
|
|
|
- offset: new this.AMap.Pixel(0, -20)
|
|
|
+ offset: new this.AMap.Pixel(0, -20),
|
|
|
+ autoMove: false // 防止弹窗自动平移导致的中心点偏移
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -934,27 +935,55 @@ export default {
|
|
|
},
|
|
|
|
|
|
focusByLocation(targetPos) {
|
|
|
- if (!this.isMapReady() || !targetPos || targetPos.length !== 2) return;
|
|
|
+ if (!this.isMapReady() || !targetPos) return;
|
|
|
|
|
|
- let foundMarker = null;
|
|
|
+ // 如果是字符串坐标 "lng,lat",则解析
|
|
|
+ let pos = targetPos;
|
|
|
+ if (typeof targetPos === 'string') {
|
|
|
+ pos = targetPos.split(',').map(Number);
|
|
|
+ }
|
|
|
+ if (!Array.isArray(pos) || pos.length < 2) return;
|
|
|
+
|
|
|
+ const [targetLng, targetLat] = pos;
|
|
|
+ let bestMarker = null;
|
|
|
+ let minDistanceSq = Infinity;
|
|
|
+
|
|
|
+ // 遍历所有路由组,寻找离坐标点最近的标记
|
|
|
Object.values(this.routeGroups).forEach(group => {
|
|
|
- const marker = group.find(item => {
|
|
|
- if (!(item instanceof this.AMap.Marker)) return false;
|
|
|
- const pos = item.getExtData().position;
|
|
|
- return Math.abs(pos[0] - targetPos[0]) < 0.0001 && Math.abs(pos[1] - targetPos[1]) < 0.0001;
|
|
|
+ if (!Array.isArray(group)) return;
|
|
|
+ group.forEach(item => {
|
|
|
+ if (!(item instanceof this.AMap.Marker)) return;
|
|
|
+ const markerExt = item.getExtData();
|
|
|
+ const markerPos = markerExt.position;
|
|
|
+ if (!markerPos) return;
|
|
|
+
|
|
|
+ const dx = markerPos[0] - targetLng;
|
|
|
+ const dy = markerPos[1] - targetLat;
|
|
|
+ const distSq = dx * dx + dy * dy;
|
|
|
+
|
|
|
+ // 容差范围内(约 20 米),寻找最接近的点
|
|
|
+ if (distSq < 0.000001) {
|
|
|
+ // 优先规则:如果距离相同或非常接近,优先选择异常状态点(离线/降级/故障)
|
|
|
+ const isAbnormal = ["离线", "降级", "故障"].includes(markerExt.name);
|
|
|
+ const currentIsAbnormal = bestMarker ? ["离线", "降级", "故障"].includes(bestMarker.getExtData().name) : false;
|
|
|
+
|
|
|
+ if (distSq < minDistanceSq || (isAbnormal && !currentIsAbnormal)) {
|
|
|
+ minDistanceSq = distSq;
|
|
|
+ bestMarker = item;
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
- if (marker) foundMarker = marker;
|
|
|
});
|
|
|
|
|
|
- if (foundMarker) {
|
|
|
- const finalPos = foundMarker.getPosition();
|
|
|
+ if (bestMarker) {
|
|
|
+ const finalPos = bestMarker.getPosition();
|
|
|
this.map.setZoomAndCenter(17, finalPos, false, 500);
|
|
|
setTimeout(() => {
|
|
|
- if (!this.isComponentDestroyed) this.openLightInfo(foundMarker.getExtData(), finalPos);
|
|
|
+ if (!this.isComponentDestroyed) this.openLightInfo(bestMarker.getExtData(), finalPos);
|
|
|
}, 600);
|
|
|
} else {
|
|
|
// 如果找不到对应的标记,直接使用传入的坐标设置地图中心
|
|
|
- this.map.setZoomAndCenter(17, targetPos, false, 500);
|
|
|
+ this.map.setZoomAndCenter(17, [targetLng, targetLat], false, 500);
|
|
|
}
|
|
|
},
|
|
|
|