fixed zooming to nodes (lat/lon were reversed)

master
PWRxPSYCHO 2022-08-24 16:47:50 -04:00
rodzic 6a6dbad0ee
commit 3e81abb638
1 zmienionych plików z 15 dodań i 11 usunięć

Wyświetl plik

@ -1,6 +1,5 @@
package com.geeksville.mesh.ui package com.geeksville.mesh.ui
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
@ -29,7 +28,6 @@ import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.CopyrightOverlay import org.osmdroid.views.overlay.CopyrightOverlay
import org.osmdroid.views.overlay.Marker import org.osmdroid.views.overlay.Marker
@AndroidEntryPoint @AndroidEntryPoint
class MapFragment : ScreenFragment("Map"), Logging { class MapFragment : ScreenFragment("Map"), Logging {
@ -40,7 +38,8 @@ class MapFragment : ScreenFragment("Map"), Logging {
private val model: UIViewModel by activityViewModels() private val model: UIViewModel by activityViewModels()
private val defaultMinZoom = 3.0 private val defaultMinZoom = 3.0
private val defaultZoomLevel = 6.0
private val nodeZoomLevel = 8.5
private val defaultZoomSpeed = 3000L private val defaultZoomSpeed = 3000L
private val prefsName = "org.andnav.osm.prefs" private val prefsName = "org.andnav.osm.prefs"
private val prefsZoomLevelDouble = "prefsZoomLevelDouble" private val prefsZoomLevelDouble = "prefsZoomLevelDouble"
@ -56,7 +55,6 @@ class MapFragment : ScreenFragment("Map"), Logging {
): View { ): View {
binding = MapViewBinding.inflate(inflater, container, false) binding = MapViewBinding.inflate(inflater, container, false)
map = binding.map map = binding.map
map.setDestroyMode(false)
map.tag = mapTag map.tag = mapTag
return binding.root return binding.root
} }
@ -134,7 +132,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
requireActivity(), requireActivity(),
R.drawable.ic_twotone_person_pin_24 R.drawable.ic_twotone_person_pin_24
) )
map.invalidate()
map.overlays.add(marker) map.overlays.add(marker)
} }
f f
@ -168,22 +166,28 @@ class MapFragment : ScreenFragment("Map"), Logging {
val nodesWithPosition = val nodesWithPosition =
model.nodeDB.nodes.value?.values?.filter { it.validPosition != null } model.nodeDB.nodes.value?.values?.filter { it.validPosition != null }
if ((nodesWithPosition != null) && nodesWithPosition.isNotEmpty()) { if ((nodesWithPosition != null) && nodesWithPosition.isNotEmpty()) {
val unit = if (nodesWithPosition.size >= 2) { if (nodesWithPosition.size >= 2) {
// Multiple nodes, make them all fit on the map view // Multiple nodes, make them all fit on the map view
nodesWithPosition.forEach { nodesWithPosition.forEach {
points.add( points.add(
GeoPoint( GeoPoint(
it.position!!.longitude, it.position!!.latitude,
it.position!!.latitude it.position!!.longitude
) )
) )
} }
map.zoomToBoundingBox(BoundingBox.fromGeoPoints(points), true) map.zoomToBoundingBox(
BoundingBox.fromGeoPoints(points),
true,
15,
nodeZoomLevel,
defaultZoomSpeed
)
} else { } else {
// Only one node, just zoom in on it // Only one node, just zoom in on it
val it = nodesWithPosition[0].position!! val it = nodesWithPosition[0].position!!
points.add(GeoPoint(it.longitude, it.latitude)) points.add(GeoPoint(it.latitude, it.longitude))
controller.animateTo(points[0], defaultZoomLevel, defaultZoomSpeed) controller.animateTo(points[0], nodeZoomLevel, defaultZoomSpeed)
} }
} }
} }