Hwf 4 ماه پیش
والد
کامیت
34529e0b24
2فایلهای تغییر یافته به همراه25 افزوده شده و 15 حذف شده
  1. 19 14
      src/hooks/AMap/useAMap.ts
  2. 6 1
      src/utils/olMap/olMap.ts

+ 19 - 14
src/hooks/AMap/useAMap.ts

@@ -143,7 +143,7 @@ export function useAMap(options) {
     }
     addMarker([item], true);
     clickMarker = item;
-    options.onMarkerClick(item);
+    options.onMarkerClick(item, true);
   };
   // 添加多个点
   const addMarker = (points, notClean?: boolean) => {
@@ -324,7 +324,7 @@ export function useAMap(options) {
             }
           }
           clickMarker = e.target;
-          options.onMarkerClick(extData);
+          options.onMarkerClick(extData, true);
         });
         plotLayers['points2'].addOverlay(marker);
         addPoints.push(data);
@@ -411,24 +411,28 @@ export function useAMap(options) {
     infoWindow.on('mouseout', () => map.setStatus({ zoomEnable: true }));
   };
 
-  const hideInfo = (e?: any) => {
+  const hideInfo = (flag?: any) => {
     map.setStatus({ zoomEnable: true });
     if (!!infoWindow) {
       infoWindow.close();
-      if (!!clickMarker && e) {
-        const extData = clickMarker.getExtData ? clickMarker.getExtData() : clickMarker;
-        for (let i = 0; i < addPoints.length; i++) {
-          if (addPoints[i].id === extData.id) {
-            addPoints[i].icon = addPoints[i].image;
-            clickMarker.setContent(getContent(addPoints[i].icon, addPoints[i].size));
-            clickMarker = null;
-            // addMarker(addPoints);
-            break;
-          }
-        }
+      if (flag) {
+        clearHoverMarker();
       }
     }
   };
+  const clearHoverMarker = () => {
+    if (!!clickMarker) {
+      const extData = clickMarker.getExtData ? clickMarker.getExtData() : clickMarker;
+      for (let i = 0; i < addPoints.length; i++) {
+        if (addPoints[i].id === extData.id) {
+          addPoints[i].icon = addPoints[i].image;
+          clickMarker.setContent(getContent(addPoints[i].icon, addPoints[i].size));
+          clickMarker = null;
+          break;
+        }
+      }
+    }
+  }
   let maskPolygon;
   const creatMask = (options, name = '茂名市') => {
     new AMap.DistrictSearch({
@@ -805,6 +809,7 @@ export function useAMap(options) {
     getScale,
     showInfo,
     hideInfo,
+    clearHoverMarker,
     creatMask,
     removeMask,
     creatMask2,

+ 6 - 1
src/utils/olMap/olMap.ts

@@ -989,7 +989,12 @@ export class olMap {
   hideInfo(flag?: boolean) {
     this.map.removeOverlay(this.infoWindow);
     this.infoWindow = null;
-    if (!!flag && this.clickMarker) {
+    if (!!flag) {
+      this.clearHoverMarker();
+    }
+  }
+  clearHoverMarker() {
+    if (this.clickMarker) {
       const selectData = this.clickMarker.get('extData');
       this.clickMarker.setStyle(
           new Style({