Browse Source

轨迹自动聚焦

李富豪 1 year ago
parent
commit
4b2169318a
2 changed files with 13 additions and 45 deletions
  1. 12 44
      Web/src/hooks/use-g-map-cover.ts
  2. 1 1
      Web/src/hooks/use-g-map-trajectory.ts

+ 12 - 44
Web/src/hooks/use-g-map-cover.ts

@@ -168,56 +168,24 @@ export function useGMapCover() {
   }
 
   function updatePinElement(id: string, name: string, coordinates: GeojsonCoordinate, color?: string) {
-    const elements = getElementFromMap(id)
-    const textElements = getElementFromMap(id + '_text')
-    if (elements && elements.length > 0) {
-      const element = elements[0]
-      const icon = getPinIcon(color)
-      element.setPosition(new AMap.LngLat(coordinates[0], coordinates[1]))
-      element.setIcon(icon)
-      element.setTitle(name)
-      textElements[0].setText(name)
-    } else {
-      init2DPin(name, coordinates, color, {
-        id: id,
-        name: name
-      })
-    }
+    init2DPin(name, coordinates, color, {
+      id: id,
+      name: name
+    })
   }
 
   function updatePolylineElement(id: string, name: string, coordinates: GeojsonCoordinate[], color?: string) {
-    const elements = getElementFromMap(id)
-    const textElements = getElementFromMap(id + '_text')
-    if (elements && elements.length > 0) {
-      const element = elements[0]
-      const options = element.getOptions()
-      options.strokeColor = color || normalColor
-      element.setOptions(options)
-      textElements[0].setText(name)
-    } else {
-      initPolyline(name, coordinates, color, {
-        id: id,
-        name: name
-      })
-    }
+    initPolyline(name, coordinates, color, {
+      id: id,
+      name: name
+    })
   }
 
   function updatePolygonElement(id: string, name: string, coordinates: GeojsonCoordinate[][], color?: string) {
-    const elements = getElementFromMap(id)
-    const textElements = getElementFromMap(id + '_text')
-    if (elements && elements.length > 0) {
-      const element = elements[0]
-      const options = element.getOptions()
-      options.fillColor = color || normalColor
-      options.strokeColor = color || normalColor
-      element.setOptions(options)
-      textElements[0].setText(name)
-    } else {
-      initPolygon(name, coordinates, color, {
-        id: id,
-        name: name
-      })
-    }
+    initPolygon(name, coordinates, color, {
+      id: id,
+      name: name
+    })
   }
 
   function initTextInfo(content: string, coordinates: GeojsonCoordinate, id: string) {

+ 1 - 1
Web/src/hooks/use-g-map-trajectory.ts

@@ -42,7 +42,7 @@ export function useGMapTrajectory() {
     })
     root.$map.add([startMarker, endMarker, polyline]);
     // 自动缩放地图到合适的视野级别
-    root.$map.setFitView();
+    root.$map.setFitView([startMarker, endMarker, polyline]);
   }
 
   return {