Blame view
src/main/kotlin/map/Circle.kt
2.19 KB
53f01ecc3 display message o... |
1 |
package map |
d06a68ec6 add Leaflet Kotli... |
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 |
import javafx.scene.paint.Color class Circle private constructor(private var center: LatLong, private var title: String, private var zIndexOffset: Int) { private var color = Color(0.0, 0.0, 0.0, 0.0) private lateinit var map: LeafletMapView private var isAttached = false private var isDisplayed = false private var radius = 0.0 constructor(position: LatLong, radius: Double, title: String, color: Color, zIndexOffset: Int) : this(position, title, zIndexOffset) { this.color = color this.title = title.replace("-", "") this.center = position this.radius = nauticalMilesToMeter(radius) } internal fun addToMap(map: LeafletMapView) { this.map = map if (map.execScript("typeof circle$title == 'undefined'") as Boolean) { map.execScript("var circle$title;") } if (!this.isAttached) { val hexColor = "%02x".format((color.red * 255).toInt()) + "%02x".format((color.green * 255).toInt()) + "%02x".format((color.blue * 255).toInt()) map.execScript("circle$title = L.circle([${center.latitude}, ${center.longitude}], $radius, {color:'#$hexColor'}).addTo(myMap);") this.isAttached = true this.isDisplayed = true } else if (!this.isDisplayed) { map.execScript("circle$title.addTo(myMap)") this.isDisplayed = true } } fun modifyCircle(latLong: LatLong, radius: Double) { this.center = latLong this.radius = radius this.radius = nauticalMilesToMeter(radius) } fun uppdateMap() { if (this.isAttached && !this.isDisplayed) { map.execScript("myMap.removeLayer(circle$title);" + "circle$title = L.circle([${center.latitude}, ${center.longitude}], $radius).addTo(myMap);") this.isDisplayed = true } } internal fun removeCircle(map: LeafletMapView) { if (this.isAttached && this.isDisplayed) { map.execScript("myMap.removeLayer(circle$title);") this.isDisplayed = false } } private fun nauticalMilesToMeter(nauticalMiles: Double): Double { return nauticalMiles * 1.852 } } |