Blame view

src/main/kotlin/map/MapDisplayer.kt 3.77 KB
53f01ecc3   lsagona   display message o...
1
  package map
2bbe36a1b   lsagona   addd the possibil...
2
  import application.model.observableVessel
53f01ecc3   lsagona   display message o...
3

9e952e84e   lsagona   add message clust...
4
5
6
  fun clearMap(map: LeafletMapView) {
      clearMapCanvas(map)
      clearMapCluster(map)
79b001037   lsagona   heat map
7
      clearHeatMap(map)
9e952e84e   lsagona   add message clust...
8
9
10
11
12
  }
  
  fun clearMapCluster(map: LeafletMapView) {
      map.execScript(
          """
79b001037   lsagona   heat map
13
14
          |myMap.removeLayer(markerClusters);
          |var markerClusters = L.markerClusterGroup({spiderfyOnMaxZoom: false, disableClusteringAtZoom: 10});
9e952e84e   lsagona   add message clust...
15
16
17
      """.trimMargin()
      )
  }
43370abfe   lsagona   clear map canvas ...
18
  fun clearMapCanvas(map: LeafletMapView) {
9e952e84e   lsagona   add message clust...
19
20
      map.execScript(
          """
79b001037   lsagona   heat map
21
          |myRenderer.removeFrom(myMap);
43370abfe   lsagona   clear map canvas ...
22
          |var myRenderer = L.canvas({ padding: 0.5 });
9e952e84e   lsagona   add message clust...
23
24
      """.trimMargin()
      )
53f01ecc3   lsagona   display message o...
25
  }
79b001037   lsagona   heat map
26
27
28
29
30
31
32
33
  fun clearHeatMap(map: LeafletMapView) {
      map.execScript(
          """
          |heatLayer.removeFrom(myMap);
          |var heatLayer = L.heatLayer([]).addTo(myMap);
      """.trimMargin()
      )
  }
9e952e84e   lsagona   add message clust...
34
35
  fun displayAllMessageOnMap(map: LeafletMapView) {
      clearMap(map)
2bbe36a1b   lsagona   addd the possibil...
36
      observableVessel.vessels.forEach { (_, value) ->
53f01ecc3   lsagona   display message o...
37
          value.messages.forEach { (_, message) ->
79b001037   lsagona   heat map
38
              map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap)")
53f01ecc3   lsagona   display message o...
39
40
          }
      }
2bbe36a1b   lsagona   addd the possibil...
41
  }
9e952e84e   lsagona   add message clust...
42
43
  fun displayAllMessageOnMap(map: LeafletMapView, selectedMMSI: Int) {
      clearMap(map)
2bbe36a1b   lsagona   addd the possibil...
44
45
      observableVessel.vessels.forEach { (_, value) ->
          value.messages.forEach { (_, message) ->
9e952e84e   lsagona   add message clust...
46
              if (selectedMMSI == message.mmsi) {
79b001037   lsagona   heat map
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
                  map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap)")
              } else {
                  map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap)")
              }
          }
      }
  }
  
  fun displayClusterMessageOnMap(map: LeafletMapView) {
      clearMap(map)
      observableVessel.vessels.forEach { (_, value) ->
          value.messages.forEach { (_, message) ->
              map.execScript("markerClusters.addLayer(L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}));")
          }
      }
      map.execScript("myMap.addLayer(markerClusters);")
  }
  
  fun displayClusterMessageOnMap(map: LeafletMapView, selectedMMSI: Int) {
      clearMap(map)
      observableVessel.vessels.forEach { (_, value) ->
          value.messages.forEach { (_, message) ->
              if (selectedMMSI == message.mmsi) {
                  map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap);")
              } else {
                  map.execScript("markerClusters.addLayer(L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}));")
              }
          }
      }
      map.execScript("myMap.addLayer(markerClusters);")
  }
  
  fun displayHeatMapOnMap(map: LeafletMapView) {
      clearMap(map)
      observableVessel.vessels.forEach { (_, value) ->
          value.messages.forEach { (_, message) ->
              map.execScript("heatLayer.addLatLng([${message.latitude}, ${message.longitude}]);")
          }
      }
79b001037   lsagona   heat map
86
87
88
89
90
91
92
93
  }
  
  fun displayHeatMapOnMap(map: LeafletMapView, selectedMMSI: Int) {
      clearMap(map)
      observableVessel.vessels.forEach { (_, value) ->
          value.messages.forEach { (_, message) ->
              if (selectedMMSI == message.mmsi) {
                  map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap);")
9e952e84e   lsagona   add message clust...
94
              } else {
79b001037   lsagona   heat map
95
                  map.execScript("heatLayer.addLatLng([${message.latitude}, ${message.longitude}]);")
2bbe36a1b   lsagona   addd the possibil...
96
97
98
              }
          }
      }
79b001037   lsagona   heat map
99
      map.execScript("myMap.addLayer(markerClusters);")
53f01ecc3   lsagona   display message o...
100
  }