meshtastic#413 Add Satellite Map Layers

This commit is contained in:
wkawecki
2022-04-22 12:28:04 +02:00
parent ba0c48b762
commit 8b5b33bcd5
7 changed files with 82 additions and 6 deletions

View File

@@ -1081,6 +1081,10 @@ class MainActivity : BaseActivity(), Logging,
chooseLangDialog()
return true
}
R.id.preferences_map_style -> {
chooseMapStyle()
return true
}
else -> super.onOptionsItemSelected(item)
}
}
@@ -1185,9 +1189,31 @@ class MainActivity : BaseActivity(), Logging,
debug("Lang from prefs: $lang")
builder.setSingleChoiceItems(languageLabels, languageValues.indexOf(lang)) { dialog, which ->
var lang = languageValues[which];
debug("Set lang pref to $lang")
editor.putString("lang", lang)
val selectedLang = languageValues[which]
debug("Set lang pref to $selectedLang")
editor.putString("lang", selectedLang)
editor.apply()
dialog.dismiss()
}
val dialog = builder.create()
dialog.show()
}
private fun chooseMapStyle() {
/// Prepare dialog and its items
val builder = MaterialAlertDialogBuilder(this)
builder.setTitle(getString(R.string.preferences_map_style))
val mapStyles by lazy { resources.getStringArray(R.array.map_styles) }
/// Load preferences and its value
val prefs = UIViewModel.getPreferences(this)
val editor: SharedPreferences.Editor = prefs.edit()
val mapStyleId = prefs.getInt("map_style_id", 1)
debug("mapStyleId from prefs: $mapStyleId")
builder.setSingleChoiceItems(mapStyles, mapStyleId) { dialog, which ->
debug("Set mapStyleId pref to $which")
editor.putInt("map_style_id", which)
editor.apply()
dialog.dismiss()
}

View File

@@ -1,6 +1,8 @@
package com.geeksville.mesh.ui
import android.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
@@ -275,7 +277,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
R.drawable.ic_twotone_person_pin_24
)!!.toBitmap()
map.loadStyleUri(Style.OUTDOORS) {
map.loadStyleUri(loadMapStyleFromPref()) {
if (it.isStyleLoaded) {
it.addSource(nodePositions)
it.addImage(markerImageId, markerIcon)
@@ -654,6 +656,25 @@ class MapFragment : ScreenFragment("Map"), Logging {
}
}
}
private fun loadMapStyleFromPref():String {
val prefs = context?.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
val mapStyleId = prefs?.getInt("map_style_id", 1)
debug("mapStyleId from prefs: $mapStyleId")
val mapStyle = when (mapStyleId) {
0 -> Style.MAPBOX_STREETS
1 -> Style.OUTDOORS
2 -> Style.LIGHT
3 -> Style.DARK
4 -> Style.SATELLITE
5 -> Style.SATELLITE_STREETS
6 -> Style.TRAFFIC_DAY
7 -> Style.TRAFFIC_NIGHT
else -> Style.OUTDOORS
}
return mapStyle
}
}