xsh_1997 hai 1 mes
pai
achega
b5953f8741

+ 19 - 17
ruoyi-screen/src/components/GisMap.vue

@@ -13,10 +13,8 @@ import {
13
   syncWmtsLayerVisibility
13
   syncWmtsLayerVisibility
14
 } from '@/utils/gisLoader'
14
 } from '@/utils/gisLoader'
15
 import {
15
 import {
16
-  GIS_POI_SEARCH_MODE,
17
-  getGisPoiSearchMode,
18
   parsePoiLngLat,
16
   parsePoiLngLat,
19
-  searchPois
17
+  searchNearbyPois
20
 } from '@/utils/gisPoiSearch'
18
 } from '@/utils/gisPoiSearch'
21
 import {
19
 import {
22
   addTownshipBoundaryLayers,
20
   addTownshipBoundaryLayers,
@@ -24,6 +22,7 @@ import {
24
   buildTownshipInfo,
22
   buildTownshipInfo,
25
   flyToTownship,
23
   flyToTownship,
26
   getTownshipLabelPoints,
24
   getTownshipLabelPoints,
25
+  getTownshipPoiSearchCenter,
27
   removeTownshipBoundaryLayers
26
   removeTownshipBoundaryLayers
28
 } from '@/utils/gisTownshipBoundary'
27
 } from '@/utils/gisTownshipBoundary'
29
 import { getTownshipLivestockStats } from '@/constants/townshipLivestock'
28
 import { getTownshipLivestockStats } from '@/constants/townshipLivestock'
@@ -49,7 +48,7 @@ const props = defineProps({
49
     type: Boolean,
48
     type: Boolean,
50
     default: false
49
     default: false
51
   },
50
   },
52
-  /** 是否在地图加载后展示周边 POI Marker */
51
+  /** 点击乡镇后是否展示该乡镇中心点周边 POI(默认不加载,点击后才查) */
53
   showPoiMarkers: {
52
   showPoiMarkers: {
54
     type: Boolean,
53
     type: Boolean,
55
     default: true
54
     default: true
@@ -95,6 +94,8 @@ let lastWheelAround = null
95
 let poiMarkers = []
94
 let poiMarkers = []
96
 let townshipMarkers = []
95
 let townshipMarkers = []
97
 let unbindTownshipClick = null
96
 let unbindTownshipClick = null
97
+/** 当前 POI 查询中心,仅点击乡镇后赋值 */
98
+let poiSearchCenter = null
98
 
99
 
99
 function logClickCoordinate(lngLat) {
100
 function logClickCoordinate(lngLat) {
100
   if (!lngLat) {
101
   if (!lngLat) {
@@ -176,10 +177,14 @@ function bindTownshipDrillDown() {
176
     })
177
     })
177
     emit('township-click', info)
178
     emit('township-click', info)
178
 
179
 
179
-    if (props.showPoiMarkers && getGisPoiSearchMode() === GIS_POI_SEARCH_MODE.NEARBY) {
180
-      map.once('moveend', () => {
181
-        renderPoiMarkers()
182
-      })
180
+    if (props.showPoiMarkers) {
181
+      const searchCenter = getTownshipPoiSearchCenter(feature)
182
+      if (searchCenter) {
183
+        poiSearchCenter = searchCenter
184
+        map.once('moveend', () => {
185
+          renderPoiMarkers()
186
+        })
187
+      }
183
     }
188
     }
184
   })
189
   })
185
 }
190
 }
@@ -280,15 +285,15 @@ function createPoiMarkerElement(name) {
280
 }
285
 }
281
 
286
 
