From cbec64bc49161618ba5f95382b8669b9de3d939b Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Thu, 13 Jan 2022 14:33:55 -0600 Subject: Fixes the map layer issue --- .../TrackerMap/android/map/MapFragment.kt | 25 ++++++++++++++-------- .../TrackerMap/android/map/UnitMapFragment.kt | 4 ++-- 2 files changed, 18 insertions(+), 11 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 34ff655..e3f4ead 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 @@ -38,6 +38,8 @@ class MapFragment : GlobeMapFragment() { private val objects = mutableListOf() private val geofenceObjects = mutableListOf() + private var tileInfo: TileInfoNew? = null + override fun chooseDisplayType(): MapDisplayType { return MapDisplayType.Map } @@ -52,23 +54,27 @@ class MapFragment : GlobeMapFragment() { } override fun controlHasStarted() { + Log.d("MapFragment", "controlHasStarted") + val cacheDirName = "stamen_watercolor6" val cacheDir = File(activity!!.cacheDir, cacheDirName) cacheDir.mkdir() - val tileInfo = RemoteTileInfoNew( - getString(R.string.maps_streets_tile_url), - 0, - 21 - ) - tileInfo.cacheDir = cacheDir + if (tileInfo == null) { + tileInfo = RemoteTileInfoNew( + getString(R.string.maps_streets_tile_url), + 0, + 21 + ) + (tileInfo as RemoteTileInfoNew).cacheDir = cacheDir + } val params = SamplingParams() params.coordSystem = SphericalMercatorCoordSystem() params.coverPoles = true params.edgeMatching = true - params.minZoom = tileInfo.minZoom - params.maxZoom = tileInfo.maxZoom + params.minZoom = tileInfo!!.minZoom + params.maxZoom = tileInfo!!.maxZoom params.singleLevel = true params.maxTiles = 25 @@ -310,7 +316,8 @@ class MapFragment : GlobeMapFragment() { } } - fun setTileInfo(tileInfo: TileInfoNew) { + fun updateTileInfo(tileInfo: TileInfoNew) { + this.tileInfo = tileInfo loader?.changeTileInfo(tileInfo) } 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 06e5713..cc9a551 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 @@ -56,7 +56,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment } private fun setupObservers() { - Log.d("MapFragment", "setupObservers()") + Log.d("UnitMapFragment", "setupObservers()") unitsViewModel.units.observe(viewLifecycleOwner) { units -> Log.d("UnitMapFragment", "Available units: $units") @@ -95,7 +95,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment unitsViewModel.mapTileInfo.observe(viewLifecycleOwner) { tileInfo -> Log.d("UnitMapFragment", "Loading layer!") - unitsMapFragment.setTileInfo(tileInfo) + unitsMapFragment.updateTileInfo(tileInfo) } unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> -- cgit v1.2.3