Skip to content

Commit

Permalink
refactor(map): set fixed maxZoomLevel (20.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir committed Oct 5, 2024
1 parent 625bc68 commit be6ea79
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/src/main/java/com/geeksville/mesh/ui/map/MapFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ private fun MapView.addMapEventListener(onEvent: () -> Unit) {
}, INACTIVITY_DELAY_MILLIS))
}

private const val MaxZoomLevel = 20.0

@Composable
fun MapView(
model: UIViewModel = viewModel(),
Expand Down Expand Up @@ -519,7 +521,7 @@ fun MapView(
val id = mPrefs.getInt(mapStyleId, 0)
debug("mapStyleId from prefs: $id")
return CustomTileSource.getTileSource(id).also {
map.maxZoomLevel = it.maximumZoomLevel.toDouble()
zoomLevelMax = it.maximumZoomLevel.toDouble()
showDownloadButton =
if (it is OnlineTileSourceBase) it.tileSourcePolicy.acceptsBulkDownload() else false
}
Expand All @@ -531,8 +533,7 @@ fun MapView(
fun MapView.generateBoxOverlay() {
overlays.removeAll { it is Polygon }
val zoomFactor = 1.3 // zoom difference between view and download area polygon
zoomLevelMax = maxZoomLevel
zoomLevelMin = maxOf(zoomLevelDouble, maxZoomLevel)
zoomLevelMin = minOf(zoomLevelDouble, zoomLevelMax)
downloadRegionBoundingBox = boundingBox.zoomIn(zoomFactor)
val polygon = Polygon().apply {
points = Polygon.pointsAsRect(downloadRegionBoundingBox).map {
Expand Down Expand Up @@ -665,6 +666,7 @@ fun MapView(
isTilesScaledToDpi = true
// sets the minimum zoom level (the furthest out you can zoom)
minZoomLevel = 1.5
maxZoomLevel = MaxZoomLevel
// Disables default +/- button for zooming
zoomController.setVisibility(CustomZoomButtonsController.Visibility.NEVER)
addMapEventListener {
Expand Down

0 comments on commit be6ea79

Please sign in to comment.