|
@@ -8,9 +8,9 @@ import MapStyle from "./map-style";
|
|
import * as ol from "ol";
|
|
import * as ol from "ol";
|
|
import {formatGetParam, randomColor, YMDHms} from "@/utils/util";
|
|
import {formatGetParam, randomColor, YMDHms} from "@/utils/util";
|
|
import {formatPosition, getShapeView} from "@/utils/easyMap";
|
|
import {formatPosition, getShapeView} from "@/utils/easyMap";
|
|
-import { v4 } from "uuid";
|
|
|
|
import {shipArchiveDetail} from "@/api/modules/web/archive";
|
|
import {shipArchiveDetail} from "@/api/modules/web/archive";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
|
|
+import ShipTrack from '@/components/easyMap/class/ShipTrack'
|
|
|
|
|
|
export const useShipMapStore = defineStore('shipMap', () => {
|
|
export const useShipMapStore = defineStore('shipMap', () => {
|
|
const state: any = reactive({
|
|
const state: any = reactive({
|
|
@@ -41,7 +41,8 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
targetNameEn: 'targetNameEn',
|
|
targetNameEn: 'targetNameEn',
|
|
targetSourceJson: 'targetSource',
|
|
targetSourceJson: 'targetSource',
|
|
shipId: 'shipArchiveId',
|
|
shipId: 'shipArchiveId',
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ selected: null
|
|
})
|
|
})
|
|
const initMap = (map, mapFunc, {trackPointDom}) => {
|
|
const initMap = (map, mapFunc, {trackPointDom}) => {
|
|
state.map = map
|
|
state.map = map
|
|
@@ -69,14 +70,28 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
initWarningWS()
|
|
initWarningWS()
|
|
}
|
|
}
|
|
const mapPointerMove = (ev) => {
|
|
const mapPointerMove = (ev) => {
|
|
|
|
+ if (ev.dragging) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
let pixel = ev.pixel
|
|
let pixel = ev.pixel
|
|
|
|
+ if (state.selected !== null) {
|
|
|
|
+ state.selected.set('hover_', 0);
|
|
|
|
+ state.selected = null;
|
|
|
|
+ }
|
|
let feature = state.map.forEachFeatureAtPixel(pixel, function (feature) {
|
|
let feature = state.map.forEachFeatureAtPixel(pixel, function (feature) {
|
|
return feature
|
|
return feature
|
|
})
|
|
})
|
|
- if (feature && (feature.get('_featureType') == 'ship' || feature.get('_featureType') == 'trackPoint')) {
|
|
|
|
- state.map.getTargetElement().style.cursor = 'pointer'
|
|
|
|
- state.trackHoverData = feature.get('_data')
|
|
|
|
- state.ws.overlayTrack.setPosition(feature.getGeometry().getCoordinates())
|
|
|
|
|
|
+ if (feature) {
|
|
|
|
+ if (feature.get('_featureType') == 'ship') {
|
|
|
|
+ state.map.getTargetElement().style.cursor = 'pointer'
|
|
|
|
+ state.trackHoverData = feature.get('_data')
|
|
|
|
+ state.ws.overlayTrack.setPosition(feature.getGeometry().getCoordinates())
|
|
|
|
+ } else if (feature.get('type_') == 'track-point') {
|
|
|
|
+ state.selected = feature;
|
|
|
|
+ state.map.getTargetElement().style.cursor = 'pointer'
|
|
|
|
+ state.trackHoverData = feature.get('data_')
|
|
|
|
+ state.ws.overlayTrack.setPosition(feature.getGeometry().getCoordinates())
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
state.map.getTargetElement().style.cursor = ''
|
|
state.map.getTargetElement().style.cursor = ''
|
|
state.trackHoverData = null
|
|
state.trackHoverData = null
|
|
@@ -95,32 +110,18 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
if (!state.trackMap.has(feature.get('_id'))) {
|
|
if (!state.trackMap.has(feature.get('_id'))) {
|
|
const isWarning = feature.get('_warning')
|
|
const isWarning = feature.get('_warning')
|
|
const d = feature.get('_data')
|
|
const d = feature.get('_data')
|
|
|
|
+ const color = isWarning ? '#ea3147' : '#FC60FF'
|
|
state.trackMap.set(feature.get('_id'), {
|
|
state.trackMap.set(feature.get('_id'), {
|
|
|
|
+ shipTrackClass: null,
|
|
isWarning: !!isWarning,
|
|
isWarning: !!isWarning,
|
|
data: feature.get('_data'),
|
|
data: feature.get('_data'),
|
|
- color: isWarning ? '#ea3147' : '#FC60FF', //randomColor(1),
|
|
|
|
- history: [],
|
|
|
|
- real: isWarning ? [] : [d],
|
|
|
|
|
|
+ color: color, //randomColor(1),
|
|
trackId: feature.get('_trackId'),
|
|
trackId: feature.get('_trackId'),
|
|
- moveToTrack: () => {
|
|
|
|
- const position: any = []
|
|
|
|
- const t = state.trackMap.get(feature.get('_id'))
|
|
|
|
- const arr = [...t.history, ...t.real]
|
|
|
|
- arr.forEach(v => {
|
|
|
|
- position.push([v[state.trackKeys.lon], v[state.trackKeys.lat]])
|
|
|
|
- })
|
|
|
|
- if (position.length > 0) {
|
|
|
|
- getShapeView(state.map, position)
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
// 直接用图层的话declutter: true会报错,Uncaught TypeError: Failed to execute 'clip' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Path2D'.
|
|
// 直接用图层的话declutter: true会报错,Uncaught TypeError: Failed to execute 'clip' on 'CanvasRenderingContext2D': parameter 1 is not of type 'Path2D'.
|
|
- lineLayer: 'lineLayer_' + feature.get('_id'),
|
|
|
|
- pointsLayer: 'pointsLayer_' + feature.get('_id'),
|
|
|
|
warningLayer: 'warningLayer_' + feature.get('_id'),
|
|
warningLayer: 'warningLayer_' + feature.get('_id'),
|
|
del: () => {
|
|
del: () => {
|
|
- state.map.removeLayer(state.map.getLayers().getArray().filter(v => v.get('__layerName') === state.trackMap.get(feature.get('_id')).lineLayer)[0])
|
|
|
|
- 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.map.removeLayer(state.map.getLayers().getArray().filter(v => v.get('__layerName') === state.trackMap.get(feature.get('_id')).warningLayer)[0])
|
|
|
|
+ state.trackMap.get(feature.get('_id')).shipTrackClass.destroy()
|
|
state.trackMap.delete(feature.get('_id'))
|
|
state.trackMap.delete(feature.get('_id'))
|
|
if (realTrackMapCpt.value.size === 0) {
|
|
if (realTrackMapCpt.value.size === 0) {
|
|
state.ws.instance?.close()
|
|
state.ws.instance?.close()
|
|
@@ -134,59 +135,13 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
},
|
|
},
|
|
visibleTrack: (visible) => {
|
|
visibleTrack: (visible) => {
|
|
const t = state.trackMap.get(feature.get('_id'))
|
|
const t = state.trackMap.get(feature.get('_id'))
|
|
- state.map.getLayers().getArray().filter(v => v.get('__layerName') === t.lineLayer)[0]?.setVisible(visible)
|
|
|
|
- state.map.getLayers().getArray().filter(v => v.get('__layerName') === t.pointsLayer)[0]?.setVisible(visible)
|
|
|
|
state.map.getLayers().getArray().filter(v => v.get('__layerName') === t.warningLayer)[0]?.setVisible(visible)
|
|
state.map.getLayers().getArray().filter(v => v.get('__layerName') === t.warningLayer)[0]?.setVisible(visible)
|
|
t.showTrack = visible
|
|
t.showTrack = visible
|
|
if (visible) {
|
|
if (visible) {
|
|
- t.moveToTrack()
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- refreshTrackStyle: () => {
|
|
|
|
- const t = state.trackMap.get(feature.get('_id'))
|
|
|
|
- const arr = [...t.history, ...t.real]
|
|
|
|
- let lineWkt = ''
|
|
|
|
- if (arr.length > 1) {
|
|
|
|
- arr.forEach((v, i) => {
|
|
|
|
- if (i === 0) {
|
|
|
|
- lineWkt += `LINESTRING(${v[state.trackKeys.lon]} ${v[state.trackKeys.lat]}`
|
|
|
|
- } else if (i === arr.length - 1) {
|
|
|
|
- lineWkt += `,${v[state.trackKeys.lon]} ${v[state.trackKeys.lat]})`
|
|
|
|
- } else {
|
|
|
|
- lineWkt += `,${v[state.trackKeys.lon]} ${v[state.trackKeys.lat]}`
|
|
|
|
- }
|
|
|
|
- v.wkt = `POINT(${v[state.trackKeys.lon]} ${v[state.trackKeys.lat]})`
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- if (lineWkt) {
|
|
|
|
- const lS = new source.Vector({
|
|
|
|
- features: [],
|
|
|
|
- wrapX: false
|
|
|
|
- })
|
|
|
|
- const lineF: any = new format.WKT().readFeature(lineWkt)
|
|
|
|
- lineF.set('trackPointList', arr)
|
|
|
|
- lineF.setStyle((f, r) => MapStyle.trackStyle(f, r, state.map, t.color, (_s, pointList) => {
|
|
|
|
- const pointFeatures: any = []
|
|
|
|
- pointList.forEach(DATA => {
|
|
|
|
- try {
|
|
|
|
- const feat: any = new format.WKT().readFeature(DATA.wkt)
|
|
|
|
- feat.set('_featureType', 'trackPoint')
|
|
|
|
- feat.set('_data', DATA)
|
|
|
|
- feat.setStyle(MapStyle.trackPointNormalStyle(t.color))
|
|
|
|
- pointFeatures.push(feat)
|
|
|
|
- } catch (e) {
|
|
|
|
- console.log(e)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- lS.clear()
|
|
|
|
- lS.addFeatures(pointFeatures)
|
|
|
|
- return _s
|
|
|
|
- }))
|
|
|
|
- state.map.getLayers().getArray().filter(v => v.get('__layerName') === t.lineLayer)[0].setSource(new source.Vector({
|
|
|
|
- features: [lineF],
|
|
|
|
- wrapX: false
|
|
|
|
- }))
|
|
|
|
- state.map.getLayers().getArray().filter(v => v.get('__layerName') === t.pointsLayer)[0].setSource(lS)
|
|
|
|
|
|
+ t.shipTrackClass.show()
|
|
|
|
+ t.shipTrackClass.focus()
|
|
|
|
+ } else {
|
|
|
|
+ t.shipTrackClass.hide()
|
|
}
|
|
}
|
|
},
|
|
},
|
|
showTrack: true,
|
|
showTrack: true,
|
|
@@ -211,21 +166,10 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- const lineLayer = new layer.Vector({
|
|
|
|
- zIndex: 4000,
|
|
|
|
- __layerName: state.trackMap.get(feature.get('_id')).lineLayer
|
|
|
|
- })
|
|
|
|
- const pointsLayer = new layer.Vector({
|
|
|
|
- zIndex: 4100,
|
|
|
|
- declutter: true,
|
|
|
|
- __layerName: state.trackMap.get(feature.get('_id')).pointsLayer
|
|
|
|
- })
|
|
|
|
const warningLayer = new layer.Vector({
|
|
const warningLayer = new layer.Vector({
|
|
zIndex: 3999,
|
|
zIndex: 3999,
|
|
- __layerName: state.trackMap.get(feature.get('_id')).warningLayer,
|
|
|
|
})
|
|
})
|
|
- state.map.addLayer(lineLayer)
|
|
|
|
- state.map.addLayer(pointsLayer)
|
|
|
|
|
|
+ warningLayer.set('__layerName', state.trackMap.get(feature.get('_id')).warningLayer)
|
|
state.map.addLayer(warningLayer)
|
|
state.map.addLayer(warningLayer)
|
|
if (isWarning) {
|
|
if (isWarning) {
|
|
const wf: any = new format.WKT().readFeature(`POINT(${d[state.trackKeys.lon]} ${d[state.trackKeys.lat]})`)
|
|
const wf: any = new format.WKT().readFeature(`POINT(${d[state.trackKeys.lon]} ${d[state.trackKeys.lat]})`)
|
|
@@ -235,6 +179,8 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
wrapX: false,
|
|
wrapX: false,
|
|
}))
|
|
}))
|
|
}
|
|
}
|
|
|
|
+ const shipTrack = new ShipTrack({map: state.map, color: color}).init([], [d])
|
|
|
|
+ state.trackMap.get(feature.get('_id')).shipTrackClass = shipTrack
|
|
const ws = new WebSocket(`ws://${location.host}/history-track-ws-api/historyshiptrack`)
|
|
const ws = new WebSocket(`ws://${location.host}/history-track-ws-api/historyshiptrack`)
|
|
ws.onopen = (e) => {
|
|
ws.onopen = (e) => {
|
|
if (isWarning) {
|
|
if (isWarning) {
|
|
@@ -259,10 +205,9 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
if (json.length === 0) {
|
|
if (json.length === 0) {
|
|
ws.close()
|
|
ws.close()
|
|
} else if (json?.length > 0) {
|
|
} else if (json?.length > 0) {
|
|
- state.trackMap.get(feature.get('_id')).history.push(...json)
|
|
|
|
- state.trackMap.get(feature.get('_id')).refreshTrackStyle()
|
|
|
|
|
|
+ state.trackMap.get(feature.get('_id')).shipTrackClass.add(json)
|
|
if (isWarning) {
|
|
if (isWarning) {
|
|
- state.trackMap.get(feature.get('_id')).moveToTrack()
|
|
|
|
|
|
+ state.trackMap.get(feature.get('_id')).shipTrackClass.focus()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -410,10 +355,9 @@ export const useShipMapStore = defineStore('shipMap', () => {
|
|
// 实时轨迹
|
|
// 实时轨迹
|
|
const t = state.trackMap.get(feat.get('_id'))
|
|
const t = state.trackMap.get(feat.get('_id'))
|
|
if (t && t.trackId !== feat.get('_trackId')) {
|
|
if (t && t.trackId !== feat.get('_trackId')) {
|
|
- t.real.push(feat.get('_data'))
|
|
|
|
t.trackId = feat.get('_trackId')
|
|
t.trackId = feat.get('_trackId')
|
|
t.data = feat.get('_data')
|
|
t.data = feat.get('_data')
|
|
- t.refreshTrackStyle()
|
|
|
|
|
|
+ t.shipTrackClass.update([feat.get('_data')])
|
|
}
|
|
}
|
|
return feat
|
|
return feat
|
|
} catch (e) {
|
|
} catch (e) {
|