mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Added SampleApps/ProjectionDemo
This commit is contained in:
parent
e3332e44d4
commit
d603ac7e72
9
SampleApps/ProjectionDemo/App.xaml
Normal file
9
SampleApps/ProjectionDemo/App.xaml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<Application x:Class="ProjectionDemo.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:ProjectionDemo"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
8
SampleApps/ProjectionDemo/App.xaml.cs
Normal file
8
SampleApps/ProjectionDemo/App.xaml.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace ProjectionDemo
|
||||||
|
{
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
34
SampleApps/ProjectionDemo/MainWindow.xaml
Normal file
34
SampleApps/ProjectionDemo/MainWindow.xaml
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<Window x:Class="ProjectionDemo.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:map="clr-namespace:MapControl;assembly=MapControl.WPF"
|
||||||
|
Title="XAML MapControl - Projection Demo" Height="600" Width="800"
|
||||||
|
Loaded="Window_Loaded">
|
||||||
|
<DockPanel>
|
||||||
|
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
|
||||||
|
<ComboBox Margin="2"
|
||||||
|
ItemsSource="{Binding Projections}"
|
||||||
|
SelectedItem="{Binding CurrentProjection}"
|
||||||
|
DisplayMemberPath="CrsId"/>
|
||||||
|
<ComboBox Margin="2"
|
||||||
|
ItemsSource="{Binding Layers}"
|
||||||
|
SelectedValue="{Binding CurrentLayer}"
|
||||||
|
SelectedValuePath="Value"
|
||||||
|
DisplayMemberPath="Key"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<map:Map MaxZoomLevel="22" ZoomLevel="8" Center="50,8" MapLayer="{Binding CurrentLayer}"
|
||||||
|
MouseRightButtonUp="Map_MouseRightButtonUp">
|
||||||
|
<map:MapBase.MapProjection>
|
||||||
|
<Binding Path="CurrentProjection">
|
||||||
|
<Binding.FallbackValue>
|
||||||
|
<map:WebMercatorProjection/>
|
||||||
|
</Binding.FallbackValue>
|
||||||
|
</Binding>
|
||||||
|
</map:MapBase.MapProjection>
|
||||||
|
|
||||||
|
<map:Pushpin map:MapPanel.Location="{Binding PushpinLocation}"
|
||||||
|
Content="{Binding PushpinText}"/>
|
||||||
|
</map:Map>
|
||||||
|
</DockPanel>
|
||||||
|
</Window>
|
||||||
156
SampleApps/ProjectionDemo/MainWindow.xaml.cs
Normal file
156
SampleApps/ProjectionDemo/MainWindow.xaml.cs
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
using MapControl;
|
||||||
|
using MapControl.Projections;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace ProjectionDemo
|
||||||
|
{
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
private readonly HttpClient httpClient = new HttpClient();
|
||||||
|
private readonly ViewModel viewModel = new ViewModel();
|
||||||
|
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> GetWktAsync(int epsgCode)
|
||||||
|
{
|
||||||
|
var wkt = await httpClient.GetStringAsync(string.Format("https://epsg.io/{0}.wkt", epsgCode));
|
||||||
|
|
||||||
|
if (!wkt.Contains("PARAMETER[\"latitude_of_origin\",") &&
|
||||||
|
!wkt.Contains("PARAMETER[\"latitude_of_center\","))
|
||||||
|
{
|
||||||
|
wkt = wkt.Replace(
|
||||||
|
"PARAMETER[\"central_meridian\",",
|
||||||
|
"PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",");
|
||||||
|
}
|
||||||
|
|
||||||
|
return wkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
viewModel.Projections.Add(new MapControl.Projections.WebMercatorProjection());
|
||||||
|
|
||||||
|
viewModel.Projections.Add(new GeoApiProjection
|
||||||
|
{
|
||||||
|
WKT = await httpClient.GetStringAsync("https://epsg.io/25832.wkt") // ETRS89 / UTM zone 32N
|
||||||
|
});
|
||||||
|
|
||||||
|
viewModel.Layers.Add(
|
||||||
|
"OpenStreetMap WMS",
|
||||||
|
new WmsImageLayer
|
||||||
|
{
|
||||||
|
ServiceUri = new Uri("http://ows.terrestris.de/osm/service"),
|
||||||
|
Layers = "OSM-WMS"
|
||||||
|
});
|
||||||
|
|
||||||
|
viewModel.Layers.Add(
|
||||||
|
"TopPlusOpen WMS",
|
||||||
|
new WmsImageLayer
|
||||||
|
{
|
||||||
|
ServiceUri = new Uri("https://sgx.geodatenzentrum.de/wms_topplus_open"),
|
||||||
|
Layers = "web"
|
||||||
|
});
|
||||||
|
|
||||||
|
viewModel.Layers.Add(
|
||||||
|
"Orthophotos Wiesbaden",
|
||||||
|
new WmsImageLayer
|
||||||
|
{
|
||||||
|
ServiceUri = new Uri("https://geoportal.wiesbaden.de/cgi-bin/mapserv.fcgi?map=d:/openwimap/umn/map/orthophoto/orthophotos.map"),
|
||||||
|
Layers = "orthophoto2017"
|
||||||
|
});
|
||||||
|
|
||||||
|
viewModel.CurrentProjection = viewModel.Projections[0];
|
||||||
|
viewModel.CurrentLayer = viewModel.Layers.First().Value;
|
||||||
|
|
||||||
|
DataContext = viewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Map_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
viewModel.PushpinLocation = viewModel.CurrentProjection.ViewportPointToLocation(e.GetPosition((IInputElement)sender));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewModel : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
private MapProjection currentProjection;
|
||||||
|
private IMapLayer currentLayer;
|
||||||
|
private Location pushpinLocation = new Location();
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
public List<MapProjection> Projections { get; } = new List<MapProjection>();
|
||||||
|
|
||||||
|
public Dictionary<string, IMapLayer> Layers { get; } = new Dictionary<string, IMapLayer>();
|
||||||
|
|
||||||
|
public MapProjection CurrentProjection
|
||||||
|
{
|
||||||
|
get => currentProjection;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
currentProjection = value;
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentProjection)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMapLayer CurrentLayer
|
||||||
|
{
|
||||||
|
get => currentLayer;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
currentLayer = value;
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentLayer)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location PushpinLocation
|
||||||
|
{
|
||||||
|
get => pushpinLocation;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
pushpinLocation = value;
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PushpinLocation)));
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PushpinText)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PushpinText
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var latitude = (int)Math.Round(PushpinLocation.Latitude * 3600);
|
||||||
|
var longitude = (int)Math.Round(Location.NormalizeLongitude(PushpinLocation.Longitude) * 3600);
|
||||||
|
var latHemisphere = 'N';
|
||||||
|
var lonHemisphere = 'E';
|
||||||
|
|
||||||
|
if (latitude < 0)
|
||||||
|
{
|
||||||
|
latitude = -latitude;
|
||||||
|
latHemisphere = 'S';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (longitude < 0)
|
||||||
|
{
|
||||||
|
longitude = -longitude;
|
||||||
|
lonHemisphere = 'W';
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1:00} {2:00} {3:00}\n{4} {5:000} {6:00} {7:00}",
|
||||||
|
latHemisphere, latitude / 3600, (latitude / 60) % 60, latitude % 60,
|
||||||
|
lonHemisphere, longitude / 3600, (longitude / 60) % 60, longitude % 60);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
SampleApps/ProjectionDemo/ProjectionDemo.csproj
Normal file
19
SampleApps/ProjectionDemo/ProjectionDemo.csproj
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
<Version>4.17.0</Version>
|
||||||
|
<Authors>Clemens Fischer</Authors>
|
||||||
|
<Description>XAML Map Control Map Projection Demo Application</Description>
|
||||||
|
<Product>XAML Map Control</Product>
|
||||||
|
<Copyright>Copyright © 2020 Clemens Fischer</Copyright>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.csproj" />
|
||||||
|
<ProjectReference Include="..\..\MapProjections\WPF\MapProjections.WPF.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
14
SampleApps/ProjectionDemo/ProjectionDemo.csproj.user
Normal file
14
SampleApps/ProjectionDemo/ProjectionDemo.csproj.user
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
<ItemGroup>
|
||||||
|
<ApplicationDefinition Update="App.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</ApplicationDefinition>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Page Update="MainWindow.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</Page>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
Loading…
Reference in a new issue