kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
up to date with master and fixed CacheManager
commit
dae89d349a
|
@ -17,10 +17,11 @@ import android.widget.*
|
|||
import android.widget.SeekBar.OnSeekBarChangeListener
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.BuildConfig
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.database.entity.Packet
|
||||
import com.geeksville.mesh.databinding.MapViewBinding
|
||||
import com.geeksville.mesh.model.CustomTileSource
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
|
@ -74,6 +75,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
private val prefsName = "org.geeksville.osm.prefs"
|
||||
private val mapStyleId = "map_style_id"
|
||||
private var nodePositions = listOf<MarkerWithLabel>()
|
||||
private var wayPoints = listOf<MarkerWithLabel>()
|
||||
private val nodeLayer = 1
|
||||
|
||||
|
||||
|
@ -94,7 +96,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
|
||||
setupMapProperties()
|
||||
map.setTileSource(loadOnlineTileSourceBase())
|
||||
cacheManager = CacheManager(map)
|
||||
map.let {
|
||||
if (view != null) {
|
||||
mapController = map.controller
|
||||
|
@ -113,7 +114,8 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
}
|
||||
model.waypoints.observe(viewLifecycleOwner) {
|
||||
debug("New waypoints received: ${it.size}")
|
||||
// build Collection<Packet> from (it.values)
|
||||
onWaypointChanged(it.values)
|
||||
drawOverlays()
|
||||
}
|
||||
zoomToNodes(mapController)
|
||||
}
|
||||
|
@ -165,6 +167,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
|
||||
private fun showCurrentCacheInfo() {
|
||||
Toast.makeText(activity, "Calculating...", Toast.LENGTH_SHORT).show()
|
||||
cacheManager = CacheManager(map) // Make sure CacheManager has latest from map
|
||||
Thread {
|
||||
val alertDialogBuilder = AlertDialog.Builder(
|
||||
activity
|
||||
|
@ -244,6 +247,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
* if false, just update the dialog box
|
||||
*/
|
||||
private fun updateEstimate(startJob: Boolean) {
|
||||
cacheManager = CacheManager(map) // Make sure cacheManager has latest from map
|
||||
try {
|
||||
if (cacheWest.text != null && cacheNorth.text != null && cacheSouth.text != null && ::zoomMax.isInitialized && ::zoomMin.isInitialized) {
|
||||
val n: Double = cacheNorth.text.toString().toDouble()
|
||||
|
@ -323,6 +327,34 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
dialog.show()
|
||||
}
|
||||
|
||||
private fun onWaypointChanged(wayPt: Collection<Packet>) {
|
||||
|
||||
/**
|
||||
* Using the latest waypoint, generate GeoPoint
|
||||
*/
|
||||
// Find all waypoints
|
||||
fun getCurrentWayPoints(): List<MarkerWithLabel> {
|
||||
val wayPoint = wayPt.map { pt ->
|
||||
debug("Showing on map: $pt")
|
||||
lateinit var marker: MarkerWithLabel
|
||||
pt.data.waypoint?.let {
|
||||
val label = it.name + " " + formatAgo(it.expire)
|
||||
marker = MarkerWithLabel(map, label)
|
||||
marker.title = it.name
|
||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||
marker.position = GeoPoint(it.latitudeI.toDouble(), it.longitudeI.toDouble())
|
||||
marker.icon = ContextCompat.getDrawable(
|
||||
requireActivity(),
|
||||
R.drawable.ic_baseline_location_on_24
|
||||
)
|
||||
}
|
||||
marker
|
||||
}
|
||||
return wayPoint
|
||||
}
|
||||
wayPoints = getCurrentWayPoints()
|
||||
}
|
||||
|
||||
private fun onNodesChanged(nodes: Collection<NodeInfo>) {
|
||||
val nodesWithPosition = nodes.filter { it.validPosition != null }
|
||||
|
||||
|
@ -362,6 +394,8 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
map.overlayManager.overlays().clear()
|
||||
addCopyright() // Copyright is required for certain map sources
|
||||
map.overlayManager.addAll(nodeLayer, nodePositions)
|
||||
map.overlayManager.addAll(nodeLayer, wayPoints)
|
||||
map.invalidate()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Ładowanie…
Reference in New Issue