From a994a13fac7501c79b2aadd8f66b395d231ae11e Mon Sep 17 00:00:00 2001 From: "sushi.at" Date: Fri, 22 Dec 2023 23:33:06 +0000 Subject: [PATCH] osm maps Removed bing maps key from settings --- OpenSky.Agent.Simulator/OpenAPIs/swagger.cs | 18 ++-- OpenSky.Agent.Simulator/OpenAPIs/swagger.json | 17 ++- OpenSky.Agent/Controls/OsmTileSource.cs | 56 ++++++++++ OpenSky.Agent/OpenSky.Agent.csproj | 5 +- OpenSky.Agent/Resources/osm25.png | Bin 0 -> 1171 bytes OpenSky.Agent/Views/FlightTracking.xaml | 29 +++--- OpenSky.Agent/Views/FlightTracking.xaml.cs | 74 +++++++++++-- .../Models/FlightTrackingViewModel.Map.cs | 97 ------------------ .../Views/Models/SettingsViewModel.cs | 33 ------ OpenSky.Agent/Views/Settings.xaml | 17 ++- changelog.txt | 1 + 11 files changed, 171 insertions(+), 176 deletions(-) create mode 100644 OpenSky.Agent/Controls/OsmTileSource.cs create mode 100644 OpenSky.Agent/Resources/osm25.png diff --git a/OpenSky.Agent.Simulator/OpenAPIs/swagger.cs b/OpenSky.Agent.Simulator/OpenAPIs/swagger.cs index 61ad9e4..b7f0331 100644 --- a/OpenSky.Agent.Simulator/OpenAPIs/swagger.cs +++ b/OpenSky.Agent.Simulator/OpenAPIs/swagger.cs @@ -13424,12 +13424,6 @@ public enum JobType [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")] public partial class LinkedAccounts { - /// - /// Gets or sets the Bing maps API key. - /// - [Newtonsoft.Json.JsonProperty("bingMapsKey", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string BingMapsKey { get; set; } - /// /// Gets or sets the Simbrief username. /// @@ -13698,6 +13692,18 @@ public enum OnlineNetwork [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")] public partial class Payload { + /// + /// Gets or sets the aircraft latitude (if currently loaded onto an aircraft). + /// + [Newtonsoft.Json.JsonProperty("aircraftLatitude", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double? AircraftLatitude { get; set; } + + /// + /// Gets or sets the aircraft longitude (if currently loaded onto an aircraft). + /// + [Newtonsoft.Json.JsonProperty("aircraftLongitude", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double? AircraftLongitude { get; set; } + /// /// Gets or sets the aircraft registry the payload is currently loaded on, or NULL if stored at an airport. /// diff --git a/OpenSky.Agent.Simulator/OpenAPIs/swagger.json b/OpenSky.Agent.Simulator/OpenAPIs/swagger.json index 5a0a624..8f7a4f5 100644 --- a/OpenSky.Agent.Simulator/OpenAPIs/swagger.json +++ b/OpenSky.Agent.Simulator/OpenAPIs/swagger.json @@ -8517,11 +8517,6 @@ "LinkedAccounts": { "type": "object", "properties": { - "bingMapsKey": { - "type": "string", - "description": "Gets or sets the Bing maps API key.", - "nullable": true - }, "simbriefUsername": { "type": "string", "description": "Gets or sets the Simbrief username.", @@ -8798,6 +8793,18 @@ ], "type": "object", "properties": { + "aircraftLatitude": { + "type": "number", + "description": "Gets or sets the aircraft latitude (if currently loaded onto an aircraft).", + "format": "double", + "nullable": true + }, + "aircraftLongitude": { + "type": "number", + "description": "Gets or sets the aircraft longitude (if currently loaded onto an aircraft).", + "format": "double", + "nullable": true + }, "aircraftRegistry": { "maxLength": 12, "minLength": 6, diff --git a/OpenSky.Agent/Controls/OsmTileSource.cs b/OpenSky.Agent/Controls/OsmTileSource.cs new file mode 100644 index 0000000..e8ba2d2 --- /dev/null +++ b/OpenSky.Agent/Controls/OsmTileSource.cs @@ -0,0 +1,56 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// OpenSky project 2021-2023 +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace OpenSky.Agent.Controls +{ + using System; + + using Microsoft.Maps.MapControl.WPF; + + /// ------------------------------------------------------------------------------------------------- + /// + /// OpenStreetMap tile source. + /// + /// + /// sushi.at, 20/12/2023. + /// + /// + /// ------------------------------------------------------------------------------------------------- + public class OsmTileSource : TileSource + { + /// ------------------------------------------------------------------------------------------------- + /// + /// Retrieves the URI for the tile specified by the given x, y coordinates and zoom level. + /// + /// + /// sushi.at, 20/12/2023. + /// + /// + /// The horizontal position of the tile. + /// + /// + /// The vertical position of the tile. + /// + /// + /// The zoom level of the tile. + /// + /// + /// Returns a for the tile. + /// + /// + /// ------------------------------------------------------------------------------------------------- + public override Uri GetUri(int x, int y, int zoomLevel) + { + if (string.IsNullOrEmpty(this.UriFormat)) + { + return null; + } + + return new Uri( + this.UriFormat.Replace("{x}", x.ToString()).Replace("{y}", y.ToString()).Replace("{z}", zoomLevel.ToString())); + } + } +} \ No newline at end of file diff --git a/OpenSky.Agent/OpenSky.Agent.csproj b/OpenSky.Agent/OpenSky.Agent.csproj index 7ce8f62..4eec891 100644 --- a/OpenSky.Agent/OpenSky.Agent.csproj +++ b/OpenSky.Agent/OpenSky.Agent.csproj @@ -110,6 +110,7 @@ FuelTankControl.xaml + PayloadStationControl.xaml @@ -449,7 +450,9 @@ OpenSky.Agent.UdpXPlane11 - + + + call "$(ProjectDir)pre-build.bat" "$(ProjectDir)" "$(ConfigurationName)" diff --git a/OpenSky.Agent/Resources/osm25.png b/OpenSky.Agent/Resources/osm25.png new file mode 100644 index 0000000000000000000000000000000000000000..6de064612cec8ffa5dee4b4c661265168c87df8b GIT binary patch literal 1171 zcmV;E1Z?|>P)P000>X1ONa4Zs1Mm0003ZX+uL$Nkc;* zaB^>EX>4Tx04R~2kiSa9P!z_0siGovQYwf;2G_co$-#dZ911m!V0B896pKj=NlNhz zd=q_`4uaq-xGOmO-RR(87B769ABS_k@7@b7I|QWGJPf4hn5UV%S zOvR0;l#|Pm$QS804S8F2USBCAc}(PG67ERlY4R}t`@QyYUT<2Rc^(u&-CB@Z<1xHH z!rBnlpJDa7A#3IL+Ztw^dgh;R`~pq^P?rknizWa700Lr5M??T7cz~wQ00009a7bBm z001r{001r{0eGc9b^rhX2XskIMF-~$77Q>KBA70S0000PbVXQnLvL+uWo~o;Lvm$d zbY)~9cWHEJAV*0}P*;Ht7XSbP(Md!>R5;6((_LuRWf%tV-}C>!@8&i~#&k5bk3}dZ zeR!azr4~gWh@Mzf6iIa?6%_>?MIA&3VHA=WQU`ew9u?7tbuufPlAv?wWHB{0Li}2D z(|7MX|IgFGJDsHo-G}#mU0nBdbKRlS|E;jr4q)Ji~O7O6WS%JMemOG^}jd_whL8NsNVU z-qY0+ipS%d>1Kf$re6?_)$FvvePLzW!P3QT%IQ9f)6YqL?~qRk111XDFRse&n54LO4n!5m98O8)e%7HiA_dwl6` zH`u33$-}1E<(E38*&+@4Of%CwO>T8ej}AK&GPzlLbZD2!>b7XpY|xK(OWL#wYL5HL zPIX_C%y;KFTwNu{n5c$akEL$(jA)1N>-RNV5HFH45^_O?)h0 zD1*jKG21M`uql=sv0qIXk7S>IyPUpsv0;17bH89%uSYDk4D56UNzD(Edl=U#5p_Fe zx~hJIw)tJB;DGJg^*e4z#1YAn3lyRO1LHqZ(WUD`uuOc@VTUKYT%~HRke@6>z0O_< zo_*n=@Rok(|3$eeW^40%!)BFBx-sm}pDI0(ZOz{)Ey$h@TT~|WLc-@xmE(f=s^xLg z9>rf_eg0w7$qnO>O@aipmNz{SBYU4jN5aU0eVF002ovPDHLkV1m!7B}D)L literal 0 HcmV?d00001 diff --git a/OpenSky.Agent/Views/FlightTracking.xaml b/OpenSky.Agent/Views/FlightTracking.xaml index 77c69e2..1745919 100644 --- a/OpenSky.Agent/Views/FlightTracking.xaml +++ b/OpenSky.Agent/Views/FlightTracking.xaml @@ -671,8 +671,13 @@ Map - - + + + + + @@ -687,26 +692,16 @@ Follow aircraft - + - Road + Dark + Bright + Topo Aerial - - - - - Darken road map - + diff --git a/OpenSky.Agent/Views/FlightTracking.xaml.cs b/OpenSky.Agent/Views/FlightTracking.xaml.cs index dbdcb69..a6e386e 100644 --- a/OpenSky.Agent/Views/FlightTracking.xaml.cs +++ b/OpenSky.Agent/Views/FlightTracking.xaml.cs @@ -162,7 +162,16 @@ private void FlightTrackingLoaded(object sender, RoutedEventArgs e) } // Configure map view - this.MapView.CredentialsProvider = new ApplicationIdCredentialsProvider(UserSessionService.Instance.LinkedAccounts?.BingMapsKey); + try + { + this.MapView.Children.Add(this.mapLayer); + this.MapView.Children.Add(this.overlayLayer); + } + catch (Exception ex) + { + Debug.WriteLine($"Map layer already added error.\r\n{ex}"); + } + this.AddAircraftAndTrailsToMap(); // Add fuel tank controls @@ -286,6 +295,16 @@ private void FlightTrackingViewModelOnMapPositionUpdated(object sender, MapPosit private void FlightTrackingViewModelOnResetTrackingMap(object sender, EventArgs e) { this.MapView.Children.Clear(); + try + { + this.MapView.Children.Add(this.mapLayer); + this.MapView.Children.Add(this.overlayLayer); + } + catch (Exception ex) + { + Debug.WriteLine($"Map layer already added error.\r\n{ex}"); + } + this.AddAircraftAndTrailsToMap(); } @@ -409,6 +428,34 @@ private void GroundHandlingWarningOnIsVisibleChanged(object sender, DependencyPr } } + // ------------------------------------------------------------------------------------------------- + /// + /// The map layer. + /// + /// ------------------------------------------------------------------------------------------------- + private MapTileLayer mapLayer = new MapTileLayer + { + TileSource = new OsmTileSource + { + UriFormat = "https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png" + }, + Opacity = 1 + }; + + /// ------------------------------------------------------------------------------------------------- + /// + /// The overlay layer. + /// + /// ------------------------------------------------------------------------------------------------- + private readonly MapTileLayer overlayLayer = new MapTileLayer + { + TileSource = new OsmTileSource() + { + // No source uri format initially for default + }, + Opacity = 1 + }; + /// ------------------------------------------------------------------------------------------------- /// /// Map type selection changed. @@ -425,17 +472,32 @@ private void GroundHandlingWarningOnIsVisibleChanged(object sender, DependencyPr /// ------------------------------------------------------------------------------------------------- private void MapTypeOnSelectionChanged(object sender, SelectionChangedEventArgs e) { - if (this.MapType.SelectedItem is ComboBoxItem item) + if (this.MapType.SelectedItem is ComboBoxItem { Content: string content }) { - switch (item.Content as string) + this.MapView.Children.Remove(this.mapLayer); + this.mapLayer = new MapTileLayer + { + TileSource = new OsmTileSource(), + Opacity = 1, + }; + + switch (content) { - case "Road": - this.MapView.Mode = new RoadMode(); + case "Dark": + this.mapLayer.TileSource.UriFormat = "https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"; + break; + case "Bright": + this.mapLayer.TileSource.UriFormat = "https://basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png"; + break; + case "Topo": + this.mapLayer.TileSource.UriFormat = "https://tile.opentopomap.org/{z}/{x}/{y}.png"; break; case "Aerial": - this.MapView.Mode = new AerialMode(); + this.mapLayer.TileSource.UriFormat = "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"; break; } + + this.MapView.Children.Insert(0, this.mapLayer); } } diff --git a/OpenSky.Agent/Views/Models/FlightTrackingViewModel.Map.cs b/OpenSky.Agent/Views/Models/FlightTrackingViewModel.Map.cs index e67ba56..3c1e150 100644 --- a/OpenSky.Agent/Views/Models/FlightTrackingViewModel.Map.cs +++ b/OpenSky.Agent/Views/Models/FlightTrackingViewModel.Map.cs @@ -13,7 +13,6 @@ namespace OpenSky.Agent.Views.Models using System.Net; using System.Text; using System.Windows; - using System.Windows.Controls; using System.Xml.Linq; using Microsoft.Maps.MapControl.WPF; @@ -47,20 +46,6 @@ public partial class FlightTrackingViewModel /// ------------------------------------------------------------------------------------------------- private Location aircraftLocation; - /// ------------------------------------------------------------------------------------------------- - /// - /// True to darken road map. - /// - /// ------------------------------------------------------------------------------------------------- - private bool darkenRoadMap = true; - - /// ------------------------------------------------------------------------------------------------- - /// - /// The dark road map visibility. - /// - /// ------------------------------------------------------------------------------------------------- - private Visibility darkRoadMapVisibility = Visibility.Visible; - /// ------------------------------------------------------------------------------------------------- /// /// True to follow plane on the map. @@ -89,13 +74,6 @@ public partial class FlightTrackingViewModel /// ------------------------------------------------------------------------------------------------- private DateTime lastUserMapInteraction = DateTime.MinValue; - /// ------------------------------------------------------------------------------------------------- - /// - /// The selected map mode. - /// - /// ------------------------------------------------------------------------------------------------- - private ComboBoxItem selectedMapMode; - /// ------------------------------------------------------------------------------------------------- /// /// Occurs when the view model wants to update the map position. @@ -157,54 +135,6 @@ public Location AircraftLocation } } - /// ------------------------------------------------------------------------------------------------- - /// - /// Gets or sets a value indicating whether to the darken the road map. - /// - /// ------------------------------------------------------------------------------------------------- - public bool DarkenRoadMap - { - get => this.darkenRoadMap; - - set - { - if (Equals(this.darkenRoadMap, value)) - { - return; - } - - this.darkenRoadMap = value; - this.NotifyPropertyChanged(); - Debug.WriteLine($"Darken road map toggled {value}"); - - if (this.SelectedMapMode.Content is string mode) - { - this.DarkRoadMapVisibility = mode.Equals("Road", StringComparison.InvariantCultureIgnoreCase) && this.DarkenRoadMap ? Visibility.Visible : Visibility.Collapsed; - } - } - } - - /// ------------------------------------------------------------------------------------------------- - /// - /// Gets or sets the dark road map visibility. - /// - /// ------------------------------------------------------------------------------------------------- - public Visibility DarkRoadMapVisibility - { - get => this.darkRoadMapVisibility; - - set - { - if (Equals(this.darkRoadMapVisibility, value)) - { - return; - } - - this.darkRoadMapVisibility = value; - this.NotifyPropertyChanged(); - } - } - /// ------------------------------------------------------------------------------------------------- /// /// Gets or sets a value indicating whether to follow the plane on the map. @@ -262,33 +192,6 @@ public DateTime LastUserMapInteraction /// ------------------------------------------------------------------------------------------------- public Command MoveMapToCoordinateCommand { get; } - /// ------------------------------------------------------------------------------------------------- - /// - /// Gets or sets the selected map mode. - /// - /// ------------------------------------------------------------------------------------------------- - public ComboBoxItem SelectedMapMode - { - get => this.selectedMapMode; - - set - { - if (Equals(this.selectedMapMode, value)) - { - return; - } - - this.selectedMapMode = value; - this.NotifyPropertyChanged(); - Debug.WriteLine($"Map mode changed {value.Content}"); - - if (this.SelectedMapMode.Content is string mode) - { - this.DarkRoadMapVisibility = mode.Equals("Road", StringComparison.InvariantCultureIgnoreCase) && this.DarkenRoadMap ? Visibility.Visible : Visibility.Collapsed; - } - } - } - /// ------------------------------------------------------------------------------------------------- /// /// Import simbrief waypoints. diff --git a/OpenSky.Agent/Views/Models/SettingsViewModel.cs b/OpenSky.Agent/Views/Models/SettingsViewModel.cs index f45336c..742febc 100644 --- a/OpenSky.Agent/Views/Models/SettingsViewModel.cs +++ b/OpenSky.Agent/Views/Models/SettingsViewModel.cs @@ -53,13 +53,6 @@ public class SettingsViewModel : ViewModel /// ------------------------------------------------------------------------------------------------- private int aircraftPositionUpdateInterval; - /// ------------------------------------------------------------------------------------------------- - /// - /// The Bing maps key. - /// - /// ------------------------------------------------------------------------------------------------- - private string bingMapsKey; - /// ------------------------------------------------------------------------------------------------- /// /// Are there changes to the settings to be saved? @@ -197,7 +190,6 @@ public SettingsViewModel() this.XplaneIPAddress = Settings.Default.XPlaneIPAddress; this.XplanePort = Settings.Default.XPlanePort; this.AircraftPositionUpdateInterval = Settings.Default.AircraftPositionUpdateInterval; - this.BingMapsKey = UserSessionService.Instance.LinkedAccounts?.BingMapsKey; this.SimBriefUsername = UserSessionService.Instance.LinkedAccounts?.SimbriefUsername; this.VatsimID = UserSessionService.Instance.LinkedAccounts?.VatsimID; this.SelectedLandingReportNotification = LandingReportNotification.Parse(Settings.Default.LandingReportNotification); @@ -274,28 +266,6 @@ public int AircraftPositionUpdateInterval } } - /// ------------------------------------------------------------------------------------------------- - /// - /// Gets or sets the Bing maps key. - /// - /// ------------------------------------------------------------------------------------------------- - public string BingMapsKey - { - get => this.bingMapsKey; - - set - { - if (Equals(this.bingMapsKey, value)) - { - return; - } - - this.bingMapsKey = value; - this.NotifyPropertyChanged(); - this.IsDirty = true; - } - } - /// ------------------------------------------------------------------------------------------------- /// /// Gets the change password command. @@ -766,7 +736,6 @@ private void LogoutOpenSkyUser() () => { var wasDirty = this.IsDirty; - this.BingMapsKey = null; this.SimBriefUsername = null; this.ProfileImage = new BitmapImage(new Uri("pack://application:,,,/OpenSky.Agent;component/Resources/profile200.png")); this.IsDirty = wasDirty; @@ -884,7 +853,6 @@ private void SaveSettings() { var linkedAccounts = new LinkedAccounts { - BingMapsKey = this.BingMapsKey, SimbriefUsername = this.SimBriefUsername, VatsimID = this.VatsimID }; @@ -1098,7 +1066,6 @@ private void UserSessionPropertyChanged(object sender, PropertyChangedEventArgs } var wasDirty = this.IsDirty; - this.BingMapsKey = UserSessionService.Instance.LinkedAccounts?.BingMapsKey; this.SimBriefUsername = UserSessionService.Instance.LinkedAccounts?.SimbriefUsername; this.IsDirty = wasDirty; } diff --git a/OpenSky.Agent/Views/Settings.xaml b/OpenSky.Agent/Views/Settings.xaml index 7be593d..4e78668 100644 --- a/OpenSky.Agent/Views/Settings.xaml +++ b/OpenSky.Agent/Views/Settings.xaml @@ -111,18 +111,13 @@ - - - A Bing Maps key is required to correctly display the maps in the various clients, if you don't already have one please visit the Bing Maps Dev Center and create one. - Bing maps key: - You can import your simBrief flight plans into your flight plans and tracking sessions, to enable this feature please enter your account alias as shown on the simBrief Account Settings page. - simBrief user name: - If you want to fly on Vatsim, please provide your numerical user ID here. You can find it on your Vatsim profile page. - Vatsim ID: - - - + You can import your simBrief flight plans into your flight plans and tracking sessions, to enable this feature please enter your account alias as shown on the simBrief Account Settings page. + simBrief user name: + If you want to fly on Vatsim, please provide your numerical user ID here. You can find it on your Vatsim profile page. + Vatsim ID: + + diff --git a/changelog.txt b/changelog.txt index 25d559b..68510a3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ OpenSky Flight Tracking Agent Changelog Version 0.5.12 (ALPHA5) -------------------------------------------------------------------------------------- - Fixed default AvGas override for new aircraft +- Map view now using OSM, bing maps key no longer necessary, removed from settings -------------------------------------------------------------------------------------- Version 0.5.11 (ALPHA5)