aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-16 02:31:26 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-16 02:31:26 -0600
commit18bc70d4fa7453c1191fc446327d1e24d5defe6d (patch)
treea6c977cae455374bbbc705c06d5c980286767f9a /androidApp/src/main
parent73a7543dbd286a4ff3b6bd4d3155823491102095 (diff)
downloadetbsa-trackermap-mobile-18bc70d4fa7453c1191fc446327d1e24d5defe6d.tar.gz
etbsa-trackermap-mobile-18bc70d4fa7453c1191fc446327d1e24d5defe6d.tar.bz2
etbsa-trackermap-mobile-18bc70d4fa7453c1191fc446327d1e24d5defe6d.zip
Set zoom limits of mapControl by converting zoom levels to Mapnik scale denominators
Diffstat (limited to 'androidApp/src/main')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt46
1 files changed, 38 insertions, 8 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
index 4a63e65..9fa37c9 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
@@ -18,6 +18,7 @@ import mil.nga.sf.wkt.GeometryReader
import java.io.File
import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.client.models.Geofence
+import mx.trackermap.TrackerMap.utils.MapCalculus
import mx.trackermap.TrackerMap.utils.MarkerType
typealias MarkerCallback = (Int?) -> Unit
@@ -60,7 +61,10 @@ class MapFragment : GlobeMapFragment() {
if (tileInfo == null) {
val layer = resources.getStringArray(R.array.maps_streets_tile_url)
val tmpInfo = RemoteTileInfoNew(layer[0], layer[1].toInt(), layer[2].toInt())
- tileInfo = makeTileInfo(layer[0], tmpInfo)
+ tileInfo = tileInfoSetCacheDir(layer[0], tmpInfo)
+ tileInfo?.let {
+ setZoomLimits(it.minZoom, it.maxZoom)
+ }
}
val params = SamplingParams()
@@ -77,7 +81,16 @@ class MapFragment : GlobeMapFragment() {
val latitude = 23.191
val longitude = -100.36
- focusOn(latitude, longitude, zoom = 0.4, animated = false)
+ focusOn(latitude, longitude, height = 0.4, animated = false)
+ }
+
+ override fun mapDidStopMoving(
+ mapControl: MapController?,
+ corners: Array<out Point3d>?,
+ userMotion: Boolean
+ ) {
+ super.mapDidStopMoving(mapControl, corners, userMotion)
+ Log.d("MapFragment", "Height: ${mapControl?.height}")
}
override fun userDidSelect(
@@ -221,7 +234,8 @@ class MapFragment : GlobeMapFragment() {
mbr.expandByFraction(0.1)
mapControl.addPostSurfaceRunnable {
- val zoom = mapControl.findHeightToViewBounds(mbr, mbr.middle())
+ val zoom = mapControl.zoomLimitMax.coerceAtLeast(
+ mapControl.findHeightToViewBounds(mbr, mbr.middle()))
mapControl.setPositionGeo(mbr.middle(), zoom)
}
}
@@ -301,17 +315,19 @@ class MapFragment : GlobeMapFragment() {
))
}
- fun focusOn(latitude: Double, longitude: Double, zoom: Double = 0.00009, animated: Boolean = true) {
+ fun focusOn(latitude: Double, longitude: Double, height: Double = 0.00009, animated: Boolean = true) {
val lat = latitude * Math.PI / 180
val lon = longitude * Math.PI / 180
+ // Ensure height is equal or higher than bottom limit
+ val z = mapControl.zoomLimitMin.coerceAtLeast(height)
if (animated) {
- mapControl.animatePositionGeo(lon, lat, zoom, 0.2)
+ mapControl.animatePositionGeo(lon, lat, z, 0.2)
} else {
- mapControl.setPositionGeo(lon, lat, zoom)
+ mapControl.setPositionGeo(lon, lat, z)
}
}
- private fun makeTileInfo(url: String, tileInfo: TileInfoNew): TileInfoNew? {
+ private fun tileInfoSetCacheDir(url: String, tileInfo: TileInfoNew): TileInfoNew? {
return context?.let {
val cacheDirName = url.toByteArray(Charsets.UTF_8).md5().hex
val cacheDirMap = File(it.cacheDir, cacheDirName)
@@ -323,11 +339,25 @@ class MapFragment : GlobeMapFragment() {
}
}
+ private fun setZoomLimits(minZoom: Int, maxZoom: Int) {
+ mapControl?.setZoomLimits(
+ mapControl.heightForMapScale(
+ MapCalculus.zoomLevelToScale(maxZoom)
+ ?: MapCalculus.zoomLevelToScale(20)!!
+ ),
+ mapControl.heightForMapScale(
+ MapCalculus.zoomLevelToScale(minZoom)
+ ?: MapCalculus.zoomLevelToScale(1)!!
+ )
+ )
+ }
+
fun updateTileInfo(url: String, tileInfo: TileInfoNew) {
context?.let {
- this.tileInfo = makeTileInfo(url, tileInfo)
+ this.tileInfo = tileInfoSetCacheDir(url, tileInfo)
this.tileInfo?.let {
loader?.changeTileInfo(it)
+ setZoomLimits(tileInfo.minZoom, tileInfo.maxZoom)
}
}
}