started collision handeling for label
This commit is contained in:
107
apps/dispatch/app/_store/aircraftsStore.ts
Normal file
107
apps/dispatch/app/_store/aircraftsStore.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { create } from "zustand";
|
||||
|
||||
export interface Aircraft {
|
||||
id: string;
|
||||
bosName: string;
|
||||
bosNameShort: string;
|
||||
fmsStatus: string;
|
||||
fmsLog: {
|
||||
status: string;
|
||||
timestamp: string;
|
||||
user: string;
|
||||
}[];
|
||||
location: {
|
||||
lat: number;
|
||||
lon: number;
|
||||
altitude: number;
|
||||
speed: number;
|
||||
};
|
||||
locationHistory: {
|
||||
lat: number;
|
||||
lon: number;
|
||||
altitude: number;
|
||||
speed: number;
|
||||
timestamp: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
interface AircraftStore {
|
||||
aircrafts: Aircraft[];
|
||||
setAircrafts: (aircrafts: Aircraft[]) => void;
|
||||
setAircraft: (aircraft: Aircraft) => void;
|
||||
}
|
||||
|
||||
export const useAircraftsStore = create<AircraftStore>((set) => ({
|
||||
aircrafts: [
|
||||
{
|
||||
id: "1",
|
||||
bosName: "Aircraft 1",
|
||||
bosNameShort: "A1",
|
||||
fmsStatus: "1",
|
||||
fmsLog: [],
|
||||
location: {
|
||||
lat: 52.546781040592776,
|
||||
lon: 13.369535209542219,
|
||||
altitude: 0,
|
||||
speed: 0,
|
||||
},
|
||||
locationHistory: [],
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
bosName: "Aircraft 2",
|
||||
bosNameShort: "A2",
|
||||
fmsStatus: "2",
|
||||
fmsLog: [],
|
||||
location: {
|
||||
lat: 52.54588546048977,
|
||||
lon: 13.46470691054384,
|
||||
altitude: 0,
|
||||
speed: 0,
|
||||
},
|
||||
locationHistory: [],
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
bosName: "Aircraft 3",
|
||||
bosNameShort: "A3",
|
||||
fmsStatus: "3",
|
||||
fmsLog: [],
|
||||
location: {
|
||||
lat: 52.497519717230155,
|
||||
lon: 13.342040806552554,
|
||||
altitude: 0,
|
||||
speed: 0,
|
||||
},
|
||||
locationHistory: [],
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
bosName: "Aircraft 4",
|
||||
bosNameShort: "A4",
|
||||
fmsStatus: "6",
|
||||
fmsLog: [],
|
||||
location: {
|
||||
lat: 52.50175041192073,
|
||||
lon: 13.478628701227349,
|
||||
altitude: 0,
|
||||
speed: 0,
|
||||
},
|
||||
locationHistory: [],
|
||||
},
|
||||
],
|
||||
setAircrafts: (aircrafts) => set({ aircrafts }),
|
||||
setAircraft: (aircraft) =>
|
||||
set((state) => {
|
||||
const existingAircraftIndex = state.aircrafts.findIndex(
|
||||
(a) => a.id === aircraft.id,
|
||||
);
|
||||
if (existingAircraftIndex !== -1) {
|
||||
const updatedAircrafts = [...state.aircrafts];
|
||||
updatedAircrafts[existingAircraftIndex] = aircraft;
|
||||
return { aircrafts: updatedAircrafts };
|
||||
} else {
|
||||
return { aircrafts: [...state.aircrafts, aircraft] };
|
||||
}
|
||||
}),
|
||||
}));
|
||||
@@ -12,6 +12,8 @@ interface MapStore {
|
||||
};
|
||||
openMissionMarker: string[];
|
||||
setOpenMissionMarker: (mission: { open: string[]; close: string[] }) => void;
|
||||
openAircraftMarker: string[];
|
||||
setOpenAircraftMarker: (mission: { open: string[]; close: string[] }) => void;
|
||||
searchElements: {
|
||||
id: number;
|
||||
nodes: {
|
||||
@@ -48,6 +50,14 @@ export const useMapStore = create<MapStore>((set, get) => ({
|
||||
),
|
||||
}));
|
||||
},
|
||||
openAircraftMarker: [],
|
||||
setOpenAircraftMarker: ({ open, close }) => {
|
||||
set((state) => ({
|
||||
openAircraftMarker: [...state.openAircraftMarker, ...open].filter(
|
||||
(id) => !close.includes(id),
|
||||
),
|
||||
}));
|
||||
},
|
||||
map: {
|
||||
center: [51.5, 10.5],
|
||||
zoom: 6,
|
||||
|
||||
Reference in New Issue
Block a user