From 43370abfea7cd24e86ea747adf23c021031c24dc Mon Sep 17 00:00:00 2001 From: lsagona Date: Fri, 17 Jul 2020 16:29:05 +0200 Subject: [PATCH] clear map canvas when importing new data set --- src/main/kotlin/map/CircleMarkerGenerator.kt | 8 ++++++-- src/main/kotlin/map/LeafletMapView.kt | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/map/CircleMarkerGenerator.kt b/src/main/kotlin/map/CircleMarkerGenerator.kt index c08da33..e30ebc0 100644 --- a/src/main/kotlin/map/CircleMarkerGenerator.kt +++ b/src/main/kotlin/map/CircleMarkerGenerator.kt @@ -2,11 +2,15 @@ package map import application.model.observableMessages -fun clearMap(map: LeafletMapView) { - map.clearAllLayer() +fun clearMapCanvas(map: LeafletMapView) { + map.execScript(""" + |myRenderer.removeFrom(myMap) + |var myRenderer = L.canvas({ padding: 0.5 }); + """.trimMargin()) } fun displayMessageOnMap(map: LeafletMapView) { + clearMapCanvas(map) observableMessages.vessels.forEach { (_, value) -> value.messages.forEach { (_, message) -> map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01}).addTo(myMap)") diff --git a/src/main/kotlin/map/LeafletMapView.kt b/src/main/kotlin/map/LeafletMapView.kt index 1228dc0..238805c 100644 --- a/src/main/kotlin/map/LeafletMapView.kt +++ b/src/main/kotlin/map/LeafletMapView.kt @@ -92,7 +92,7 @@ class LeafletMapView : StackPane() { | zoomControl: false, | layers: [layer1] |}); - |L.control.scale().addTo(mymap); + |L.control.scale().addTo(myMap); |var myRenderer = L.canvas({ padding: 0.5 });""".trimMargin() ) -- 1.7.10.4