kt
unknown
kotlin
2 years ago
1.1 kB
16
Indexable
class CustomMarker(
context: Context?,
mapView: MapView?,
label: String?,
position: GeoPoint?
) : Marker(mapView) {
private val labelText: String = label ?: ""
private val painttext: Paint = Paint()
init {
title = labelText
setIcon(null) // You can set a custom icon if needed
position?.let { setPosition(it) }
painttext.color = android.graphics.Color.WHITE
// Customize label text color
painttext.textSize = 20f // Customize label text size
painttext.textAlign = Paint.Align.CENTER
setAnchor(Marker.ANCHOR_CENTER,Marker.ANCHOR_TOP)
}
override fun draw(canvas: Canvas?, mapView: MapView?, shadow: Boolean) {
super.draw(canvas, mapView, shadow)
if (!shadow) {
// Draw label text on the marker
val mpostion = mapView?.projection?.toPixels(this.position,null)
mpostion?.let {
canvas?.drawText(labelText, it.x.toFloat(), it.y.toFloat(), painttext)
}
}
}
}Editor is loading...