Skip to content

Commit

Permalink
osm maps
Browse files Browse the repository at this point in the history
Removed bing maps key from settings
  • Loading branch information
sushiat committed Dec 22, 2023
1 parent 429841c commit a994a13
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 176 deletions.
18 changes: 12 additions & 6 deletions OpenSky.Agent.Simulator/OpenAPIs/swagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
/// Gets or sets the Bing maps API key.
/// </summary>
[Newtonsoft.Json.JsonProperty("bingMapsKey", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string BingMapsKey { get; set; }

/// <summary>
/// Gets or sets the Simbrief username.
/// </summary>
Expand Down Expand Up @@ -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
{
/// <summary>
/// Gets or sets the aircraft latitude (if currently loaded onto an aircraft).
/// </summary>
[Newtonsoft.Json.JsonProperty("aircraftLatitude", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double? AircraftLatitude { get; set; }

/// <summary>
/// Gets or sets the aircraft longitude (if currently loaded onto an aircraft).
/// </summary>
[Newtonsoft.Json.JsonProperty("aircraftLongitude", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double? AircraftLongitude { get; set; }

/// <summary>
/// Gets or sets the aircraft registry the payload is currently loaded on, or NULL if stored at an airport.
/// </summary>
Expand Down
17 changes: 12 additions & 5 deletions OpenSky.Agent.Simulator/OpenAPIs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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,
Expand Down
56 changes: 56 additions & 0 deletions OpenSky.Agent/Controls/OsmTileSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OsmTileSource.cs" company="OpenSky">
// OpenSky project 2021-2023
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace OpenSky.Agent.Controls
{
using System;

using Microsoft.Maps.MapControl.WPF;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// OpenStreetMap tile source.
/// </summary>
/// <remarks>
/// sushi.at, 20/12/2023.
/// </remarks>
/// <seealso cref="Microsoft.Maps.MapControl.WPF.TileSource"/>
/// -------------------------------------------------------------------------------------------------
public class OsmTileSource : TileSource
{
/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Retrieves the URI for the tile specified by the given x, y coordinates and zoom level.
/// </summary>
/// <remarks>
/// sushi.at, 20/12/2023.
/// </remarks>
/// <param name="x">
/// The horizontal position of the tile.
/// </param>
/// <param name="y">
/// The vertical position of the tile.
/// </param>
/// <param name="zoomLevel">
/// The zoom level of the tile.
/// </param>
/// <returns>
/// Returns a <see cref="T:System.Uri"></see> for the tile.
/// </returns>
/// <seealso cref="Microsoft.Maps.MapControl.WPF.TileSource.GetUri(int,int,int)"/>
/// -------------------------------------------------------------------------------------------------
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()));
}
}
}
5 changes: 4 additions & 1 deletion OpenSky.Agent/OpenSky.Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<DependentUpon>FuelTankControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\OpenSkyWindow.cs" />
<Compile Include="Controls\OsmTileSource.cs" />
<Compile Include="Controls\PayloadStationControl.xaml.cs">
<DependentUpon>PayloadStationControl.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -449,7 +450,9 @@
<Name>OpenSky.Agent.UdpXPlane11</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="Resources\osm25.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>call "$(ProjectDir)pre-build.bat" "$(ProjectDir)" "$(ConfigurationName)"
Expand Down
Binary file added OpenSky.Agent/Resources/osm25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 12 additions & 17 deletions OpenSky.Agent/Views/FlightTracking.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,13 @@
<TextBlock FontSize="15" FontWeight="DemiBold">Map</TextBlock>
</GroupBox.Header>
<Grid>
<wpf:Map Name="MapView" ZoomLevel="13" UseInertia="False" AnimationLevel="Full" MouseDoubleClick="UserMapInteraction" MouseWheel="UserMapInteraction" MouseLeftButtonDown="UserMapInteraction" MouseLeftButtonUp="UserMapInteraction" TouchMove="UserMapInteraction" Center="{Binding Simulator.PrimaryTracking.MapLocation, Mode=OneTime}" />
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="#66000000" IsHitTestVisible="False" Visibility="{Binding DarkRoadMapVisibility}" />
<wpf:Map Name="MapView" ZoomLevel="13" UseInertia="False" AnimationLevel="Full" MouseDoubleClick="UserMapInteraction" MouseWheel="UserMapInteraction" MouseLeftButtonDown="UserMapInteraction" MouseLeftButtonUp="UserMapInteraction" TouchMove="UserMapInteraction"
Center="{Binding Simulator.PrimaryTracking.MapLocation, Mode=OneTime}"
CredentialsProvider="fArR3iVIKxkPiLfleVSt~7ukVq4lwvPH4aTvFlJByPg~AhkC97Z8SGWamMatR22bF1snD0j_26rdxLfQzKjIRM-b7IP9Cfpo1ibjMBrJOal1" Background="{StaticResource OpenSkyGroupboxBackgroundBrush}">
<wpf:Map.Mode>
<wpf:MercatorMode />
</wpf:Map.Mode>
</wpf:Map>
<StackPanel Orientation="Vertical" HorizontalAlignment="Right" VerticalAlignment="Top">
<Border CornerRadius="2" Padding="8,0,8,0" BorderThickness="0.7" BorderBrush="White" Margin="1">
<Border.Style>
Expand All @@ -687,26 +692,16 @@
</Border.Style>
<CheckBox IsChecked="{Binding FollowPlane, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">Follow aircraft</CheckBox>
</Border>
<ComboBox Name="MapType" HorizontalAlignment="Stretch" Margin="0,2,1,2" SelectionChanged="MapTypeOnSelectionChanged" SelectedValue="{Binding SelectedMapMode, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}">
<ComboBox Name="MapType" HorizontalAlignment="Stretch" Margin="0,2,1,2" SelectionChanged="MapTypeOnSelectionChanged">
<ComboBox.Items>
<ComboBoxItem IsSelected="True">Road</ComboBoxItem>
<ComboBoxItem IsSelected="True">Dark</ComboBoxItem>
<ComboBoxItem>Bright</ComboBoxItem>
<ComboBoxItem>Topo</ComboBoxItem>
<ComboBoxItem>Aerial</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
<Border CornerRadius="2" Padding="8,0,8,0" BorderThickness="0.7" BorderBrush="White" Margin="1">
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="#66000000"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#99000000" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<CheckBox IsChecked="{Binding DarkenRoadMap, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">Darken road map</CheckBox>
</Border>
</StackPanel>
<Image Source="/Resources/osm25.png" Width="25" Height="25" Margin="65,0,0,12" HorizontalAlignment="Left" VerticalAlignment="Bottom" />
</Grid>
</GroupBox>
<Border Grid.Row="0" Grid.Column="0" Grid.RowSpan="8" Grid.ColumnSpan="5" Background="#CC000000" Margin="-20" Visibility="{Binding NoFlightVisibility, Mode=OneWay}">
Expand Down
74 changes: 68 additions & 6 deletions OpenSky.Agent/Views/FlightTracking.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -409,6 +428,34 @@ private void GroundHandlingWarningOnIsVisibleChanged(object sender, DependencyPr
}
}

// -------------------------------------------------------------------------------------------------
/// <summary>
/// The map layer.
/// </summary>
/// -------------------------------------------------------------------------------------------------
private MapTileLayer mapLayer = new MapTileLayer
{
TileSource = new OsmTileSource
{
UriFormat = "https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"
},
Opacity = 1
};

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The overlay layer.
/// </summary>
/// -------------------------------------------------------------------------------------------------
private readonly MapTileLayer overlayLayer = new MapTileLayer
{
TileSource = new OsmTileSource()
{
// No source uri format initially for default
},
Opacity = 1
};

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Map type selection changed.
Expand All @@ -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);
}
}

Expand Down
Loading

0 comments on commit a994a13

Please sign in to comment.