kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
fix: calculate download BoundingBox based on zoom factor
instead of calling `setZoom()` before/after `MapView.boundingBox` which can get out of sync and cause inconsistencies in the tile count. fixes #670pull/674/head
rodzic
094af7c380
commit
49617d2e19
app/src/main/java/com/geeksville/mesh
ui/map
util
|
@ -52,6 +52,7 @@ import com.geeksville.mesh.util.EnableWakeLock
|
|||
import com.geeksville.mesh.util.SqlTileWriterExt
|
||||
import com.geeksville.mesh.util.requiredZoomLevel
|
||||
import com.geeksville.mesh.util.formatAgo
|
||||
import com.geeksville.mesh.util.zoomIn
|
||||
import com.geeksville.mesh.waypoint
|
||||
import com.google.accompanist.themeadapter.appcompat.AppCompatTheme
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
@ -461,21 +462,21 @@ fun MapView(model: UIViewModel = viewModel()) {
|
|||
*/
|
||||
fun generateBoxOverlay(zoomLevel: Double) = map.apply {
|
||||
overlayManager = CustomOverlayManager(TilesOverlay(tileProvider, context))
|
||||
val zoomFactor = 1.3 // zoom difference between view and download area polygon
|
||||
controller.setZoom(zoomLevel - zoomFactor)
|
||||
setMultiTouchControls(false)
|
||||
// furthest back
|
||||
zoomLevelMax = zoomLevelHighest // FIXME zoomLevel
|
||||
// furthest in min should be > than max
|
||||
zoomLevelMin = map.tileProvider.tileSource.maximumZoomLevel.toDouble()
|
||||
controller.setZoom(zoomLevel)
|
||||
downloadRegionBoundingBox = map.boundingBox
|
||||
zoomLevelMin = tileProvider.tileSource.maximumZoomLevel.toDouble()
|
||||
downloadRegionBoundingBox = boundingBox.zoomIn(zoomFactor)
|
||||
val polygon = Polygon().apply {
|
||||
points = Polygon.pointsAsRect(downloadRegionBoundingBox).map {
|
||||
GeoPoint(it.latitude, it.longitude)
|
||||
}
|
||||
}
|
||||
overlayManager.add(polygon)
|
||||
controller.setZoom(zoomLevel - 1.0)
|
||||
val tileCount: Int = CacheManager(map).possibleTilesInArea(
|
||||
val tileCount: Int = CacheManager(this).possibleTilesInArea(
|
||||
downloadRegionBoundingBox,
|
||||
zoomLevelMax.toInt(),
|
||||
zoomLevelMin.toInt()
|
||||
|
|
|
@ -12,6 +12,7 @@ import kotlin.math.acos
|
|||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.log2
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sin
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -251,3 +252,30 @@ fun BoundingBox.requiredZoomLevel(): Double {
|
|||
return maxOf(requiredLatZoom, requiredLonZoom)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new bounding box with adjusted dimensions based on the provided [zoomFactor].
|
||||
* @return A new [BoundingBox] with added [zoomFactor]. Example:
|
||||
* ```
|
||||
* // Setting the zoom level directly using setZoom()
|
||||
* map.setZoom(14.0)
|
||||
* val boundingBoxZoom14 = map.boundingBox
|
||||
*
|
||||
* // Using zoomIn() results the equivalent BoundingBox with setZoom(15.0)
|
||||
* val boundingBoxZoom15 = boundingBoxZoom14.zoomIn(1.0)
|
||||
* ```
|
||||
*/
|
||||
fun BoundingBox.zoomIn(zoomFactor: Double): BoundingBox {
|
||||
val center = GeoPoint((latNorth + latSouth) / 2, (lonWest + lonEast) / 2)
|
||||
val latDiff = latNorth - latSouth
|
||||
val lonDiff = lonEast - lonWest
|
||||
|
||||
val newLatDiff = latDiff / (2.0.pow(zoomFactor))
|
||||
val newLonDiff = lonDiff / (2.0.pow(zoomFactor))
|
||||
|
||||
return BoundingBox(
|
||||
center.latitude + newLatDiff / 2,
|
||||
center.longitude + newLonDiff / 2,
|
||||
center.latitude - newLatDiff / 2,
|
||||
center.longitude - newLonDiff / 2
|
||||
)
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue