aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt51
1 files changed, 32 insertions, 19 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 1ba8fd6..5304f8e 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
@@ -27,7 +27,7 @@ import mx.trackermap.TrackerMap.utils.MarkerType
typealias SetupCallback = () -> Unit
typealias MarkerCallback = (Int?) -> Unit
-class MapFragment : GlobeMapFragment() {
+open class MapFragment : GlobeMapFragment() {
private var loader: QuadImageLoader? = null
@@ -98,6 +98,11 @@ class MapFragment : GlobeMapFragment() {
mapControl.setPositionGeo(longitude, latitude, 0.4)
}
+ override fun onStop() {
+ super.onStop()
+ hasStarted = false
+ }
+
override fun mapDidStopMoving(
mapControl: MapController?,
corners: Array<out Point3d>?,
@@ -341,19 +346,29 @@ class MapFragment : GlobeMapFragment() {
height: Double = 0.00001,
animated: Boolean = true
) {
- mapControl?.addPostSurfaceRunnable {
- val lat = latitude * Math.PI / 180
- val lon = longitude * Math.PI / 180
- // Ensure height is equal or higher than bottom limit
- val z = height.coerceAtLeast(mapControl.zoomLimitMin)
- if (animated) {
- mapControl.animatePositionGeo(lon, lat, z, 0.2)
- } else {
- mapControl.setPositionGeo(lon, lat, z)
- }
+ val lat = latitude * Math.PI / 180
+ val lon = longitude * Math.PI / 180
+ // Ensure height is equal or higher than bottom limit
+ val z = height.coerceAtLeast(mapControl.zoomLimitMin)
+ if (animated) {
+ mapControl.animatePositionGeo(lon, lat, z, 0.2)
+ } else {
+ mapControl.setPositionGeo(lon, lat, z)
}
}
+ fun zoomIn() {
+ val pos = mapControl.positionGeo.toPoint2d().toDegrees()
+ val zoom = mapControl.currentMapScale() / 2
+ focusOn(pos.y, pos.x, mapControl.heightForMapScale(zoom))
+ }
+
+ fun zoomOut() {
+ val pos = mapControl.positionGeo.toPoint2d().toDegrees()
+ val zoom = mapControl.currentMapScale() * 2
+ focusOn(pos.y, pos.x, mapControl.heightForMapScale(zoom))
+ }
+
private fun tileInfoSetCacheDir(url: String, tileInfo: TileInfoNew): TileInfoNew? {
return context?.let {
val cacheDirName = url.toByteArray(Charsets.UTF_8).md5().hex
@@ -366,14 +381,12 @@ class MapFragment : GlobeMapFragment() {
}
fun updateLayer(layer: MapLayer.Type) {
- mapControl?.addPostSurfaceRunnable {
- MapLayer.layers[layer]?.let {
- val tileInfo = RemoteTileInfoNew(it.url, it.minZoom, it.maxZoom)
- this.tileInfo = tileInfoSetCacheDir(it.url, tileInfo)
- this.tileInfo?.let { t ->
- loader?.changeTileInfo(t)
- setZoomLimits(tileInfo.minZoom, tileInfo.maxZoom)
- }
+ MapLayer.layers[layer]?.let {
+ val tileInfo = RemoteTileInfoNew(it.url, it.minZoom, it.maxZoom)
+ this.tileInfo = tileInfoSetCacheDir(it.url, tileInfo)
+ this.tileInfo?.let { t ->
+ loader?.changeTileInfo(t)
+ setZoomLimits(tileInfo.minZoom, tileInfo.maxZoom)
}
}
}