package fdit.leafletmap
import fdit.gui.graphicalScenarioEditor.GraphicalScenarioEditorContext
import fdit.gui.utils.tooltip.VesselTooltipUtils.formatVesselSnapshotTooltip
import fdit.metamodel.vessel.Vessel
/**
* 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
private lateinit var context: GraphicalScenarioEditorContext
private var relativeDate: Double = 0.0
constructor(position: LatLong, aircraft: Vessel, relativeDate: Double, context: GraphicalScenarioEditorContext, aircraftIcon: String, zIndexOffset: Int) : this(position, zIndexOffset){
this.aircraft = aircraft
this.context = context
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
map.execScript("""
|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);
|}
""".trimMargin())
setTooltip()
if (clickable) {
setClickable()
}
}
fun setTooltip() {
this.tooltip = formatVesselSnapshotTooltip(aircraft,
context.getGraphicalScenario().getRecording(),
relativeDate)
this.tooltip = tooltip.replace("\n", "
")
this.tooltip = tooltip.replace("'", "'")
map.execScript("$name.bindTooltip('