Skip to content

Commit

Permalink
Add Stadia Maps as a map source
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjore committed Jan 16, 2025
1 parent ea82789 commit d65a7c7
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 34 deletions.
4 changes: 3 additions & 1 deletion Fragments/Fragment_preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public class Fragment_Preferences : PreferenceFragmentCompat, ISharedPreferences

public static List<MapSource> MapSources = [
new MapSource("OpenStreetMap", @"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", ""),
new MapSource("Mapbox", @"https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/tiles/{z}/{x}/{y}?access_token=", "MapBoxToken"),
new MapSource("Mapbox", @"https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/tiles/{z}/{x}/{y}?access_token=", "MapboxToken"),
new MapSource("Thunderforest", @"https://tile.thunderforest.com/outdoors/{z}/{x}/{y}.png?apikey=", "ThunderforestToken"),
new MapSource("Stadia Maps", @"https://tiles.stadiamaps.com/tiles/outdoors/{z}/{x}/{y}.png?api_key=" , "StadiaToken"),
new MapSource("Custom", "CustomServerURL", "CustomToken"),
];

Expand All @@ -99,6 +100,7 @@ public override void OnCreatePreferences(Bundle? savedInstanceState, string? roo
CreateArrayList((ListPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.OSM_BulkDownload_Source)), true);

//Set Summary to "Not Set" or "Hidden" for sensitive fields
SetSummary((EditTextPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.StadiaToken)));
SetSummary((EditTextPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.MapboxToken)));
SetSummary((EditTextPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.ThunderforestToken)));
SetSummary((EditTextPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.CustomServerURL)));
Expand Down
3 changes: 2 additions & 1 deletion Fragments/Fragment_restore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ private static bool RestorePreferences(string RestoreFolder)
Preferences.Set("OSM_Browse_Source", prefSettings.OSM_Browse_Source);
Preferences.Set("CustomServerURL ", prefSettings.CustomServerURL);
Preferences.Set("CustomToken", prefSettings.CustomToken);
Preferences.Set("StadiaToken", prefSettings.StadiaToken);
Preferences.Set("MapboxToken", prefSettings.MapboxToken);
Preferences.Set("ThunderforestToken", prefSettings.ThunderforestToken);
Preferences.Set("ThunderforestToken", prefSettings.ThunderforestToken);

Preferences.Set("mapScale", prefSettings.mapScale);
Preferences.Set("mapUTMZone", prefSettings.mapUTMZone);
Expand Down
69 changes: 56 additions & 13 deletions MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ protected override async void OnCreate(Bundle? savedInstanceState)
//Preferences.Set("freq_s_OffRoute", Fragment_Preferences.freq_OffRoute_s.ToString());
//Preferences.Set("KeepNBackups", Fragment_Preferences.KeepNBackups.ToString());

#if DEBUG
if (string.IsNullOrEmpty(Resources?.GetString(Resource.String.Sentry_APIKey)))
{
Serilog.Log.Fatal("Sentry DSN entry is missing and in debug mode");
}
#endif

