Commit b79efadb by liimin

fix(zoneCar): 修复地址为空时未设置默认值的问题并优化坐标转换

- 为地址字段添加空值处理,防止undefined错误
- 新增AMapPoint2BMapPoint方法处理坐标转换
- 移除冗余的clearOverlays调用
- 优化区域查车功能中的坐标转换逻辑
1 parent 8883e6e5
...@@ -241,7 +241,7 @@ export default { ...@@ -241,7 +241,7 @@ export default {
AMap.invoke("autocompleteShow"); AMap.invoke("autocompleteShow");
AMap.invoke("autocompleteAddEventListener", "onconfirm", (e) => { AMap.invoke("autocompleteAddEventListener", "onconfirm", (e) => {
this.poi = e.item.value; this.poi = e.item.value;
this.$set(this.form, "address", this.poi.address); this.$set(this.form, "address", this.poi.address||'');
this.$refs.addressInput.focus(); this.$refs.addressInput.focus();
}); });
...@@ -570,15 +570,21 @@ export default { ...@@ -570,15 +570,21 @@ export default {
}); });
}, },
// 将坐标转换封装为返回 Promise 的函数 // 将坐标转换封装为返回 Promise 的函数
convertCoordinate(item) { convertCoordinate(item) {
item = item.split(",") item = item.split(",")
return new Promise((resolve) => { return new Promise((resolve) => {
AMap.invoke('Convertor', [AMap.invoke('Point', item[0], item[1])], 5, 3, res => { AMap.invoke('Convertor', [AMap.invoke('Point', item[0], item[1])], 5, 3, res => {
const convertedPoint = res.points.length ? res.points[0] : item;
resolve(convertedPoint);
});
});
},
AMapPoint2BMapPoint(AMapPoint,callback) {
AMap.invoke('Convertor', [AMap.invoke('Point', AMapPoint.lng, AMapPoint.lat)], 3, 5, res => {
const convertedPoint = res.points.length ? res.points[0] : item; const convertedPoint = res.points.length ? res.points[0] : item;
resolve(convertedPoint); callback(convertedPoint);
}); });
}); },
},
// 区域查车 // 区域查车
async getAreaLocation() { async getAreaLocation() {
let _this = this; let _this = this;
...@@ -594,7 +600,7 @@ convertCoordinate(item) { ...@@ -594,7 +600,7 @@ convertCoordinate(item) {
_this.deviceList = []; _this.deviceList = [];
if (_this.mapMass) { if (_this.mapMass) {
AMap.invoke("clearOverlays"); // AMap.invoke("clearOverlays");
_this.mapMass = null; _this.mapMass = null;
} }
if (_options.type != "full") { if (_options.type != "full") {
...@@ -640,15 +646,17 @@ convertCoordinate(item) { ...@@ -640,15 +646,17 @@ convertCoordinate(item) {
let k = arr[i]; let k = arr[i];
console.log(k); console.log(k);
let lnglat = mapService.getLngLat(k.lng, k.lat); let lnglat = mapService.getLngLat(k.lng, k.lat);
let marker = mapService.createCarMarker(lnglat); this.AMapPoint2BMapPoint(lnglat,(carPoint)=>{ //写死了 高德地图转百度地图 TODO: 动态判断
markers.push(marker); let marker = mapService.createCarMarker(carPoint);
AMap.invoke("addOverlay", marker); markers.push(marker);
AMap.invoke("panTo", lnglat); AMap.invoke("addOverlay", marker);
AMap.invoke("markerAddEventListener", "click", (e) => { AMap.invoke("panTo", lnglat);
console.log(e); AMap.invoke("markerAddEventListener", "click", (e) => {
let infoWindow = mapService.createAraeInfowindow(k); console.log(e);
AMap.invoke("mapOpenInfoWindow", infoWindow, e.target.getPosition()); let infoWindow = mapService.createAraeInfowindow(k);
}); AMap.invoke("mapOpenInfoWindow", infoWindow, e.target.getPosition());
});
})
} }
this.drawDone = true; this.drawDone = true;
// if (arr && arr.length < 10) { // if (arr && arr.length < 10) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!