fixed map being null on switch

pull/470/head
PWRxPSYCHO 2022-08-24 23:15:48 -04:00
rodzic 3e81abb638
commit 19a847604e
1 zmienionych plików z 20 dodań i 9 usunięć

Wyświetl plik

@ -53,9 +53,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
binding = MapViewBinding.inflate(inflater, container, false) binding = MapViewBinding.inflate(inflater)
map = binding.map
map.tag = mapTag
return binding.root return binding.root
} }
@ -63,7 +61,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
super.onViewCreated(viewIn, savedInstanceState) super.onViewCreated(viewIn, savedInstanceState)
Configuration.getInstance().userAgentValue = Configuration.getInstance().userAgentValue =
BuildConfig.APPLICATION_ID // Required to get online tiles BuildConfig.APPLICATION_ID // Required to get online tiles
map = viewIn.findViewById(R.id.map)
mPrefs = context!!.getSharedPreferences(prefsName, Context.MODE_PRIVATE) mPrefs = context!!.getSharedPreferences(prefsName, Context.MODE_PRIVATE)
addCopyright() // Copyright is required for certain map sources addCopyright() // Copyright is required for certain map sources
@ -132,7 +130,6 @@ class MapFragment : ScreenFragment("Map"), Logging {
requireActivity(), requireActivity(),
R.drawable.ic_twotone_person_pin_24 R.drawable.ic_twotone_person_pin_24
) )
map.overlays.add(marker) map.overlays.add(marker)
} }
f f
@ -152,6 +149,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
private fun setupMapProperties() { private fun setupMapProperties() {
if (this::map.isInitialized) { if (this::map.isInitialized) {
map.setDestroyMode(false)
map.isTilesScaledToDpi = map.isTilesScaledToDpi =
true // scales the map tiles to the display density of the screen true // scales the map tiles to the display density of the screen
map.minZoomLevel = map.minZoomLevel =
@ -202,10 +200,9 @@ class MapFragment : ScreenFragment("Map"), Logging {
2 -> TileSourceFactory.USGS_SAT 2 -> TileSourceFactory.USGS_SAT
3 -> TileSourceFactory.OpenTopo 3 -> TileSourceFactory.OpenTopo
4 -> TileSourceFactory.ROADS_OVERLAY_NL 4 -> TileSourceFactory.ROADS_OVERLAY_NL
5 -> TileSourceFactory.CLOUDMADESMALLTILES
6 -> TileSourceFactory.ChartbundleENRH 6 -> TileSourceFactory.ChartbundleENRH
7 -> TileSourceFactory.ChartbundleWAC 7 -> TileSourceFactory.ChartbundleWAC
else -> TileSourceFactory.CLOUDMADESMALLTILES else -> TileSourceFactory.OpenTopo
} }
return mapSource return mapSource
} }
@ -227,11 +224,25 @@ class MapFragment : ScreenFragment("Map"), Logging {
TileSourceFactory.DEFAULT_TILE_SOURCE.name() TileSourceFactory.DEFAULT_TILE_SOURCE.name()
) )
try { try {
val tileSource = TileSourceFactory.getTileSource(tileSourceName) map.setTileSource(matchOnlineTileSourceBase(tileSourceName!!))
map.setTileSource(tileSource)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE) map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE)
} }
map.onResume()
}
private fun matchOnlineTileSourceBase(name: String): OnlineTileSourceBase {
val tileSourceBase = when (name) {
TileSourceFactory.MAPNIK.name() -> TileSourceFactory.MAPNIK
TileSourceFactory.USGS_TOPO.name() -> TileSourceFactory.USGS_TOPO
TileSourceFactory.USGS_SAT.name() -> TileSourceFactory.USGS_SAT
TileSourceFactory.ROADS_OVERLAY_NL.name() -> TileSourceFactory.ROADS_OVERLAY_NL
TileSourceFactory.ChartbundleENRH.name() -> TileSourceFactory.ChartbundleENRH
TileSourceFactory.ChartbundleWAC.name() -> TileSourceFactory.ChartbundleWAC
else -> TileSourceFactory.DEFAULT_TILE_SOURCE
}
return tileSourceBase
} }
override fun onDestroy() { override fun onDestroy() {