Fix: Colored transparent precision circles around nodes on map (#1190)

This commit is contained in:
James Rich 2024-08-20 15:04:36 -05:00 committed by GitHub
parent 94ff201822
commit da2a9f82fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 48 deletions

View file

@ -7,6 +7,7 @@ import android.graphics.RectF
import android.view.MotionEvent
import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.Marker
import org.osmdroid.views.overlay.Polygon
class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) : Marker(mapView) {
@ -15,6 +16,34 @@ class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) :
private const val LABEL_Y_OFFSET = 100F
}
private var nodeColor: Int = Color.GRAY
fun setNodeColors(colors: Pair<Int, Int>) {
nodeColor = colors.second
}
private var precisionBits: Int? = null
fun setPrecisionBits(bits: Int) {
precisionBits = bits
}
@Suppress("MagicNumber")
private fun getPrecisionMeters(): Double? {
return when (precisionBits) {
10 -> 23345.484932
11 -> 11672.7369
12 -> 5836.36288
13 -> 2918.175876
14 -> 1459.0823719999053
15 -> 729.53562
16 -> 364.7622
17 -> 182.375556
18 -> 91.182212
19 -> 45.58554
else -> null
}
}
private var onLongClickListener: (() -> Boolean)? = null
fun setOnLongClickListener(listener: () -> Boolean) {
@ -57,6 +86,7 @@ class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) :
return super.onLongPress(event, mapView)
}
@Suppress("MagicNumber")
override fun draw(c: Canvas, osmv: MapView?, shadow: Boolean) {
super.draw(c, osmv, false)
val p = mPositionPixels
@ -66,6 +96,23 @@ class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) :
c.drawRoundRect(bgRect, LABEL_CORNER_RADIUS, LABEL_CORNER_RADIUS, bgPaint)
c.drawText(mLabel, (p.x - 0F), (p.y - LABEL_Y_OFFSET), textPaint)
mEmoji?.let { c.drawText(it, (p.x - 0f), (p.y - 30f), emojiPaint) }
}
getPrecisionMeters()?.let { radius ->
val polygon = Polygon(osmv).apply {
points = Polygon.pointsAsCircle(
position,
radius
)
fillPaint.apply {
color = nodeColor
alpha = 48
}
outlinePaint.apply {
color = nodeColor
alpha = 64
}
}
polygon.draw(c, osmv, false)
}
}
}