kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Fix: Colored transparent precision circles around nodes on map (#1190)
rodzic
94ff201822
commit
da2a9f82fc
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import androidx.compose.ui.platform.LocalHapticFeedback
|
|||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
|
@ -108,36 +107,10 @@ class MapFragment : ScreenFragment("Map Fragment"), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
private enum class PositionPrecision(val value: Int, val precisionMeters: Double) {
|
||||
TWO(2, 5976446.981252),
|
||||
THREE(3, 2988223.4850600003),
|
||||
FOUR(4, 1494111.7369640006),
|
||||
FIVE(5, 747055.8629159998),
|
||||
SIX(6, 373527.9258920002),
|
||||
SEVEN(7, 186763.95738000044),
|
||||
EIGHT(8, 93381.97312400135),
|
||||
NINE(9, 46690.98099600022),
|
||||
TEN(10, 23345.48493200123),
|
||||
ELEVEN(11, 11672.736900000944),
|
||||
TWELVE(12, 5836.362884000802),
|
||||
THIRTEEN(13, 2918.1758760007315),
|
||||
FOURTEEN(14, 1459.0823719999053),
|
||||
FIFTEEN(15, 729.5356200010741),
|
||||
SIXTEEN(16, 364.7622440000765),
|
||||
SEVENTEEN(17, 182.37555600115968),
|
||||
EIGHTEEN(18, 91.1822120001193),
|
||||
NINETEEN(19, 45.58554000039009),
|
||||
TWENTY(20, 22.787204001316468),
|
||||
TWENTY_ONE(21, 11.388036000988677),
|
||||
TWENTY_TWO(22, 5.688452000824781),
|
||||
TWENTY_THREE(23, 2.8386600007428338),
|
||||
TWENTY_FOUR(24, 1.413763999910884),
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MapView.UpdateMarkers(
|
||||
nodeMarkers: List<MarkerWithLabel>,
|
||||
waypointMarkers: List<MarkerWithLabel>,
|
||||
waypointMarkers: List<MarkerWithLabel>
|
||||
) {
|
||||
debug("Showing on map: ${nodeMarkers.size} nodes ${waypointMarkers.size} waypoints")
|
||||
overlays.removeAll(overlays.filterIsInstance<MarkerWithLabel>())
|
||||
|
@ -172,7 +145,6 @@ fun MapView(
|
|||
val hasGps = context.hasGps()
|
||||
|
||||
val map = rememberMapViewWithLifecycle(context)
|
||||
val primaryColor = ContextCompat.getColor(context, R.color.colorPrimary)
|
||||
|
||||
fun MapView.toggleMyLocation() {
|
||||
if (context.gpsDisabled()) {
|
||||
|
@ -243,6 +215,7 @@ fun MapView(
|
|||
val displayUnits = model.config.display.units.number
|
||||
return nodesWithPosition.map { node ->
|
||||
val (p, u) = node.position!! to node.user!!
|
||||
val nodePosition = GeoPoint(p.latitude, p.longitude)
|
||||
MarkerWithLabel(
|
||||
mapView = this,
|
||||
label = "${u.shortName} ${formatAgo(p.time)}"
|
||||
|
@ -255,31 +228,16 @@ fun MapView(
|
|||
context.getString(R.string.map_subDescription, ourNode.bearing(node), dist)
|
||||
}
|
||||
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||
position = GeoPoint(p.latitude, p.longitude)
|
||||
position = nodePosition
|
||||
icon = markerIcon
|
||||
|
||||
PositionPrecision.entries.find { it.value == p.precisionBits }?.let { precision ->
|
||||
if (precision in PositionPrecision.TEN..PositionPrecision.NINETEEN) {
|
||||
if ((precision.precisionMeters) > 0) {
|
||||
val circle = Polygon.pointsAsCircle(
|
||||
position,
|
||||
precision.precisionMeters
|
||||
)
|
||||
val polygon = Polygon(this@onNodesChanged)
|
||||
polygon.points = circle
|
||||
polygon.fillPaint.color = primaryColor
|
||||
polygon.fillPaint.alpha = 64
|
||||
polygon.outlinePaint.color = primaryColor
|
||||
this@onNodesChanged.overlays.add(polygon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setOnLongClickListener {
|
||||
performHapticFeedback()
|
||||
model.focusUserNode(node)
|
||||
true
|
||||
}
|
||||
setNodeColors(node.colors)
|
||||
setPrecisionBits(p.precisionBits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue