Commit b79efadb by liimin

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

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