Browse Source

轨迹列表实时区分

CzRger 2 months ago
parent
commit
ae40107409
1 changed files with 30 additions and 11 deletions
  1. 30 11
      src/stores/ship-map/ship-map.ts

+ 30 - 11
src/stores/ship-map/ship-map.ts

@@ -52,7 +52,6 @@ export const useShipMapStore = defineStore('shipMap', () => {
       map.un('singleclick', mapSingleClick)
     })
     state.map.on('moveend', e => {
-      state.trackHover = new Date().getTime()
       state.zoom = e.map.getView().getZoom()
       switchZoom()
       map.on('singleclick', mapSingleClick)
@@ -123,6 +122,14 @@ export const useShipMapStore = defineStore('shipMap', () => {
             state.map.removeLayer(state.map.getLayers().getArray().filter(v => v.get('__layerName') === state.trackMap.get(feature.get('_id')).pointsLayer)[0])
             state.map.removeLayer(state.map.getLayers().getArray().filter(v => v.get('__layerName') === state.trackMap.get(feature.get('_id')).warningLayer)[0])
             state.trackMap.delete(feature.get('_id'))
+            if (realTrackMapCpt.value.size === 0) {
+              state.ws.instance?.close()
+              state.ws.instance = null
+              state.map.removeLayer(state.ws.layerShip)
+              state.ws.layerShip = null
+            } else {
+              initWebSocket()
+            }
           },
           visibleTrack: (visible) => {
             const t = state.trackMap.get(feature.get('_id'))
@@ -220,7 +227,6 @@ export const useShipMapStore = defineStore('shipMap', () => {
         state.map.addLayer(pointsLayer)
         state.map.addLayer(warningLayer)
         if (isWarning) {
-          console.log(d)
           const wf: any = new format.WKT().readFeature(`POINT(${d[state.trackKeys.lon]} ${d[state.trackKeys.lat]})`)
           wf.setStyle(MapStyle.warningStyle(feature.get('_warning').ruleInfo.level))
           warningLayer.setSource(new source.Vector({
@@ -268,9 +274,18 @@ export const useShipMapStore = defineStore('shipMap', () => {
   const zoomWMS = computed(() => {
     return state.zoom <= 14
   })
+  const realTrackMapCpt = computed(() => {
+    let map = new Map()
+    state.trackMap.forEach((v, k) => {
+      if (!v.isWarning) {
+        map.set(k, v)
+      }
+    })
+    return map
+  })
   const switchZoom = () => {
     if (zoomWMS.value) {
-      if (state.ws.instance && state.trackMap.size === 0) {
+      if (state.ws.instance && realTrackMapCpt.value.size === 0) {
         state.ws.instance.close()
         state.ws.instance = null
         state.map.removeLayer(state.ws.layerShip)
@@ -279,7 +294,7 @@ export const useShipMapStore = defineStore('shipMap', () => {
       // 瓦片
       initWMS()
       // ws
-      if (state.trackMap.size > 0) {
+      if (realTrackMapCpt.value.size > 0) {
         initWebSocket()
       }
     } else {
@@ -329,17 +344,21 @@ export const useShipMapStore = defineStore('shipMap', () => {
       // userId: "18889231165"
     }
     let idCql = ''
-    if (state.trackMap.size > 0) {
+    if (realTrackMapCpt.value.size > 0) {
       let arr = []
-      state.trackMap.forEach((v, k) => {
-        if (!v.isWarning) {
-          arr.push(`'${k}'`)
-        }
+      realTrackMapCpt.value.forEach((v, k) => {
+        arr.push(`'${k}'`)
       })
-      idCql = `${state.trackKeys.mergeTarget} in (${arr.join(',')})`
+      if (arr.length > 0) {
+        idCql = `${state.trackKeys.mergeTarget} in (${arr.join(',')})`
+      }
     }
     if (zoomWMS.value) {
-      param.cql = idCql
+      if (idCql) {
+        param.cql = idCql
+      } else {
+        delete param.cql
+      }
     } else {
       param.cql = getBBOX()
       if (idCql) {