MapPanelController.kt
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package application.controller
import application.model.*
import application.model.MapState.*
import javafx.fxml.FXML
import javafx.fxml.Initializable
import javafx.scene.layout.StackPane
import map.*
import java.net.URL
import java.util.*
class MapPanelController : Initializable {
@FXML
private lateinit var map: StackPane
private val mapView = LeafletMapView()
override fun initialize(location: URL?, resources: ResourceBundle?) {
mapView.displayMap(MapConfig())
setObservableVesselListener()
setObservableSelectedVesselListener()
setStateListener()
observableCurrentTime()
/*val completeFutureMap: CompletableFuture<Worker.State> = mapView.displayMap(MapConfig())
completeFutureMap.whenComplete{
workerState, _ ->
if (workerState == Worker.State.SUCCEEDED) {
}
}*/
map.children.add(mapView)
map.children
}
private fun setStateListener() {
observableMapState.listeners.add(object : StateListener {
override fun onValueChanged(newValue: MapState) {
if (observableSelectedVessel.vessel.mmsi != null) {
updateMap(observableSelectedVessel.vessel.mmsi!!)
} else {
updateMap()
}
}
})
}
private fun observableCurrentTime() {
observableCurrentTime.listeners.add(object : CurrentTime{
override fun onValueChanged(newValue: Int) {
updateMap()
}
})
}
private fun updateMap() {
if (observableIsReplayState.value){
displayTargetedVessels(mapView)
} else {
when (observableMapState.state) {
ALL_MESSAGES -> displayAllMessageOnMap(mapView)
CLUSTERED_MESSAGES -> displayClusterMessageOnMap(mapView)
HEAT_MAP -> displayHeatMapOnMap(mapView)
}
}
}
private fun updateMap(selectedMMSI: String) {
when (observableMapState.state) {
ALL_MESSAGES -> displayAllMessageOnMap(mapView, selectedMMSI)
CLUSTERED_MESSAGES -> displayClusterMessageOnMap(mapView, selectedMMSI)
HEAT_MAP -> displayHeatMapOnMap(mapView, selectedMMSI)
}
}
private fun setObservableVesselListener() {
observableVessel.listeners.add(object : MessageListener {
override fun onValueChanged(newValue: MutableMap<String?, Vessel>) {
updateMap()
}
})
}
private fun setObservableSelectedVesselListener() {
observableSelectedVessel.listeners.add(object : SelectedVesselListener {
override fun onValueChanged(newValue: Vessel) {
if (newValue.mmsi != null){
updateMap(newValue.mmsi)
}else {
updateMap()
}
}
})
}
}