282
 async function renderPoiMarkers() {
287
 async function renderPoiMarkers() {
283
-  if (!props.showPoiMarkers || !map || !cmmapglRef) {
288
+  if (!props.showPoiMarkers || !map || !cmmapglRef || !poiSearchCenter) {
284
     return
289
     return
285
   }
290
   }
286
   clearPoiMarkers()
291
   clearPoiMarkers()
287
 
292
 
288
   let pois = []
293
   let pois = []
289
   try {
294
   try {
290
-    pois = await searchPois({
291
-      center: resolveCenter()
295
+    pois = await searchNearbyPois({
296
+      center: poiSearchCenter
292
     })
297
     })
293
   } catch {
298
   } catch {
294
     return
299
     return
@@ -330,6 +335,7 @@ function destroyMap() {
330
   wheelDeltaAccum = 0
335
   wheelDeltaAccum = 0
331
   lastWheelAround = null
336
   lastWheelAround = null
332
   clampingZoom = false
337
   clampingZoom = false
338
+  poiSearchCenter = null
333
   clearPoiMarkers()
339
   clearPoiMarkers()
334
   teardownTownshipBoundary()
340
   teardownTownshipBoundary()
335
   if (map) {
341
   if (map) {
@@ -571,7 +577,6 @@ async function initMap() {
571
       syncWmtsLayerVisibility(map)
577
       syncWmtsLayerVisibility(map)
572
       resizeMap()
578
       resizeMap()
573
       renderTownshipBoundary()
579
       renderTownshipBoundary()
574
-      renderPoiMarkers()
575
       emit('ready', map)
580
       emit('ready', map)
576
     })
581
     })
577
     // 瓦片/遥测等非致命错误不向页面报错
582
     // 瓦片/遥测等非致命错误不向页面报错
@@ -589,9 +594,6 @@ watch(
589
       center: resolveCenter(),
594
       center: resolveCenter(),
590
       zoom: resolveZoom()
595
       zoom: resolveZoom()
591
     })
596
     })
592
-    if (props.showPoiMarkers && getGisPoiSearchMode() === GIS_POI_SEARCH_MODE.NEARBY) {
593
-      renderPoiMarkers()
594
-    }
595
   },
597
   },
596
   { deep: true }
598
   { deep: true }
597
 )
599
 )
@@ -600,9 +602,9 @@ watch(
600
   () => props.showPoiMarkers,
602
   () => props.showPoiMarkers,
601
   (show) => {
603
   (show) => {
602
     if (!map || !cmmapglRef) return
604
     if (!map || !cmmapglRef) return
603
-    if (show) {
605
+    if (show && poiSearchCenter) {
604
       renderPoiMarkers()
606
       renderPoiMarkers()
605
-    } else {
607
+    } else if (!show) {
606
       clearPoiMarkers()
608
       clearPoiMarkers()
607
     }
609
     }
608
   }
610
   }

+ 27 - 0
ruoyi-screen/src/utils/gisTownshipBoundary.js

@@ -43,6 +43,33 @@ function getTownshipDrillCenter(feature) {
43
   return null
43
   return null
44
 }
44
 }
45
 
45
 
46
+/** POI 周边搜索中心:拉西镇用手动坐标,其余乡镇用 json 的 center/centroid */
47
+export function getTownshipPoiSearchCenter(feature) {
48
+  if (!feature) {
49
+    return null
50
+  }
51
+  const name = String(feature.properties?.name || '')
52
+  const override = TOWNSHIP_DRILL_CENTER_OVERRIDES[name]
53
+  if (Array.isArray(override) && override.length >= 2) {
54
+    const lng = Number(override[0])
55
+    const lat = Number(override[1])
56
+    if (Number.isFinite(lng) && Number.isFinite(lat)) {
57
+      return [lng, lat]
58
+    }
59
+  }
60
+
61
+  const center = feature.properties?.centroid || feature.properties?.center
62
+  if (Array.isArray(center) && center.length >= 2) {
63
+    const lng = Number(center[0])
64
+    const lat = Number(center[1])
65
+    if (Number.isFinite(lng) && Number.isFinite(lat)) {
66
+      return [lng, lat]
67
+    }
68
+  }
69
+
70
+  return null
71
+}
72
+
46
 export function getTownshipGeoJson() {
73
 export function getTownshipGeoJson() {
47
   return townshipGeoJson
74
   return townshipGeoJson
48
 }
75
 }