From 972b0cf5ff61fd7eabfb8960fa474cb80dcde80a Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 00:00:20 -0600 Subject: Default map changed to OpenStreetMap.fr (because .org one doesn't work), and now each map URL has its own cache dir --- androidApp/build.gradle.kts | 3 +- .../TrackerMap/android/map/MapFragment.kt | 36 ++++++++++++++-------- .../TrackerMap/android/map/UnitMapFragment.kt | 2 +- .../TrackerMap/android/units/UnitsViewModel.kt | 10 ++++-- androidApp/src/main/res/values/strings.xml | 3 +- 5 files changed, 34 insertions(+), 20 deletions(-) (limited to 'androidApp') diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 07fe740..cd63ac0 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -39,7 +39,7 @@ val googleImplementation by configurations dependencies { implementation(project(":shared")) - implementation("com.google.android.material:material:1.4.0") + implementation("com.google.android.material:material:1.5.0") implementation("androidx.appcompat:appcompat:1.4.0") implementation("androidx.constraintlayout:constraintlayout:2.1.2") implementation("com.squareup.okhttp3:okhttp:4.9.1") @@ -56,6 +56,7 @@ dependencies { implementation("com.github.zerobranch:SwipeLayout:1.3.1") implementation("com.github.addisonElliott:SegmentedButton:3.1.9") implementation("mil.nga.sf:sf-wkt:1.0.1") + implementation("com.soywiz.korlibs.krypto:krypto:2.4.12") implementation(group = "", name = "WhirlyGlobeMaply", ext = "aar") googleImplementation(platform("com.google.firebase:firebase-bom:29.0.3")) 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 60c8a47..e4fb8ea 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 @@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.drawable.toBitmap import com.mousebird.maply.* +import com.soywiz.krypto.md5 import mil.nga.sf.Polygon import mil.nga.sf.util.SFException import mil.nga.sf.wkt.GeometryReader @@ -56,17 +57,10 @@ class MapFragment : GlobeMapFragment() { override fun controlHasStarted() { Log.d("MapFragment", "controlHasStarted") - val cacheDirName = "stamen_watercolor6" - val cacheDir = File(activity!!.cacheDir, cacheDirName) - cacheDir.mkdir() - if (tileInfo == null) { - tileInfo = RemoteTileInfoNew( - getString(R.string.maps_streets_tile_url), - 0, - 21 - ) - (tileInfo as RemoteTileInfoNew).cacheDir = cacheDir + val mapUrl = getString(R.string.maps_streets_tile_url) + val tmpInfo = RemoteTileInfoNew(mapUrl, 0, 21) + tileInfo = makeTileInfo(getString(R.string.maps_streets_tile_url), tmpInfo) } val params = SamplingParams() @@ -318,9 +312,25 @@ class MapFragment : GlobeMapFragment() { } } - fun updateTileInfo(tileInfo: TileInfoNew) { - this.tileInfo = tileInfo - loader?.changeTileInfo(tileInfo) + private fun makeTileInfo(url: String, tileInfo: TileInfoNew): TileInfoNew? { + return context?.let { + val cacheDirName = url.toByteArray(Charsets.UTF_8).md5().hex + val cacheDirMap = File(it.cacheDir, cacheDirName) + cacheDirMap.mkdir() + Log.d("MapFragment", "Cache dir for $url = ${cacheDirMap.absolutePath}") + + (tileInfo as? RemoteTileInfoNew)?.cacheDir = cacheDirMap + tileInfo + } + } + + fun updateTileInfo(url: String, tileInfo: TileInfoNew) { + context?.let { + this.tileInfo = makeTileInfo(url, tileInfo) + this.tileInfo?.let { + loader?.changeTileInfo(it) + } + } } private fun getIcon(markerType: MarkerType): Bitmap { diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt index 09f41a8..c17e6a4 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt @@ -96,7 +96,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment unitsViewModel.mapTileInfo.observe(viewLifecycleOwner) { tileInfo -> Log.d("UnitMapFragment", "Loading layer!") - unitsMapFragment.updateTileInfo(tileInfo) + unitsMapFragment.updateTileInfo(tileInfo.first, tileInfo.second) } unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt index 08d35a2..94e22fa 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt @@ -4,6 +4,10 @@ import android.util.Log import androidx.lifecycle.* import com.mousebird.maply.RemoteTileInfoNew import com.mousebird.maply.TileInfoNew +import com.soywiz.krypto.Hash +import com.soywiz.krypto.Hasher +import com.soywiz.krypto.HasherFactory +import com.soywiz.krypto.md5 import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch @@ -30,14 +34,14 @@ class UnitsViewModel( private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP) private var _units = MutableLiveData>() private var _selectedUnit = MutableLiveData() - private var _mapTileInfo = MutableLiveData() + private var _mapTileInfo = MutableLiveData>() private var _geofences = MutableLiveData>() val searchQuery: LiveData get() = _searchQuery val unitsDisplayMode: LiveData get() = _unitsDisplayMode val units: LiveData> get() = _units val selectedUnit: LiveData get() = _selectedUnit - val mapTileInfo: LiveData get() = _mapTileInfo + val mapTileInfo: LiveData> get() = _mapTileInfo val geofences: LiveData> get() = _geofences init { @@ -88,7 +92,7 @@ class UnitsViewModel( fun setMapLayer(url: String, minZoom: Int = 0, maxZoom: Int = 21) { val tileInfo = RemoteTileInfoNew(url, minZoom, maxZoom) - _mapTileInfo.postValue(tileInfo) + _mapTileInfo.postValue(url to tileInfo) } fun toggleDisplayMode() { diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 20f5b21..025a7b9 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -11,7 +11,7 @@ - https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga + https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png https://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Ga @@ -41,7 +41,6 @@ Streets Satellite - Hybrid Account About -- cgit v1.2.3 From 73a7543dbd286a4ff3b6bd4d3155823491102095 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 00:49:24 -0600 Subject: Added max zoom, min zoom and attribution text on strings.xml and reduced device selection zoom --- .../TrackerMap/android/map/MapFragment.kt | 9 ++++----- .../TrackerMap/android/units/UnitsActivity.kt | 9 +++++---- androidApp/src/main/res/values/strings.xml | 23 ++++++++++++++++------ 3 files changed, 26 insertions(+), 15 deletions(-) (limited to 'androidApp') 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 e4fb8ea..4a63e65 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 @@ -58,9 +58,9 @@ class MapFragment : GlobeMapFragment() { Log.d("MapFragment", "controlHasStarted") if (tileInfo == null) { - val mapUrl = getString(R.string.maps_streets_tile_url) - val tmpInfo = RemoteTileInfoNew(mapUrl, 0, 21) - tileInfo = makeTileInfo(getString(R.string.maps_streets_tile_url), tmpInfo) + 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) } val params = SamplingParams() @@ -87,7 +87,6 @@ class MapFragment : GlobeMapFragment() { screenLoc: Point2d? ) { super.userDidSelect(mapControl, selObjs, loc, screenLoc) - selObjs?.forEach { selectedObject -> if (selectedObject.selObj is ScreenMarker) { val screenMarker = selectedObject.selObj as ScreenMarker @@ -302,7 +301,7 @@ class MapFragment : GlobeMapFragment() { )) } - fun focusOn(latitude: Double, longitude: Double, zoom: Double = 0.0000144, animated: Boolean = true) { + fun focusOn(latitude: Double, longitude: Double, zoom: Double = 0.00009, animated: Boolean = true) { val lat = latitude * Math.PI / 180 val lon = longitude * Math.PI / 180 if (animated) { diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt index bf5f1d8..cbd543a 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt @@ -90,13 +90,14 @@ class UnitsActivity : AppCompatActivity() { val popOver = PopupMenu(this, view) popOver.menuInflater.inflate(R.menu.map_layers, popOver.menu) popOver.setOnMenuItemClickListener { item -> - unitsViewModel.setMapLayer( + val layer = resources.getStringArray( when (item.itemId) { - R.id.layerStreets -> getString(R.string.maps_streets_tile_url) - R.id.layerSatellite -> getString(R.string.maps_satellite_url) - else -> getString(R.string.maps_streets_tile_url) + R.id.layerStreets -> R.array.maps_streets_tile_url + R.id.layerSatellite -> R.array.maps_satellite_tile_url + else -> R.array.maps_streets_tile_url } ) + unitsViewModel.setMapLayer(layer[0], layer[1].toInt(), layer[2].toInt()) true } popOver.show() diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 025a7b9..67f0a26 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -10,12 +10,23 @@ https://www.google.com/maps/place/%1$f,%2$f?z=19 - - https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png - - - https://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Ga - + + + + + + + https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png + 0 + 20 + © OpenStreetMap France | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors + + + https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x} + 0 + 17 + Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community + default Default -- cgit v1.2.3 From 18bc70d4fa7453c1191fc446327d1e24d5defe6d Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 02:31:26 -0600 Subject: Set zoom limits of mapControl by converting zoom levels to Mapnik scale denominators --- .../TrackerMap/android/map/MapFragment.kt | 46 ++++++++++++++++++---- .../mx/trackermap/TrackerMap/utils/MapCalculus.kt | 31 +++++++++++++++ 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt (limited to 'androidApp') 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?, + 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) } } } diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt new file mode 100644 index 0000000..8c58179 --- /dev/null +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt @@ -0,0 +1,31 @@ +package mx.trackermap.TrackerMap.utils + +class MapCalculus { + companion object { + // Source: https://github.com/openstreetmap/mapnik-stylesheets/blob/master/zoom-to-scale.txt + fun zoomLevelToScale(zoom: Int): Double? = + when (zoom) { + 1 -> 279541132.014 + 2 -> 139770566.007 + 3 -> 69885283.0036 + 4 -> 34942641.5018 + 5 -> 17471320.7509 + 6 -> 8735660.37545 + 7 -> 4367830.18772 + 8 -> 2183915.09386 + 9 -> 1091957.54693 + 10 -> 545978.773466 + 11 -> 272989.386733 + 12 -> 136494.693366 + 13 -> 68247.3466832 + 14 -> 34123.6733416 + 15 -> 17061.8366708 + 16 -> 8530.9183354 + 17 -> 4265.4591677 + 18 -> 2132.72958385 + 19 -> 1000.0 // made up + 20 -> 500.0 // made up + else -> null + } + } +} \ No newline at end of file -- cgit v1.2.3 From f8e7e755dc8e557e1e5b9e9be318f8415a2c7f8e Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 02:58:04 -0600 Subject: Moved layer definitions to map_layers.xml and adjusted zoom limits, and adjusted zoomLevelToScale(zoom) --- .../TrackerMap/android/map/MapFragment.kt | 29 ++++++++++++++-------- androidApp/src/main/res/values/map_layers.xml | 23 +++++++++++++++++ androidApp/src/main/res/values/strings.xml | 18 -------------- .../mx/trackermap/TrackerMap/utils/MapCalculus.kt | 5 ++-- 4 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 androidApp/src/main/res/values/map_layers.xml (limited to 'androidApp') 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 9fa37c9..e30885d 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 @@ -315,11 +315,16 @@ class MapFragment : GlobeMapFragment() { )) } - fun focusOn(latitude: Double, longitude: Double, height: Double = 0.00009, animated: Boolean = true) { + fun focusOn( + latitude: Double, + longitude: Double, + height: Double? = 0.00001, + 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) + val z = mapControl.zoomLimitMin.coerceAtLeast(height ?: 0.0) if (animated) { mapControl.animatePositionGeo(lon, lat, z, 0.2) } else { @@ -340,16 +345,18 @@ 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)!! + mapControl?.let { + it.setZoomLimits( + it.heightForMapScale( + MapCalculus.zoomLevelToScale(maxZoom) + ?: MapCalculus.zoomLevelToScale(21)!! + ), + it.heightForMapScale( + MapCalculus.zoomLevelToScale(minZoom) + ?: MapCalculus.zoomLevelToScale(1)!! + ) ) - ) + } } fun updateTileInfo(url: String, tileInfo: TileInfoNew) { diff --git a/androidApp/src/main/res/values/map_layers.xml b/androidApp/src/main/res/values/map_layers.xml new file mode 100644 index 0000000..c0e83a5 --- /dev/null +++ b/androidApp/src/main/res/values/map_layers.xml @@ -0,0 +1,23 @@ + + + + + + + + + + https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png + 0 + 21 + © OpenStreetMap France | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors + + + + https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x} + 0 + 20 + Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community + + + \ No newline at end of file diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 67f0a26..a3d2f28 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -10,24 +10,6 @@ https://www.google.com/maps/place/%1$f,%2$f?z=19 - - - - - - - https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png - 0 - 20 - © OpenStreetMap France | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors - - - https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x} - 0 - 17 - Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community - - default Default diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt index d4c5261..118c117 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt @@ -28,8 +28,9 @@ class MapCalculus { 16 -> 8530.9183354 17 -> 4265.4591677 18 -> 2132.72958385 - 19 -> 1000.0 // made up - 20 -> 500.0 // made up + 19 -> 1066.36479193 + 20 -> 533.182395965 + 21 -> 266.5911979825 else -> null } } -- cgit v1.2.3 From 3f6958e68f6e4dd5d42e1049c05059502d939cf9 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 04:02:30 -0600 Subject: Added attribution and refactored map layers code --- .../TrackerMap/android/map/MapFragment.kt | 23 +++++++++++----------- .../TrackerMap/android/map/UnitMapFragment.kt | 14 ++++++++++--- .../TrackerMap/android/units/UnitsActivity.kt | 11 +++++++---- .../TrackerMap/android/units/UnitsViewModel.kt | 16 +++++---------- .../src/main/res/layout/unit_map_fragment.xml | 23 +++++++++++++++++++++- .../src/main/res/values-es-rMX/map_layers.xml | 5 +++++ androidApp/src/main/res/values-es-rMX/strings.xml | 3 --- androidApp/src/main/res/values/colors.xml | 2 ++ androidApp/src/main/res/values/dimen.xml | 1 + androidApp/src/main/res/values/map_layers.xml | 7 +++++-- androidApp/src/main/res/values/strings.xml | 3 --- .../TrackerMap/client/models/MapLayer.kt | 8 ++++++++ 12 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 androidApp/src/main/res/values-es-rMX/map_layers.xml create mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt (limited to 'androidApp') 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 e30885d..c4e5fc8 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.client.models.MapLayer import mx.trackermap.TrackerMap.utils.MapCalculus import mx.trackermap.TrackerMap.utils.MarkerType @@ -59,7 +60,8 @@ class MapFragment : GlobeMapFragment() { Log.d("MapFragment", "controlHasStarted") if (tileInfo == null) { - val layer = resources.getStringArray(R.array.maps_streets_tile_url) + // Load default map layer + val layer = resources.getStringArray(R.array.maps_streets_tile) val tmpInfo = RemoteTileInfoNew(layer[0], layer[1].toInt(), layer[2].toInt()) tileInfo = tileInfoSetCacheDir(layer[0], tmpInfo) tileInfo?.let { @@ -344,6 +346,15 @@ class MapFragment : GlobeMapFragment() { } } + fun updateTileInfo(layer: MapLayer) { + val tileInfo = RemoteTileInfoNew(layer.url, layer.minZoom, layer.maxZoom) + this.tileInfo = tileInfoSetCacheDir(layer.url, tileInfo) + this.tileInfo?.let { + loader?.changeTileInfo(it) + setZoomLimits(tileInfo.minZoom, tileInfo.maxZoom) + } + } + private fun setZoomLimits(minZoom: Int, maxZoom: Int) { mapControl?.let { it.setZoomLimits( @@ -359,16 +370,6 @@ class MapFragment : GlobeMapFragment() { } } - fun updateTileInfo(url: String, tileInfo: TileInfoNew) { - context?.let { - this.tileInfo = tileInfoSetCacheDir(url, tileInfo) - this.tileInfo?.let { - loader?.changeTileInfo(it) - setZoomLimits(tileInfo.minZoom, tileInfo.maxZoom) - } - } - } - private fun getIcon(markerType: MarkerType): Bitmap { return ResourcesCompat.getDrawable( activity!!.resources, diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt index c17e6a4..66ccc7a 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt @@ -6,6 +6,7 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.text.HtmlCompat import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitMapFragmentBinding @@ -14,6 +15,7 @@ import mx.trackermap.TrackerMap.android.devices.Action import mx.trackermap.TrackerMap.android.devices.UnitRenderData import mx.trackermap.TrackerMap.android.units.UnitFragment import mx.trackermap.TrackerMap.android.units.UnitsViewModel +import mx.trackermap.TrackerMap.client.models.MapLayer import mx.trackermap.TrackerMap.client.models.UnitInformation @DelicateCoroutinesApi @@ -53,6 +55,11 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment private fun initializeMap() { unitsMapFragment = childFragmentManager.findFragmentById(R.id.unitsMap) as MapFragment unitsMapFragment.markerCallback = unitsViewModel::selectUnitWith + + val layer = resources.getStringArray(R.array.maps_streets_tile) + unitsViewModel.setMapLayer(MapLayer( + layer[0], layer[1].toInt(), layer[2].toInt(), layer[3] + )) } private fun setupObservers() { @@ -94,9 +101,10 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment } } - unitsViewModel.mapTileInfo.observe(viewLifecycleOwner) { tileInfo -> + unitsViewModel.mapLayer.observe(viewLifecycleOwner) { layer -> Log.d("UnitMapFragment", "Loading layer!") - unitsMapFragment.updateTileInfo(tileInfo.first, tileInfo.second) + unitsMapFragment.updateTileInfo(layer) + binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0) } unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> @@ -108,7 +116,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment Log.d("UnitMapFragment", "removeObservers()") unitsViewModel.units.removeObservers(viewLifecycleOwner) unitsViewModel.selectedUnit.removeObservers(viewLifecycleOwner) - unitsViewModel.mapTileInfo.removeObservers(viewLifecycleOwner) + unitsViewModel.mapLayer.removeObservers(viewLifecycleOwner) unitsViewModel.geofences.removeObservers(viewLifecycleOwner) } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt index cbd543a..1bbcb80 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt @@ -17,6 +17,7 @@ import mx.trackermap.TrackerMap.android.databinding.UnitsActivityBinding import mx.trackermap.TrackerMap.android.devices.DevicesFragment import mx.trackermap.TrackerMap.android.map.UnitMapFragment import mx.trackermap.TrackerMap.android.session.UserInformationActivity +import mx.trackermap.TrackerMap.client.models.MapLayer import org.koin.androidx.viewmodel.ext.android.viewModel @DelicateCoroutinesApi @@ -92,12 +93,14 @@ class UnitsActivity : AppCompatActivity() { popOver.setOnMenuItemClickListener { item -> val layer = resources.getStringArray( when (item.itemId) { - R.id.layerStreets -> R.array.maps_streets_tile_url - R.id.layerSatellite -> R.array.maps_satellite_tile_url - else -> R.array.maps_streets_tile_url + R.id.layerStreets -> R.array.maps_streets_tile + R.id.layerSatellite -> R.array.maps_satellite_tile + else -> R.array.maps_streets_tile } ) - unitsViewModel.setMapLayer(layer[0], layer[1].toInt(), layer[2].toInt()) + unitsViewModel.setMapLayer(MapLayer( + layer[0], layer[1].toInt(), layer[2].toInt(), layer[3] + )) true } popOver.show() diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt index 94e22fa..d3060f0 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt @@ -2,16 +2,11 @@ package mx.trackermap.TrackerMap.android.units import android.util.Log import androidx.lifecycle.* -import com.mousebird.maply.RemoteTileInfoNew -import com.mousebird.maply.TileInfoNew -import com.soywiz.krypto.Hash -import com.soywiz.krypto.Hasher -import com.soywiz.krypto.HasherFactory -import com.soywiz.krypto.md5 import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.models.Geofence +import mx.trackermap.TrackerMap.client.models.MapLayer import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.controllers.GeofencesController import mx.trackermap.TrackerMap.controllers.UnitsController @@ -34,14 +29,14 @@ class UnitsViewModel( private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP) private var _units = MutableLiveData>() private var _selectedUnit = MutableLiveData() - private var _mapTileInfo = MutableLiveData>() + private var _mapLayer = MutableLiveData() private var _geofences = MutableLiveData>() val searchQuery: LiveData get() = _searchQuery val unitsDisplayMode: LiveData get() = _unitsDisplayMode val units: LiveData> get() = _units val selectedUnit: LiveData get() = _selectedUnit - val mapTileInfo: LiveData> get() = _mapTileInfo + val mapLayer: LiveData get() = _mapLayer val geofences: LiveData> get() = _geofences init { @@ -90,9 +85,8 @@ class UnitsViewModel( _unitsDisplayMode.postValue(displayMode) } - fun setMapLayer(url: String, minZoom: Int = 0, maxZoom: Int = 21) { - val tileInfo = RemoteTileInfoNew(url, minZoom, maxZoom) - _mapTileInfo.postValue(url to tileInfo) + fun setMapLayer(layer: MapLayer) { + _mapLayer.postValue(layer) } fun toggleDisplayMode() { diff --git a/androidApp/src/main/res/layout/unit_map_fragment.xml b/androidApp/src/main/res/layout/unit_map_fragment.xml index 486f1ce..8395013 100644 --- a/androidApp/src/main/res/layout/unit_map_fragment.xml +++ b/androidApp/src/main/res/layout/unit_map_fragment.xml @@ -14,7 +14,8 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" - android:name="mx.trackermap.TrackerMap.android.map.MapFragment"/> + android:name="mx.trackermap.TrackerMap.android.map.MapFragment" + tools:visibility="invisible"/> + + + + + + + \ No newline at end of file diff --git a/androidApp/src/main/res/values-es-rMX/map_layers.xml b/androidApp/src/main/res/values-es-rMX/map_layers.xml new file mode 100644 index 0000000..eff37d9 --- /dev/null +++ b/androidApp/src/main/res/values-es-rMX/map_layers.xml @@ -0,0 +1,5 @@ + + + Calles + Satélite + \ No newline at end of file diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml index 809b64c..5e41768 100644 --- a/androidApp/src/main/res/values-es-rMX/strings.xml +++ b/androidApp/src/main/res/values-es-rMX/strings.xml @@ -19,9 +19,6 @@ Cambiar capa del mapa Ver información de cuenta - Calles - Satélite - Cuenta Acerca de Cerrar sesión diff --git a/androidApp/src/main/res/values/colors.xml b/androidApp/src/main/res/values/colors.xml index bb4ab14..23fe6fb 100644 --- a/androidApp/src/main/res/values/colors.xml +++ b/androidApp/src/main/res/values/colors.xml @@ -12,6 +12,8 @@ #1976D2 #FFFFFF #388E3C + #66000000 + #4DFFFFFF #388E3C #D32F2F diff --git a/androidApp/src/main/res/values/dimen.xml b/androidApp/src/main/res/values/dimen.xml index 271a12b..92d5242 100644 --- a/androidApp/src/main/res/values/dimen.xml +++ b/androidApp/src/main/res/values/dimen.xml @@ -33,6 +33,7 @@ 11sp 4dp 10dp + 11sp 8dp diff --git a/androidApp/src/main/res/values/map_layers.xml b/androidApp/src/main/res/values/map_layers.xml index c0e83a5..bffceb9 100644 --- a/androidApp/src/main/res/values/map_layers.xml +++ b/androidApp/src/main/res/values/map_layers.xml @@ -1,19 +1,22 @@ + Streets + Satellite + - + https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png 0 21 © OpenStreetMap France | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors - + https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x} 0 20 diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index a3d2f28..11c914f 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -32,9 +32,6 @@ Switch map layer View account info - Streets - Satellite - Account About Logout diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt new file mode 100644 index 0000000..64381d9 --- /dev/null +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt @@ -0,0 +1,8 @@ +package mx.trackermap.TrackerMap.client.models + +data class MapLayer( + val url: String, + val minZoom: Int, + val maxZoom: Int, + val attribution: String +) \ No newline at end of file -- cgit v1.2.3 From a2ba612c515a53cb6e7f283858a518d60188651b Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 04:14:04 -0600 Subject: Removed problematic layer pre-initialization --- .../main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt | 2 +- .../java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'androidApp') 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 c4e5fc8..a8478fd 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 @@ -346,7 +346,7 @@ class MapFragment : GlobeMapFragment() { } } - fun updateTileInfo(layer: MapLayer) { + fun updateTile(layer: MapLayer) { val tileInfo = RemoteTileInfoNew(layer.url, layer.minZoom, layer.maxZoom) this.tileInfo = tileInfoSetCacheDir(layer.url, tileInfo) this.tileInfo?.let { diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt index 66ccc7a..6f6596f 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt @@ -15,7 +15,6 @@ import mx.trackermap.TrackerMap.android.devices.Action import mx.trackermap.TrackerMap.android.devices.UnitRenderData import mx.trackermap.TrackerMap.android.units.UnitFragment import mx.trackermap.TrackerMap.android.units.UnitsViewModel -import mx.trackermap.TrackerMap.client.models.MapLayer import mx.trackermap.TrackerMap.client.models.UnitInformation @DelicateCoroutinesApi @@ -57,9 +56,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment unitsMapFragment.markerCallback = unitsViewModel::selectUnitWith val layer = resources.getStringArray(R.array.maps_streets_tile) - unitsViewModel.setMapLayer(MapLayer( - layer[0], layer[1].toInt(), layer[2].toInt(), layer[3] - )) + binding.attributionText.text = HtmlCompat.fromHtml(layer[3], 0) } private fun setupObservers() { @@ -103,7 +100,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment unitsViewModel.mapLayer.observe(viewLifecycleOwner) { layer -> Log.d("UnitMapFragment", "Loading layer!") - unitsMapFragment.updateTileInfo(layer) + unitsMapFragment.updateTile(layer) binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0) } -- cgit v1.2.3