@@ -4,6 +4,8 @@ import type { Extent } from "ol/extent";
44import { Point } from "ol/geom" ;
55import { fromLonLat , transformExtent } from "ol/proj" ;
66import RBush from "rbush" ;
7+ import { toast } from "react-toastify" ;
8+ import MessageBox from "@/components/MessageBox/MessageBox" ;
79import type { PilotProperties } from "@/types/ol" ;
810import { pilotMainSource } from "./dataLayers" ;
911import { animateOverlays , resetMap } from "./events" ;
@@ -50,7 +52,6 @@ export function initPilotFeatures(data: WsAll): void {
5052}
5153
5254export function updatePilotFeatures ( delta : PilotDelta ) : void {
53- const items : RBushPilotFeature [ ] = [ ] ;
5455 const pilotsInDelta = new Set < string > ( ) ;
5556
5657 for ( const p of delta . updated ) {
@@ -71,15 +72,6 @@ export function updatePilotFeatures(delta: PilotDelta): void {
7172 }
7273
7374 pilotMap . set ( p . id , feature ) ;
74-
75- const item : RBushPilotFeature = {
76- minX : p . longitude ?? props . longitude ,
77- minY : p . latitude ?? props . latitude ,
78- maxX : p . longitude ?? props . longitude ,
79- maxY : p . latitude ?? props . latitude ,
80- feature,
81- } ;
82- items . push ( item ) ;
8375 }
8476
8577 for ( const p of delta . added ) {
@@ -98,15 +90,6 @@ export function updatePilotFeatures(delta: PilotDelta): void {
9890 feature . setId ( `pilot_${ p . id } ` ) ;
9991
10092 pilotMap . set ( p . id , feature ) ;
101-
102- const item : RBushPilotFeature = {
103- minX : p . longitude ,
104- minY : p . latitude ,
105- maxX : p . longitude ,
106- maxY : p . latitude ,
107- feature,
108- } ;
109- items . push ( item ) ;
11093 }
11194
11295 for ( const id of pilotMap . keys ( ) ) {
@@ -115,13 +98,26 @@ export function updatePilotFeatures(delta: PilotDelta): void {
11598 }
11699 }
117100
118- if ( highlightedPilot && ! pilotMap . has ( highlightedPilot ) ) {
119- highlightedPilot = null ;
120- resetMap ( true ) ;
101+ const items : RBushPilotFeature [ ] = [ ] ;
102+ for ( const [ _id , feature ] of pilotMap . entries ( ) ) {
103+ const props = feature . getProperties ( ) as PilotProperties ;
104+ items . push ( {
105+ minX : props . longitude ,
106+ minY : props . latitude ,
107+ maxX : props . longitude ,
108+ maxY : props . latitude ,
109+ feature,
110+ } ) ;
121111 }
122112
123113 pilotRBush . clear ( ) ;
124114 pilotRBush . load ( items ) ;
115+
116+ if ( highlightedPilot && ! pilotMap . has ( highlightedPilot ) ) {
117+ toast . info ( MessageBox , { data : { title : "Pilot Disconnected" , message : `The viewed pilot has disconnected.` } } ) ;
118+ highlightedPilot = null ;
119+ resetMap ( true ) ;
120+ }
125121}
126122
127123let highlightedPilot : string | null = null ;
@@ -134,8 +130,10 @@ export function clearHighlightedPilot(): void {
134130 highlightedPilot = null ;
135131}
136132
133+ let initialized = false ;
137134export function setPilotFeatures ( extent : Extent , zoom : number ) : void {
138- if ( zoom > 10 ) {
135+ if ( zoom > 12 && ! initialized ) {
136+ initialized = true ;
139137 return ;
140138 }
141139
@@ -203,6 +201,8 @@ export function animatePilotFeatures(map: OlMap) {
203201
204202 features . forEach ( ( feature ) => {
205203 const groundspeed = ( feature . get ( "groundspeed" ) as number ) || 0 ;
204+ if ( groundspeed <= 0 ) return ;
205+
206206 const heading = ( feature . get ( "heading" ) as number ) || 0 ;
207207 const latitude = ( feature . get ( "latitude" ) as number ) || 0 ;
208208 const longitude = ( feature . get ( "longitude" ) as number ) || 0 ;
0 commit comments