Blame view

src/main/kotlin/application/controller/MapPanelController.kt 4.11 KB
53f01ecc3   lsagona   display message o...
1
  package application.controller
2bbe36a1b   lsagona   addd the possibil...
2
  import application.model.*
3b26be8f9   lsagona   controle the time...
3
  import application.model.MapState.*
e220e082b   lsagona   graph binded to s...
4
  import javafx.application.Platform
53f01ecc3   lsagona   display message o...
5
6
7
  import javafx.fxml.FXML
  import javafx.fxml.Initializable
  import javafx.scene.layout.StackPane
9e952e84e   lsagona   add message clust...
8
  import map.*
53f01ecc3   lsagona   display message o...
9
10
  import java.net.URL
  import java.util.*
53f01ecc3   lsagona   display message o...
11

2bbe36a1b   lsagona   addd the possibil...
12
  class MapPanelController : Initializable {
53f01ecc3   lsagona   display message o...
13
14
15
16
17
  
      @FXML
      private lateinit var map: StackPane
  
      private val mapView = LeafletMapView()
53f01ecc3   lsagona   display message o...
18
      override fun initialize(location: URL?, resources: ResourceBundle?) {
79b001037   lsagona   heat map
19
          mapView.displayMap(MapConfig())
9e952e84e   lsagona   add message clust...
20
21
22
          setObservableVesselListener()
          setObservableSelectedVesselListener()
          setStateListener()
dd1ce7fe8   lsagona   add button to swi...
23
          setObservableIsReplayState()
3b26be8f9   lsagona   controle the time...
24
          observableCurrentTime()
9e952e84e   lsagona   add message clust...
25
26
27
28
29
          map.children.add(mapView)
          map.children
      }
  
      private fun setStateListener() {
3b26be8f9   lsagona   controle the time...
30
31
          observableMapState.listeners.add(object : StateListener {
              override fun onValueChanged(newValue: MapState) {
dd1ce7fe8   lsagona   add button to swi...
32
33
                  if (observableSelectedVessel.value.mmsi != null) {
                      updateMap(observableSelectedVessel.value.mmsi!!)
79b001037   lsagona   heat map
34
35
36
                  } else {
                      updateMap()
                  }
9e952e84e   lsagona   add message clust...
37
38
39
              }
          })
      }
3b26be8f9   lsagona   controle the time...
40
      private fun observableCurrentTime() {
78935bd62   lsagona   slider bind to al...
41
          observableCurrentTime.listeners.add(object : CurrentTime {
3b26be8f9   lsagona   controle the time...
42
              override fun onValueChanged(newValue: Int) {
dd1ce7fe8   lsagona   add button to swi...
43
44
                  if (observableSelectedVessel.value.mmsi != null) {
                      updateMap(observableSelectedVessel.value.mmsi!!)
78935bd62   lsagona   slider bind to al...
45
46
47
                  } else {
                      updateMap()
                  }
3b26be8f9   lsagona   controle the time...
48
49
50
              }
          })
      }
9e952e84e   lsagona   add message clust...
51
      private fun updateMap() {
e220e082b   lsagona   graph binded to s...
52
53
54
55
56
57
58
59
60
61
62
63
64
          Platform.runLater {
              if (observableIsReplayState.value) {
                  when (observableMapState.state) {
                      ALL_MESSAGES -> displayTimedAllMessageOnMap(mapView)
                      CLUSTERED_MESSAGES -> displayTimedClusterMessageOnMap(mapView)
                      HEAT_MAP -> displayTimedHeatMapOnMap(mapView)
                  }
              } else {
                  when (observableMapState.state) {
                      ALL_MESSAGES -> displayAllMessageOnMap(mapView)
                      CLUSTERED_MESSAGES -> displayClusterMessageOnMap(mapView)
                      HEAT_MAP -> displayHeatMapOnMap(mapView)
                  }
3b26be8f9   lsagona   controle the time...
65
              }
9e952e84e   lsagona   add message clust...
66
67
          }
      }
f39d90e60   lsagona   Select/deselect MMSI
68
      private fun updateMap(selectedMMSI: String) {
e220e082b   lsagona   graph binded to s...
69
70
71
72
73
74
75
76
77
78
79
80
81
          Platform.runLater {
              if (observableIsReplayState.value) {
                  when (observableMapState.state) {
                      ALL_MESSAGES -> displayTimedAllMessageOnMap(mapView, selectedMMSI)
                      CLUSTERED_MESSAGES -> displayTimedClusterMessageOnMap(mapView, selectedMMSI)
                      HEAT_MAP -> displayTimedHeatMapOnMap(mapView, selectedMMSI)
                  }
              } else {
                  when (observableMapState.state) {
                      ALL_MESSAGES -> displayAllMessageOnMap(mapView, selectedMMSI)
                      CLUSTERED_MESSAGES -> displayClusterMessageOnMap(mapView, selectedMMSI)
                      HEAT_MAP -> displayHeatMapOnMap(mapView, selectedMMSI)
                  }
78935bd62   lsagona   slider bind to al...
82
              }
9e952e84e   lsagona   add message clust...
83
84
85
86
          }
      }
  
      private fun setObservableVesselListener() {
2bbe36a1b   lsagona   addd the possibil...
87
          observableVessel.listeners.add(object : MessageListener {
f39d90e60   lsagona   Select/deselect MMSI
88
              override fun onValueChanged(newValue: MutableMap<String?, Vessel>) {
9e952e84e   lsagona   add message clust...
89
                  updateMap()
2bbe36a1b   lsagona   addd the possibil...
90
91
              }
          })
9e952e84e   lsagona   add message clust...
92
      }
2bbe36a1b   lsagona   addd the possibil...
93

dd1ce7fe8   lsagona   add button to swi...
94
      private fun setObservableIsReplayState() {
e220e082b   lsagona   graph binded to s...
95
          observableIsReplayState.listeners.add(object : ReplayState {
dd1ce7fe8   lsagona   add button to swi...
96
97
98
99
100
101
102
103
104
              override fun onValueChanged(newValue: Boolean) {
                  if (observableSelectedVessel.value.mmsi != null) {
                      updateMap(observableSelectedVessel.value.mmsi!!)
                  } else {
                      updateMap()
                  }
              }
          })
      }
9e952e84e   lsagona   add message clust...
105
      private fun setObservableSelectedVesselListener() {
2bbe36a1b   lsagona   addd the possibil...
106
107
          observableSelectedVessel.listeners.add(object : SelectedVesselListener {
              override fun onValueChanged(newValue: Vessel) {
78935bd62   lsagona   slider bind to al...
108
                  if (newValue.mmsi != null) {
79b001037   lsagona   heat map
109
                      updateMap(newValue.mmsi)
78935bd62   lsagona   slider bind to al...
110
                  } else {
f39d90e60   lsagona   Select/deselect MMSI
111
                      updateMap()
79b001037   lsagona   heat map
112
                  }
2bbe36a1b   lsagona   addd the possibil...
113
114
              }
          })
53f01ecc3   lsagona   display message o...
115
      }
53f01ecc3   lsagona   display message o...
116
  }