Blame view
src/main/kotlin/map/Marker.kt
4.27 KB
53f01ecc3 display message o... |
1 2 3 |
package map import application.model.Vessel |
d06a68ec6 add Leaflet Kotli... |
4 |
|
d06a68ec6 add Leaflet Kotli... |
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/** * Creates a marker at the specified geographical position. * * @author Niklas Kellner * * @param position marker position * @param title marker title shown in tooltip (pass empty string when tooltip not needed) * @param zIndexOffset zIndexOffset (higher number means on top) * */ class Marker private constructor(private var position: LatLong, private var zIndexOffset: Int) { private var marker = "aircraftIcon" private var markerSmall = "aircraftSmallIcon" private lateinit var map: LeafletMapView private var attached = false private var clickable = false private var name = "" private var tooltip = "" private var rotation = 0 private lateinit var aircraft: Vessel |
d06a68ec6 add Leaflet Kotli... |
26 |
private var relativeDate: Double = 0.0 |
53f01ecc3 display message o... |
27 28 29 30 31 32 33 |
constructor( position: LatLong, aircraft: Vessel, relativeDate: Double, aircraftIcon: String, zIndexOffset: Int ) : this(position, zIndexOffset) { |
d06a68ec6 add Leaflet Kotli... |
34 |
this.aircraft = aircraft |
d06a68ec6 add Leaflet Kotli... |
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
this.relativeDate = relativeDate this.marker = aircraftIcon } /** * Adds the marker to a map, gets called from the mapAddMarker * * @param nextMarkerName the variable name of the marker * @param map the LeafetMapView */ internal fun addToMap(nextMarkerName: String, map: LeafletMapView) { this.name = nextMarkerName this.map = map this.attached = true |
53f01ecc3 display message o... |
49 50 |
map.execScript( """ |
d06a68ec6 add Leaflet Kotli... |
51 52 53 54 55 56 57 |
|var currentZoom = myMap.getZoom(); |var $name; |if (currentZoom < ${map.zoomLimitSmallMarker}) { |$name = L.marker([${position.latitude}, ${position.longitude}], {title: '', icon: $markerSmall, zIndexOffset: $zIndexOffset}).addTo(markersGroup); |} else { |$name = L.marker([${position.latitude}, ${position.longitude}], {title: '', icon: $marker, zIndexOffset: $zIndexOffset}).addTo(markersGroup); |} |
53f01ecc3 display message o... |
58 59 60 |
""".trimMargin() ) // setTooltip() |
d06a68ec6 add Leaflet Kotli... |
61 62 63 64 65 66 |
if (clickable) { setClickable() } } fun setTooltip() { |
53f01ecc3 display message o... |
67 |
this.tooltip = "TODO" |
d06a68ec6 add Leaflet Kotli... |
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
this.tooltip = tooltip.replace(" ", "<br>") this.tooltip = tooltip.replace("'", "'") map.execScript("$name.bindTooltip('<div id=\"html_c92f9552ec164f36978869550cb44ffe\" style=\"width: 100.0%; height: 100.0%;\">${this.tooltip}</div>');") } /** * Changes the icon of the marker * * @param newIcon the name of the new icon */ fun changeIcon(newIcon: String) { this.marker = newIcon if (attached) { map.execScript("$name.setIcon($marker);") } } /** * Changes the icon of the marker * * @param newIcon the new ColorMarker */ fun changeIcon(newIcon: ColorMarker) { this.marker = newIcon.iconName if (attached) { map.execScript("$name.setIcon(${newIcon.iconName});") } } /** * Moves the existing marker specified by the variable name to the new geographical position. * * @param position new marker position */ fun move(position: LatLong) { this.position = position if (attached) { map.execScript("$name.setLatLng([${this.position.latitude}, ${this.position.longitude}]);") setTooltip() } } fun move(position: LatLong, aircraft: Vessel, relativeDate: Double) { this.aircraft = aircraft this.relativeDate = relativeDate this.position = position if (attached) { map.execScript("$name.setLatLng([${this.position.latitude}, ${this.position.longitude}]);") } } fun setRotation(rotation: Int) { if (rotation > 360 || rotation < 0) { this.rotation = 0 } else { this.rotation = rotation } if (attached) { map.execScript("$name.setRotationAngle(${this.rotation})") } } /** * Sets the marker clickable */ private fun setClickable() { this.clickable = true if (attached) { map.execScript("$name.on('click', function(e){ document.java.markerClick($name.options.title)})") } } internal fun getName(): String = this.name } |