aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-16 23:34:36 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-16 23:34:36 -0600
commitbce64ef4f702c351d349881704d92f724e90239f (patch)
tree20bdd817ecaea24194f81cc7bf40931e2b21855f /androidApp
parent0e2bce2fda9711aaeaa536d254911b7651cbea6a (diff)
downloadetbsa-trackermap-mobile-bce64ef4f702c351d349881704d92f724e90239f.tar.gz
etbsa-trackermap-mobile-bce64ef4f702c351d349881704d92f724e90239f.tar.bz2
etbsa-trackermap-mobile-bce64ef4f702c351d349881704d92f724e90239f.zip
Fixed initial zoom issue and refactored layers into MapLayer in shared module
Diffstat (limited to 'androidApp')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt24
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt12
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt16
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt8
-rw-r--r--androidApp/src/main/res/values/map_layers.xml21
5 files changed, 30 insertions, 51 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 6a80f95..06d3d97 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
@@ -61,12 +61,12 @@ class MapFragment : GlobeMapFragment() {
Log.d("MapFragment", "controlHasStarted")
if (tileInfo == null) {
+ val layer = MapLayer.defaultLayer
// 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)
+ val info = RemoteTileInfoNew(layer.url, layer.minZoom, layer.maxZoom)
+ tileInfo = tileInfoSetCacheDir(layer.url, info)
tileInfo?.let {
- setZoomLimits(layer[1].toInt(), layer[2].toInt())
+ setZoomLimits(layer.minZoom, layer.maxZoom)
}
}
@@ -84,7 +84,7 @@ class MapFragment : GlobeMapFragment() {
val latitude = 23.191 * Math.PI / 180
val longitude = -100.36 * Math.PI / 180
- mapControl.setPositionGeo(latitude, longitude, 0.4)
+ mapControl.setPositionGeo(longitude, latitude, 0.4)
}
override fun mapDidStopMoving(
@@ -352,13 +352,15 @@ class MapFragment : GlobeMapFragment() {
}
}
- fun updateTile(layer: MapLayer) {
+ fun updateLayer(layer: MapLayer.Type) {
mapControl?.addPostSurfaceRunnable {
- 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)
+ 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)
+ }
}
}
}
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 e96945e..cb5edc3 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,6 +15,7 @@ import mx.trackermap.TrackerMap.android.shared.MarkerTransformations
import mx.trackermap.TrackerMap.android.shared.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
@@ -55,8 +56,8 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment
unitsMapFragment = childFragmentManager.findFragmentById(R.id.unitsMap) as MapFragment
unitsMapFragment.markerCallback = unitsViewModel::selectUnitWith
- val layer = resources.getStringArray(R.array.maps_streets_tile)
- binding.attributionText.text = HtmlCompat.fromHtml(layer[3], 0)
+ val layer = MapLayer.defaultLayer
+ binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0)
}
private fun setupObservers() {
@@ -98,13 +99,14 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment
}
}
- unitsViewModel.mapLayer.observe(viewLifecycleOwner) { layer ->
+ unitsViewModel.mapLayerType.observe(viewLifecycleOwner) { type ->
Log.d("UnitMapFragment", "Loading layer!")
- unitsMapFragment.updateTile(layer)
+ unitsMapFragment.updateLayer(type)
val selectedUnit = unitsViewModel.selectedUnit.value
selectedUnit?.let {
unitsMapFragment.focusOn(it.position!!.latitude!!, it.position!!.longitude!!)
}
+ val layer = MapLayer.layers[type]!!
binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0)
}
@@ -117,7 +119,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment
Log.d("UnitMapFragment", "removeObservers()")
unitsViewModel.units.removeObservers(viewLifecycleOwner)
unitsViewModel.selectedUnit.removeObservers(viewLifecycleOwner)
- unitsViewModel.mapLayer.removeObservers(viewLifecycleOwner)
+ unitsViewModel.mapLayerType.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 1bbcb80..25169fe 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
@@ -91,16 +91,12 @@ class UnitsActivity : AppCompatActivity() {
val popOver = PopupMenu(this, view)
popOver.menuInflater.inflate(R.menu.map_layers, popOver.menu)
popOver.setOnMenuItemClickListener { item ->
- val layer = resources.getStringArray(
- when (item.itemId) {
- R.id.layerStreets -> R.array.maps_streets_tile
- R.id.layerSatellite -> R.array.maps_satellite_tile
- else -> R.array.maps_streets_tile
- }
- )
- unitsViewModel.setMapLayer(MapLayer(
- layer[0], layer[1].toInt(), layer[2].toInt(), layer[3]
- ))
+ val layer = when (item.itemId) {
+ R.id.layerStreets -> MapLayer.Type.STREETS
+ R.id.layerSatellite -> MapLayer.Type.SATELLITE
+ else -> MapLayer.Type.STREETS
+ }
+ unitsViewModel.setMapLayerType(layer)
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 d3060f0..2d2994b 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
@@ -29,14 +29,14 @@ class UnitsViewModel(
private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP)
private var _units = MutableLiveData<List<UnitInformation>>()
private var _selectedUnit = MutableLiveData<UnitInformation?>()
- private var _mapLayer = MutableLiveData<MapLayer>()
+ private var _mapLayerType = MutableLiveData<MapLayer.Type>()
private var _geofences = MutableLiveData<Map<Int, Geofence>>()
val searchQuery: LiveData<String> get() = _searchQuery
val unitsDisplayMode: LiveData<UnitsDisplayMode> get() = _unitsDisplayMode
val units: LiveData<List<UnitInformation>> get() = _units
val selectedUnit: LiveData<UnitInformation?> get() = _selectedUnit
- val mapLayer: LiveData<MapLayer> get() = _mapLayer
+ val mapLayerType: LiveData<MapLayer.Type> get() = _mapLayerType
val geofences: LiveData<Map<Int, Geofence>> get() = _geofences
init {
@@ -85,8 +85,8 @@ class UnitsViewModel(
_unitsDisplayMode.postValue(displayMode)
}
- fun setMapLayer(layer: MapLayer) {
- _mapLayer.postValue(layer)
+ fun setMapLayerType(layer: MapLayer.Type) {
+ _mapLayerType.postValue(layer)
}
fun toggleDisplayMode() {
diff --git a/androidApp/src/main/res/values/map_layers.xml b/androidApp/src/main/res/values/map_layers.xml
index bffceb9..034f3e5 100644
--- a/androidApp/src/main/res/values/map_layers.xml
+++ b/androidApp/src/main/res/values/map_layers.xml
@@ -2,25 +2,4 @@
<resources>
<string name="layer_streets">Streets</string>
<string name="layer_satellite">Satellite</string>
-
- <!-- Tile URLs -->
- <!-- [0] = tile server URL -->
- <!-- [1] = min zoom -->
- <!-- [2] = max zoom -->
- <!-- [3] = attribution text -->
-
- <string-array name="maps_streets_tile" translatable="false">
- <item>https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png</item>
- <item>0</item>
- <item>21</item>
- <item>&#169; OpenStreetMap France | &#169; &lt;a href="https://www.openstreetmap.org/copyright"&gt;OpenStreetMap&lt;/a&gt; contributors</item>
- </string-array>
-
- <string-array name="maps_satellite_tile" translatable="false">
- <item>https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}</item>
- <item>0</item>
- <item>20</item>
- <item>Tiles &#169; Esri &#8212; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community</item>
- </string-array>
-
</resources> \ No newline at end of file