aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt42
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt18
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt32
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt8
-rw-r--r--androidApp/src/main/res/layout/unit_map_fragment.xml2
-rw-r--r--androidApp/src/main/res/layout/units_activity.xml4
-rw-r--r--androidApp/src/main/res/values/map_layers.xml33
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt26
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt2
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt2
10 files changed, 92 insertions, 77 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..17fc9d4 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
@@ -1,6 +1,7 @@
package mx.trackermap.TrackerMap.android.map
import android.graphics.Bitmap
+import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.util.Log
@@ -48,6 +49,11 @@ class MapFragment : GlobeMapFragment() {
return MapDisplayType.Map
}
+ override fun preControlCreated() {
+ super.preControlCreated()
+ mapSettings.clearColor = Color.WHITE
+ }
+
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -61,12 +67,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 +90,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(
@@ -237,9 +243,11 @@ class MapFragment : GlobeMapFragment() {
mbr.expandByFraction(0.1)
mapControl?.addPostSurfaceRunnable {
- val zoom = mapControl.findHeightToViewBounds(mbr, mbr.middle())
- .coerceAtLeast(mapControl.zoomLimitMin)
- mapControl.setPositionGeo(mbr.middle(), zoom)
+ mapControl?.let {
+ val zoom = it.findHeightToViewBounds(mbr, mbr.middle())
+ .coerceAtLeast(mapControl.zoomLimitMin)
+ it.setPositionGeo(mbr.middle(), zoom)
+ }
}
}
}
@@ -328,10 +336,7 @@ class MapFragment : GlobeMapFragment() {
val lat = latitude * Math.PI / 180
val lon = longitude * Math.PI / 180
// Ensure height is equal or higher than bottom limit
- Log.d("MapFragment", "Target: %7.7f".format(height))
- Log.d("MapFragment", "Min: %7.7f".format(mapControl.zoomLimitMin))
val z = height.coerceAtLeast(mapControl.zoomLimitMin)
- Log.d("MapFragment", "Final: %7.7f".format(z))
if (animated) {
mapControl.animatePositionGeo(lon, lat, z, 0.2)
} else {
@@ -346,19 +351,20 @@ class MapFragment : GlobeMapFragment() {
val cacheDirMap = File(it.cacheDir, cacheDirName)
cacheDirMap.mkdir()
Log.d("MapFragment", "Cache dir for $url = ${cacheDirMap.absolutePath}")
-
(tileInfo as? RemoteTileInfoNew)?.cacheDir = cacheDirMap
tileInfo
}
}
- 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 90ee36a..0658f56 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() {
@@ -67,8 +68,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment
unitsMapFragment.display(
units.mapNotNull(MarkerTransformations::unitToMarker).toTypedArray(),
- isReport = false,
- center = unitsViewModel.selectedUnit.value == null
+ isReport = false
)
}
@@ -98,9 +98,13 @@ 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)
+ unitsViewModel.selectedUnit.value?.let {
+ unitsMapFragment.focusOn(it.position!!.latitude!!, it.position!!.longitude!!)
+ }
+ val layer = MapLayer.layers[type]!!
binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0)
}
@@ -113,7 +117,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 f2ff30e..e9b9010 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
@@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.TooltipCompat
import androidx.core.widget.doAfterTextChanged
+import androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_FADE
import androidx.fragment.app.commit
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.R
@@ -79,7 +80,9 @@ class UnitsActivity : AppCompatActivity() {
}
binding.searchInput.doAfterTextChanged {
Log.d("UnitsActivity", "Search changed to ${it.toString()}")
- binding.searchInput
+ if (unitsViewModel.unitsDisplayMode.value == UnitsViewModel.UnitsDisplayMode.MAP) {
+ unitsViewModel.setDisplayMode(UnitsViewModel.UnitsDisplayMode.LIST)
+ }
unitsViewModel.search(it.toString())
}
binding.searchInputLayout.setEndIconOnClickListener {
@@ -91,17 +94,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.layerGmaps -> R.array.maps_gmaps_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()
@@ -155,6 +153,7 @@ class UnitsActivity : AppCompatActivity() {
}
supportFragmentManager.commit {
replace(R.id.displayContainer, newFragment)
+ setTransition(TRANSIT_FRAGMENT_FADE)
}
}
unitsViewModel.selectedUnit.observe(this) {
@@ -164,5 +163,14 @@ class UnitsActivity : AppCompatActivity() {
private fun removeObservers() {
unitsViewModel.unitsDisplayMode.removeObservers(this)
+ unitsViewModel.selectedUnit.removeObservers(this)
+ }
+
+ override fun onBackPressed() {
+ if (unitsViewModel.unitsDisplayMode.value == UnitsViewModel.UnitsDisplayMode.LIST) {
+ unitsViewModel.setDisplayMode(UnitsViewModel.UnitsDisplayMode.MAP)
+ } else {
+ super.onBackPressed()
+ }
}
} \ No newline at end of file
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/layout/unit_map_fragment.xml b/androidApp/src/main/res/layout/unit_map_fragment.xml
index e2bee95..a86a7e9 100644
--- a/androidApp/src/main/res/layout/unit_map_fragment.xml
+++ b/androidApp/src/main/res/layout/unit_map_fragment.xml
@@ -15,7 +15,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:name="mx.trackermap.TrackerMap.android.map.MapFragment"
- tools:visibility="invisible"/>
+ tools:visibility="visible"/>
<androidx.cardview.widget.CardView
android:id="@+id/mapUnitCard"
diff --git a/androidApp/src/main/res/layout/units_activity.xml b/androidApp/src/main/res/layout/units_activity.xml
index a468151..5abb95b 100644
--- a/androidApp/src/main/res/layout/units_activity.xml
+++ b/androidApp/src/main/res/layout/units_activity.xml
@@ -7,14 +7,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <FrameLayout
+ <androidx.fragment.app.FragmentContainerView
android:id="@+id/displayContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/displayModeToggle"
diff --git a/androidApp/src/main/res/values/map_layers.xml b/androidApp/src/main/res/values/map_layers.xml
index 59c6af5..034f3e5 100644
--- a/androidApp/src/main/res/values/map_layers.xml
+++ b/androidApp/src/main/res/values/map_layers.xml
@@ -1,34 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="layer_streets">OpenStreetMap</string>
- <string name="layer_gmaps">Google Streets</string>
- <string name="layer_satellite">Google 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_gmaps_tile" translatable="false">
- <item>https://mt0.google.com/vt/lyrs=m&amp;hl=en&amp;x={x}&amp;y={y}&amp;z={z}&amp;s=Ga</item>
- <item>0</item>
- <item>21</item>
- <item>&#169; Google</item>
- </string-array>
-
- <string-array name="maps_satellite_tile" translatable="false">
- <item>https://mt0.google.com/vt/lyrs=y&amp;hl=en&amp;x={x}&amp;y={y}&amp;z={z}&amp;s=Ga</item>
- <item>0</item>
- <item>21</item>
- <item>&#169; Google</item>
- </string-array>
-
+ <string name="layer_streets">Streets</string>
+ <string name="layer_satellite">Satellite</string>
</resources> \ No newline at end of file
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
index 64381d9..ff0489e 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/MapLayer.kt
@@ -5,4 +5,28 @@ data class MapLayer(
val minZoom: Int,
val maxZoom: Int,
val attribution: String
-) \ No newline at end of file
+) {
+ enum class Type {
+ STREETS,
+ SATELLITE
+ }
+
+ companion object {
+ val layers = mapOf(
+ Type.STREETS to MapLayer(
+ url = "https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png",
+ minZoom = 1,
+ maxZoom = 23,
+ attribution = "&#169; OpenStreetMap France | &#169; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"
+ ),
+ Type.SATELLITE to MapLayer(
+ url = "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
+ minZoom = 1,
+ maxZoom = 20,
+ attribution = "Tiles &#169; Esri &#8212; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community"
+ )
+ )
+
+ val defaultLayer = layers[Type.STREETS]!!
+ }
+} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
index 237f1a3..2ce4dc6 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
@@ -95,7 +95,7 @@ class SessionController(
if (tokens == "null" || !tokens.contains(token)) {
if (tokens == "null") {
attributes["notificationTokens"] = JsonPrimitive(token)
- } else if (tokens.contains(token)) {
+ } else if (!tokens.contains(token)) {
attributes["notificationTokens"] = JsonPrimitive("$tokens,$token")
}
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 b1a6444..d4d69fa 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt
@@ -32,6 +32,8 @@ class MapCalculus {
20 -> 533.182395965
21 -> 266.5911979825
22 -> 133.29559899125
+ 23 -> 66.647799495625
+ 24 -> 33.3238997478125
else -> null
}
}