Blame view

src/main/kotlin/application/controller/MapPanelController.kt 2.45 KB
53f01ecc3   lsagona   display message o...
1
  package application.controller
2bbe36a1b   lsagona   addd the possibil...
2
  import application.model.*
9e952e84e   lsagona   add message clust...
3
  import application.model.State.*
53f01ecc3   lsagona   display message o...
4
5
6
  import javafx.fxml.FXML
  import javafx.fxml.Initializable
  import javafx.scene.layout.StackPane
9e952e84e   lsagona   add message clust...
7
  import map.*
53f01ecc3   lsagona   display message o...
8
9
  import java.net.URL
  import java.util.*
53f01ecc3   lsagona   display message o...
10

2bbe36a1b   lsagona   addd the possibil...
11
  class MapPanelController : Initializable {
53f01ecc3   lsagona   display message o...
12
13
14
15
16
17
18
19
  
      @FXML
      private lateinit var map: StackPane
  
      private val mapView = LeafletMapView()
  
  
      override fun initialize(location: URL?, resources: ResourceBundle?) {
79b001037   lsagona   heat map
20
          mapView.displayMap(MapConfig())
9e952e84e   lsagona   add message clust...
21
22
23
          setObservableVesselListener()
          setObservableSelectedVesselListener()
          setStateListener()
79b001037   lsagona   heat map
24
25
          /*val completeFutureMap: CompletableFuture<Worker.State> = mapView.displayMap(MapConfig())
          completeFutureMap.whenComplete{
9e952e84e   lsagona   add message clust...
26
27
28
29
30
31
32
33
34
35
36
              workerState, _ ->
              if (workerState == Worker.State.SUCCEEDED) {
              }
          }*/
          map.children.add(mapView)
          map.children
      }
  
      private fun setStateListener() {
          observableState.listeners.add(object : StateListener {
              override fun onValueChanged(newValue: State) {
79b001037   lsagona   heat map
37
38
39
40
41
                  if (observableSelectedVessel.vessel.mmsi != null) {
                      updateMap(observableSelectedVessel.vessel.mmsi!!)
                  } else {
                      updateMap()
                  }
9e952e84e   lsagona   add message clust...
42
43
44
45
46
              }
          })
      }
  
      private fun updateMap() {
79b001037   lsagona   heat map
47
48
          when (observableState.state) {
              ALL_MESSAGES -> displayAllMessageOnMap(mapView)
9e952e84e   lsagona   add message clust...
49
50
51
52
53
54
              CLUSTERED_MESSAGES -> displayClusterMessageOnMap(mapView)
              HEAT_MAP -> displayHeatMapOnMap(mapView)
          }
      }
  
      private fun updateMap(selectedMMSI: Int) {
79b001037   lsagona   heat map
55
56
          when (observableState.state) {
              ALL_MESSAGES -> displayAllMessageOnMap(mapView, selectedMMSI)
9e952e84e   lsagona   add message clust...
57
58
59
60
61
62
              CLUSTERED_MESSAGES -> displayClusterMessageOnMap(mapView, selectedMMSI)
              HEAT_MAP -> displayHeatMapOnMap(mapView, selectedMMSI)
          }
      }
  
      private fun setObservableVesselListener() {
2bbe36a1b   lsagona   addd the possibil...
63
64
          observableVessel.listeners.add(object : MessageListener {
              override fun onValueChanged(newValue: MutableMap<Int?, Vessel>) {
9e952e84e   lsagona   add message clust...
65
                  updateMap()
2bbe36a1b   lsagona   addd the possibil...
66
67
              }
          })
9e952e84e   lsagona   add message clust...
68
      }
2bbe36a1b   lsagona   addd the possibil...
69

9e952e84e   lsagona   add message clust...
70
      private fun setObservableSelectedVesselListener() {
2bbe36a1b   lsagona   addd the possibil...
71
72
          observableSelectedVessel.listeners.add(object : SelectedVesselListener {
              override fun onValueChanged(newValue: Vessel) {
79b001037   lsagona   heat map
73
74
75
                  if (newValue.mmsi != null){
                      updateMap(newValue.mmsi)
                  }
2bbe36a1b   lsagona   addd the possibil...
76
77
              }
          })
53f01ecc3   lsagona   display message o...
78
      }
53f01ecc3   lsagona   display message o...
79
80
  
  }