33import { useEffect } from "react" ;
44import "./Map.css" ;
55import { useRouter } from "next/navigation" ;
6+ import { useTheme } from "next-themes" ;
67import { ToastContainer } from "react-toastify" ;
8+ import { useSettingsStore } from "@/storage/zustand" ;
79import { MessageBoxCloseButton } from "../MessageBox/MessageBox" ;
10+ import MapControls from "./components/MapControls" ;
11+ import { setDataLayersSettings } from "./utils/dataLayers" ;
812import { onClick , onMoveEnd , onPointerMove , setNavigator } from "./utils/events" ;
9- import { initMap } from "./utils/init" ;
13+ import { getMap , initMap , setMapTheme } from "./utils/init" ;
1014import { animatePilotFeatures } from "./utils/pilotFeatures" ;
15+ import { setSunLayerSettings } from "./utils/sunLayer" ;
1116
1217export default function OMap ( ) {
1318 const router = useRouter ( ) ;
19+ const { theme } = useTheme ( ) ;
20+ const {
21+ dayNightLayer,
22+ dayNightLayerBrightness,
23+ airportMarkers,
24+ airportMarkerSize,
25+ planeMarkerSize,
26+ animatedPlaneMarkers,
27+ sectorAreas,
28+ traconColor,
29+ traconTransparency,
30+ firColor,
31+ firTransparency,
32+ } = useSettingsStore ( ) ;
1433
1534 useEffect ( ( ) => {
1635 setNavigator ( ( href ) => router . push ( href ) ) ;
@@ -20,6 +39,24 @@ export default function OMap() {
2039 map . on ( "pointermove" , onPointerMove ) ;
2140 map . on ( "click" , onClick ) ;
2241
42+ return ( ) => {
43+ map . un ( [ "moveend" ] , onMoveEnd ) ;
44+ map . un ( "pointermove" , onPointerMove ) ;
45+ map . un ( "click" , onClick ) ;
46+ map . setTarget ( undefined ) ;
47+ } ;
48+ } , [ router ] ) ;
49+
50+ useEffect ( ( ) => {
51+ setMapTheme ( theme === "dark" ) ;
52+ } , [ theme ] ) ;
53+
54+ useEffect ( ( ) => {
55+ if ( ! animatedPlaneMarkers ) return ;
56+
57+ const map = getMap ( ) ;
58+ if ( ! map ) return ;
59+
2360 let animationFrameId = 0 ;
2461 const animate = ( ) => {
2562 animatePilotFeatures ( map ) ;
@@ -28,17 +65,39 @@ export default function OMap() {
2865 animationFrameId = window . requestAnimationFrame ( animate ) ;
2966
3067 return ( ) => {
31- map . un ( [ "moveend" ] , onMoveEnd ) ;
32- map . un ( "pointermove" , onPointerMove ) ;
33- map . un ( "click" , onClick ) ;
34- map . setTarget ( undefined ) ;
3568 window . cancelAnimationFrame ( animationFrameId ) ;
3669 } ;
37- } , [ router ] ) ;
70+ } , [ animatedPlaneMarkers ] ) ;
71+
72+ useEffect ( ( ) => {
73+ setSunLayerSettings ( dayNightLayer , dayNightLayerBrightness ) ;
74+ setDataLayersSettings (
75+ airportMarkers ,
76+ airportMarkerSize ,
77+ planeMarkerSize ,
78+ sectorAreas ,
79+ traconColor ,
80+ traconTransparency ,
81+ firColor ,
82+ firTransparency ,
83+ ) ;
84+ } , [
85+ dayNightLayer ,
86+ dayNightLayerBrightness ,
87+ airportMarkers ,
88+ airportMarkerSize ,
89+ planeMarkerSize ,
90+ sectorAreas ,
91+ traconColor ,
92+ traconTransparency ,
93+ firColor ,
94+ firTransparency ,
95+ ] ) ;
3896
3997 return (
4098 < >
4199 < ToastContainer closeButton = { MessageBoxCloseButton } icon = { false } theme = "colored" />
100+ < MapControls />
42101 < div id = "map" />
43102 </ >
44103 ) ;
0 commit comments