//Logging
string _Path = System.IO.Path.Combine(Fragment_Preferences.rootPath, Fragment_Preferences.logFile);
Expand Down Expand Up @@ -248,22 +254,42 @@ public override bool OnCreateOptionsMenu(IMenu? menu)
public override bool OnOptionsItemSelected(IMenuItem item)
{
int id = item.ItemId;
if (id == Resource.Id.action_settings)
if (id == Resource.Id.AddCurrentLocationAsPOI)
{
Log.Information($"Change to Settings");

SupportFragmentManager.BeginTransaction()
.SetReorderingAllowed(true)
.Replace(Resource.Id.fragment_container, new Fragment_Preferences(), Fragment_Preferences.Fragment_Settings)
.AddToBackStack(Fragment_Preferences.Fragment_Settings)
.Commit();
SupportFragmentManager.ExecutePendingTransactions();

return true;
var CurrentLocation = LocationForegroundService.GetLocation();
if (CurrentLocation != null)
{
GPXDataPOI p = new()
{
Name = "Manual Entry",
Description = "",
Symbol = null,
Lat = (decimal)CurrentLocation.Latitude,
Lon = (decimal)CurrentLocation.Longitude,
};

var r = POIDatabase.SavePOI(p);
DisplayMapItems.AddPOIToMap();
}
}
else if (id == Resource.Id.action_clearmap)
if (id == Resource.Id.SaveGPSasPOI)
{
return Utils.Misc.ClearTrackRoutesFromMap();
/*
if (CurrentLocation != null)
{
GPXDataPOI p = new()
{
Name = "Manual Entry",
Description = "",
Symbol = null,
Lat = (decimal)CurrentLocation.Latitude,
Lon = (decimal)CurrentLocation.Longitude,
};
var r = POIDatabase.SavePOI(p);
DisplayMapItems.AddPOIToMap();
}
*/
}
else if (id == Resource.Id.AddRogainingPOI)
{
Expand All @@ -286,7 +312,24 @@ public override bool OnOptionsItemSelected(IMenuItem item)
{
Export.ExportPOI("Rogaining");
}
else if (id == Resource.Id.action_clearmap)
{
return Utils.Misc.ClearTrackRoutesFromMap();
}
else if (id == Resource.Id.action_settings)
{
Log.Information($"Change to Settings");

SupportFragmentManager.BeginTransaction()
.SetReorderingAllowed(true)
.Replace(Resource.Id.fragment_container, new Fragment_Preferences(), Fragment_Preferences.Fragment_Settings)
.AddToBackStack(Fragment_Preferences.Fragment_Settings)
.Commit();
SupportFragmentManager.ExecutePendingTransactions();

return true;
}

return base.OnOptionsItemSelected(item);
}

Expand Down
1 change: 1 addition & 0 deletions Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class DefaultPrefSettings
public int freq { get; set; }
public string? OSM_Browse_Source { get; set; }
public string? OSM_BulkDownload_Source { get; set; }
public string StadiaToken { get; set; }
public string? MapboxToken { get; set; }
public string? ThunderforestToken { get; set; }
public string? CustomServerURL { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion OfflineMaps/DownloadRasterImageMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private static async Task DownloadTiles(AwesomeTiles.TileRange range, int zoom,

OSMServer = url + token;
}
else //Mapbox || Thunderforst
else //Mapbox || Thunderforest || StadiaMaps
{
var token = Preferences.Get(MapSource.Token, "");

Expand Down
2 changes: 1 addition & 1 deletion OfflineMaps/MBTiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public static async void RefreshOldTiles()

OSMServer = url + token;
}
else //Mapbox || Thunderforest
else //Mapbox || Thunderforest || Stadia Maps
{
var token = Preferences.Get(MapSource.Token, "");

Expand Down
2 changes: 1 addition & 1 deletion OfflineMaps/TileCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TileCache
persistentCache: mbTileCache,
userAgent: MapSource.Name + " in Mapsui (hajk)");
}
else //Mapbox || Thunderforest
else //Mapbox || Thunderforest || Stadia Maps
{
var token = Preferences.Get(MapSource.Token, "");

Expand Down
19 changes: 13 additions & 6 deletions Resources/Xml/Preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,26 @@
app:useSimpleSummaryProvider="true" />

<EditTextPreference
android:title="@string/MapboxTokenTitle"
android:key="@string/MapboxToken"
android:inputType="textPassword"
android:summary="@string/Hidden"
app:useSimpleSummaryProvider="false" />
android:title="@string/MapboxTokenTitle"
android:key="@string/MapboxToken"
android:inputType="textPassword"
android:summary="@string/Hidden"
app:useSimpleSummaryProvider="false" />

<EditTextPreference
android:title="@string/ThunderforestTokenTitle"
android:key="@string/ThunderforestToken"
android:inputType="textPassword"
android:summary="@string/Hidden"
app:useSimpleSummaryProvider="false" />


<EditTextPreference
android:title="@string/StadiaTokenTitle"
android:key="@string/StadiaToken"
android:inputType="textPassword"
android:summary="@string/Hidden"
app:useSimpleSummaryProvider="false" />

<EditTextPreference
android:title="@string/CustomServerTitle"
android:key="@string/CustomServerURL"
Expand Down
27 changes: 18 additions & 9 deletions Resources/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item

<item
android:id="@+id/AddCurrentLocationAsPOI"
android:title="@string/AddCurrentLocationAsPOI" />

<item
android:id="@+id/SaveGPSasPOI"
android:title="@string/SaveGPSasPOI" />

<item
android:id="@+id/AddRogainingPOI"
android:title="@string/AddRogainingPOI" />

<item
android:id="@+id/ExportRogainingPOI"
android:title="@string/ExportRogainingPOI" />

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
Expand All @@ -13,12 +30,4 @@
android:title="@string/Clear_map_of_routes_and_tracks"
app:showAsAction="never" />

<item
android:id="@+id/AddRogainingPOI"
android:title="@string/AddRogainingPOI" />

<item
android:id="@+id/ExportRogainingPOI"
android:title="@string/ExportRogainingPOI" />

</menu>
8 changes: 7 additions & 1 deletion Resources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
<string name="BackupOptions">"Choose Backup Options"</string>
<string name="KeepNBackups">"Backups to Retain"</string>
<string name="EnableBackupAtStartup">"Backup on first launch of the day"</string>
<string name="AddCurrentLocationAsPOI">"Save Current Location as POI</string>
<string name="SaveGPSasPOI">"Save GPS Coordinates as POI"</string>

<!-- Map Tile provider Start -->
<string name="MapTileSources">"Map Tile Sources"</string>
Expand All @@ -110,7 +112,11 @@
<string name="ThunderforestTokenTitle">Thunderforest Token</string>
<string name="ThunderforestToken">ThunderforestToken</string>

<!-- Custom -->
<!-- Stadia Maps -->
<string name="StadiaTokenTitle">Stadia Maps Token</string>
<string name="StadiaToken">StadiaToken</string>

<!-- Custom -->
<string name="CustomServerTitle">Custom Tile Server</string>
<string name="CustomServerHint">https://servername.domain.com/tile/{z}/{x}/{y}.png</string>
<string name="CustomServerURL">"CustomServerURL"</string>
Expand Down
1 change: 1 addition & 0 deletions Utils/Backup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ private static bool BackupPreferences(string BackupFolder)
CustomServerURL = Preferences.Get("CustomServerURL ", ""),
CustomToken = Preferences.Get("CustomToken", ""),
MapboxToken = Preferences.Get("MapboxToken", ""),
StadiaToken = Preferences.Get("StadiaToken", ""),
ThunderforestToken = Preferences.Get("ThunderforestToken", ""),

mapScale = Preferences.Get("mapScale", Fragment_Preferences.DefaultMapScale),
Expand Down

0 comments on commit d65a7c7

Please sign in to comment.