Browse Source

Merge remote-tracking branch 'origin/dev' into dev

yangyuxuan 4 months ago
parent
commit
cba996dece

+ 32 - 2
src/utils/olMap/olMap.ts

@@ -1,6 +1,7 @@
 // 引入OpenLayers的主模块
 import Map from 'ol/Map';
 import View from 'ol/View';
+import TileState from 'ol/TileState'
 import Feature from 'ol/Feature';
 import Point from 'ol/geom/Point';
 import VectorLayer from 'ol/layer/Vector';
@@ -38,6 +39,7 @@ import { createBox } from 'ol/interaction/Draw';
 import * as turf from '@turf/turf';
 import { nanoid } from 'nanoid';
 import carImg from '@/assets/images/car.png';
+import { globalHeaders } from '@/utils/request';
 
 const tk = 'a8df87f1695d224d2679aa805c1268d9';
 const commonUrl = import.meta.env.VITE_APP_BASE_API2 + 'api/oneShare/proxyHandler/gd/';
@@ -253,7 +255,9 @@ export class olMap {
 
   // 请求接口获取地图信息
   getCapabilities(code) {
-    return axios.get(commonUrl + code + '?SERVICE=WMTS&REQUEST=GetCapabilities');
+    return axios.get(commonUrl + code + '?SERVICE=WMTS&REQUEST=GetCapabilities', {
+      headers: globalHeaders()
+    });
   }
 
   // 请求地图图片加载图层
@@ -270,7 +274,33 @@ export class olMap {
         origin: getTopLeft(projectionExtent),
         resolutions: resolutions,
         matrixIds: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21']
-      })
+      }),
+      // 关键修改:自定义瓦片加载函数
+      tileLoadFunction: function (tile, src) {
+        const xhr = new XMLHttpRequest();
+        xhr.open('GET', src);
+
+        // 添加自定义 Headers
+        const headers = globalHeaders()
+        xhr.setRequestHeader('Authorization', headers.Authorization);
+        xhr.setRequestHeader('clientid', headers.clientid);
+
+        xhr.responseType = 'arraybuffer'; // 确保支持图片二进制数据
+        xhr.onload = function () {
+          if (xhr.status === 200) {
+            const type = xhr.getResponseHeader('Content-Type');
+            const blob = new Blob([xhr.response], { type: type });
+            const url = window.URL.createObjectURL(blob);
+            tile.getImage().src = url; // 将图像数据绑定到瓦片
+          } else {
+            tile.setState(TileState.ERROR); // 处理请求失败
+          }
+        };
+        xhr.onerror = function () {
+          tile.setState(TileState.ERROR);
+        };
+        xhr.send();
+      }
     });
     const layer = new TileLayer({
       name: code,

+ 11 - 6
src/views/globalMap/RightMenu/DrawTools.vue

@@ -226,9 +226,7 @@ const onDraw = (event) => {
   commit(deepClone(overlaysData));
   // 右击进入编辑
   obj.on('rightclick', handleRightClick);
-  if (overlaysData.length === 1) {
-    analysisSpatial(data);
-  }
+  analysisSpatial(data);
   // 点击空间分析
   obj.on('click', function () {
     // 没在编辑时
@@ -268,9 +266,7 @@ const onDraw2 = (event) => {
   // 右击进入编辑
   let map = getMap();
   map.on('contextmenu', handleRightClick2);
-  if (overlaysData.length === 1) {
-    analysisSpatial(data);
-  }
+  analysisSpatial(data);
 };
 let rightClickObj;
 // 图形右击事件
@@ -497,6 +493,15 @@ onMounted(() => {
   }
 });
 onBeforeUnmount(() => {
+  if (overlays && overlays.length > 0) {
+    overlays.forEach((overlay) => {
+      if (AMapType.includes(props.activeMap)) {
+        overlay.setMap(null);
+      } else {
+        mapUtils.value.getDrawVector().getSource().removeFeature(overlay);
+      }
+    });
+  }
   if (!AMapType.includes(props.activeMap)) {
     map.value.un('click', onMapClick);
   }

+ 12 - 2
src/views/globalMap/RightMenu/index.vue

@@ -204,7 +204,7 @@ const handleMenu = (name, data) => {
   }
 };
 // 新增菜单 type 1 新增 2 删除
-const updateMenu = (type, menu, location?: any) => {
+const updateMenu = (type, menu, newLocation?: any) => {
   if (type === '1') {
     if (menu.name === '图层分析') {
       let index = menuState.menuData.findIndex((item) => {
@@ -215,7 +215,7 @@ const updateMenu = (type, menu, location?: any) => {
       }
     } else if (menu.name === '定点分析') {
       menuState.menuData.push(menu);
-      location2.value = location;
+      location2.value = newLocation;
     } else {
       menuState.menuData.push(menu);
     }
@@ -226,6 +226,16 @@ const updateMenu = (type, menu, location?: any) => {
       menuState.menuData.splice(index, 1);
       menuState.activeIndex = 0;
     }
+    if (menu.name === '空间分析') {
+      location.value = [];
+    }
+  } else if (type === '4') {
+    let index = menuState.menuData.findIndex((item) => item.name === menu.name);
+    if (index > -1) {
+      menuState.menuData.splice(index, 1);
+      menuState.activeIndex = 0;
+    }
+    location2.value = newLocation;
   }
 };
 const getMenuState = () => {