diff --git a/src/views/iotDevice/MapDIalog.vue b/src/views/iotDevice/MapDIalog.vue
index 3b1bcdbf..f3168d54 100644
--- a/src/views/iotDevice/MapDIalog.vue
+++ b/src/views/iotDevice/MapDIalog.vue
@@ -8,12 +8,12 @@
@close="handleCloseDialog"
destroy-on-close
>
-
-
-
-
-
-
+
+
+
+
+
+
@@ -38,8 +38,8 @@ export default {
return {
map: null,
trackAni: null,
- calLon: 116.404, // 默认北京经度
- calLat: 39.915, // 默认北京纬度
+ calLon: 116.404, // 默认北京经度(兜底值)
+ calLat: 39.915, // 默认北京纬度(兜底值)
requestParams: {
beginTime: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
endTime: moment().format('YYYY-MM-DD HH:mm:ss'),
@@ -66,7 +66,8 @@ export default {
async initPage() {
this.initMap();
},
- /** 初始化百度地图(增加双重校验) */
+
+ /** 初始化百度地图(增加双重校验 + 中心点兜底) */
initMap() {
this.$nextTick(() => {
// 校验1:百度地图SDK是否加载成功
@@ -78,10 +79,24 @@ export default {
const container = document.getElementById('container');
if (!container) return;
+ // ---------- 核心改造:地图中心点兜底逻辑 ----------
+ let targetLon = this.calLon; // 初始化经度为兜底值
+ let targetLat = this.calLat; // 初始化纬度为兜底值
+ // 仅当address非空时,才尝试解析经纬度
+ if (this.address && this.address.trim() !== '') {
+ const [lon, lat] = this.address.split(',');
+ // 校验:解析后的经纬度必须是有效数字(排除空、字符串、NaN等情况)
+ if (lon && lat && !isNaN(Number(lon)) && !isNaN(Number(lat))) {
+ targetLon = Number(lon);
+ targetLat = Number(lat);
+ }
+ }
+ // ---------------------------------------------------
+
// 创建地图实例
this.map = new window.BMapGL.Map(container);
- // 设备实际位置中心点
- const centerPoint = new window.BMapGL.Point(this.address.split(',')[0], this.address.split(',')[1]);
+ // 设备实际位置中心点(解析成功用实际值,失败用兜底值)
+ const centerPoint = new window.BMapGL.Point(targetLon, targetLat);
// 初始化地图:中心点 + 缩放级别
this.map.centerAndZoom(centerPoint, 15);
// 启用滚轮缩放
@@ -89,7 +104,7 @@ export default {
// 地图视角设置
this.map.setHeading(64.5);
this.map.setTilt(73);
- // 添加设备位置标记
+ // 添加设备位置标记(跟随兜底中心点)
const marker = new window.BMapGL.Marker(centerPoint);
this.map.addOverlay(marker);
});
diff --git a/src/views/rentEquipmentManager/index.vue b/src/views/rentEquipmentManager/index.vue
index 2904670b..0525df25 100644
--- a/src/views/rentEquipmentManager/index.vue
+++ b/src/views/rentEquipmentManager/index.vue
@@ -162,7 +162,7 @@
-
+
-
+
-