kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
feat: add map `ScaleBarOverlay`
rodzic
c6cc33e16c
commit
eea62e6533
|
@ -30,6 +30,7 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
@ -85,6 +86,7 @@ import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
|
|||
import com.geeksville.mesh.model.map.clustering.RadiusMarkerClusterer
|
||||
import com.geeksville.mesh.util.addCopyright
|
||||
import com.geeksville.mesh.util.addMapEventListener
|
||||
import com.geeksville.mesh.util.addScaleBarOverlay
|
||||
import com.geeksville.mesh.util.createLatLongGrid
|
||||
import java.io.File
|
||||
import java.text.DateFormat
|
||||
|
@ -230,6 +232,7 @@ fun MapView(
|
|||
var myLocationOverlay: MyLocationNewOverlay? by remember { mutableStateOf(null) }
|
||||
|
||||
val context = LocalContext.current
|
||||
val density = LocalDensity.current
|
||||
val mPrefs = remember { context.getSharedPreferences(prefsName, Context.MODE_PRIVATE) }
|
||||
|
||||
val haptic = LocalHapticFeedback.current
|
||||
|
@ -441,6 +444,7 @@ fun MapView(
|
|||
}
|
||||
|
||||
addCopyright() // Copyright is required for certain map sources
|
||||
addScaleBarOverlay(density)
|
||||
createLatLongGrid(false)
|
||||
|
||||
invalidate()
|
||||
|
|
|
@ -2,12 +2,17 @@ package com.geeksville.mesh.util
|
|||
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Typeface
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import org.osmdroid.events.DelayedMapListener
|
||||
import org.osmdroid.events.MapListener
|
||||
import org.osmdroid.events.ScrollEvent
|
||||
import org.osmdroid.events.ZoomEvent
|
||||
import org.osmdroid.views.MapView
|
||||
import org.osmdroid.views.overlay.CopyrightOverlay
|
||||
import org.osmdroid.views.overlay.ScaleBarOverlay
|
||||
import org.osmdroid.views.overlay.gridlines.LatLonGridlineOverlay2
|
||||
|
||||
/**
|
||||
|
@ -45,6 +50,23 @@ fun MapView.createLatLongGrid(enabled: Boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
fun MapView.addScaleBarOverlay(density: Density) {
|
||||
if (overlays.none { it is ScaleBarOverlay }) {
|
||||
val scaleBarOverlay = ScaleBarOverlay(this).apply {
|
||||
setAlignBottom(true)
|
||||
with(density) {
|
||||
setScaleBarOffset(15.dp.toPx().toInt(), 40.dp.toPx().toInt())
|
||||
setTextSize(12.sp.toPx())
|
||||
}
|
||||
textPaint.apply {
|
||||
isAntiAlias = true
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
}
|
||||
}
|
||||
overlays.add(scaleBarOverlay)
|
||||
}
|
||||
}
|
||||
|
||||
private const val INACTIVITY_DELAY_MILLIS = 500L
|
||||
fun MapView.addMapEventListener(onEvent: () -> Unit) {
|
||||
addMapListener(DelayedMapListener(object : MapListener {
|
||||
|
|
Ładowanie…
Reference in New Issue