Version 3.1.Added support for different map projections.

This commit is contained in:
ClemensF 2017-06-25 23:05:48 +02:00
parent 06c3ed56c1
commit 643abeca1e
124 changed files with 3074 additions and 2497 deletions

View file

@ -8,76 +8,6 @@
Title="XAML MapControl - WPF Test Application" Height="600" Width="800"
Stylus.IsPressAndHoldEnabled="False">
<Window.Resources>
<!--
TileLayers with OpenStreetMap data.
-->
<map:TileLayer x:Key="OpenStreetMap" SourceName="OpenStreetMap"
Description="Maps © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"
MaxZoomLevel="19"/>
<map:TileLayer x:Key="OpenCycleMap" SourceName="Thunderforest OpenCycleMap"
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://{c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png"/>
<map:TileLayer x:Key="Landscape" SourceName="Thunderforest Landscape"
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://{c}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png"/>
<map:TileLayer x:Key="Outdoors" SourceName="Thunderforest Outdoors"
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://{c}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png"/>
<map:TileLayer x:Key="Transport" SourceName="Thunderforest Transport"
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://{c}.tile.thunderforest.com/transport/{z}/{x}/{y}.png"/>
<map:TileLayer x:Key="TransportDark" SourceName="Thunderforest Transport Dark"
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://{c}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png"
Foreground="White" Background="Black"/>
<map:TileLayer x:Key="MapQuest" SourceName="MapQuest OpenStreetMap"
Description="Maps © [MapQuest](http://www.mapquest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://otile{n}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg"
MaxZoomLevel="19"/>
<map:TileLayer x:Key="Seamarks" SourceName="Seamarks"
TileSource="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
MinZoomLevel="9" MaxZoomLevel="18"/>
<!--
A TileLayer using World OSM WMS, a Web Map Service based on OpenStreetMap data.
Please contact the provider at http://www.osm-wms.de/ if you intend to use this in an application.
-->
<map:TileLayer x:Key="WorldOsm" SourceName="World OSM WMS"
Description="[World OSM WMS](http://www.osm-wms.de/) © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="http://129.206.228.72/cached/osm?SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=GetMap&amp;LAYERS=osm_auto:all&amp;STYLES=&amp;SRS=EPSG:900913&amp;BBOX={W},{S},{E},{N}&amp;WIDTH={X}&amp;HEIGHT={Y}&amp;FORMAT=image/png"/>
<!--
Bing Maps TileLayers with tile URLs retrieved from the Imagery Metadata Service
(see http://msdn.microsoft.com/en-us/library/ff701716.aspx).
A Bing Maps API Key (see http://msdn.microsoft.com/en-us/library/ff428642.aspx) is required
for using these layers and must be assigned to the static BingMapsTileLayer.ApiKey property.
-->
<map:BingMapsTileLayer x:Key="BingRoad" SourceName="Bing Maps Road"
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
Mode="Road" MaxZoomLevel="19"/>
<map:BingMapsTileLayer x:Key="BingAerial" SourceName="Bing Maps Aerial"
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
Mode="Aerial" MaxZoomLevel="19" Foreground="White" Background="Black"/>
<map:BingMapsTileLayer x:Key="BingHybrid" SourceName="Bing Maps Hybrid"
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
Mode="AerialWithLabels" MaxZoomLevel="19" Foreground="White" Background="Black"/>
<!--
A TileLayer that uses an ImageTileSource
-->
<!--<map:TileLayer x:Key="OsmImageTileSource"
Description="© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)">
<map:ImageTileSource IsAsync="True" UriFormat="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"/>
</map:TileLayer>-->
<!--
A TileLayer that demonstrates how to access local tile image files (from ImageFileCache here)
-->
<!--<map:TileLayer x:Key="OsmLocalFiles"
Description="© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
TileSource="file:///C:/ProgramData/MapControl/TileCache/OpenStreetMap/{z}/{x}/{y}.png"/>-->
<local:LocationToVisibilityConverter x:Key="LocationToVisibilityConverter"/>
<DataTemplate x:Key="PolylineItemTemplate">
@ -176,10 +106,16 @@
</Trigger>
</Style.Triggers>
</Style>
<map:WebMercatorProjection x:Key="WebMercatorProjection"/>
<map:EquirectangularProjection x:Key="EquirectangularProjection"/>
<map:OrthographicProjection x:Key="OrthographicProjection"/>
<map:GnomonicProjection x:Key="GnomonicProjection"/>
<map:StereographicProjection x:Key="StereographicProjection"/>
</Window.Resources>
<Window.DataContext>
<vm:ViewModel/>
<vm:MapViewModel/>
</Window.DataContext>
<Grid>
@ -187,20 +123,21 @@
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<map:Map x:Name="map" ZoomLevel="11" MaxZoomLevel="20" Center="{Binding MapCenter}"
TileLayer="{StaticResource OpenStreetMap}"
MouseLeftButtonDown="MapMouseLeftButtonDown" MouseRightButtonDown="MapMouseRightButtonDown"
<map:Map x:Name="map" ZoomLevel="11" MaxZoomLevel="20"
Center="{Binding MapCenter}"
MapLayer="{Binding MapLayers.CurrentMapLayer}"
MapProjection="{Binding SelectedValue, ElementName=projectionComboBox,
FallbackValue={StaticResource WebMercatorProjection},
TargetNullValue={StaticResource WebMercatorProjection}}"
MouseLeftButtonDown="MapMouseLeftButtonDown"
MouseRightButtonDown="MapMouseRightButtonDown"
MouseMove="MapMouseMove" MouseLeave="MapMouseLeave"
ManipulationInertiaStarting="MapManipulationInertiaStarting">
<!-- experimental WMS map layers -->
<!--<map:WmsImageLayer ServerUri="http://129.206.228.72/cached/osm" Layers="osm_auto:all"/>-->
<!--<map:WmsImageLayer ServerUri="http://ows.terrestris.de/osm/service" Layers="OSM-WMS"/>-->
<Image x:Name="mapImage" Source="10_535_330.jpg" Opacity="0.5" Stretch="Fill"
map:MapPanel.BoundingBox="53.54031,8.08594,53.74871,8.43750"/>
<map:MapImage x:Name="mapImage" South="53.54031" North="53.74871" West="8.08594" East="8.43750"
Source="10_535_330.jpg" Opacity="0.5"/>
<map:MapGraticule Opacity="0.6"/>
<map:MapGraticule x:Name="mapGraticule" Opacity="0.6"/>
<map:MapScale Margin="4" Opacity="0.8" HorizontalAlignment="Left" Background="Transparent"/>
<!-- use ItemTemplate or ItemContainerStyle alternatively -->
@ -218,22 +155,18 @@
ItemContainerStyle="{StaticResource PushpinItemStyle}"
IsSynchronizedWithCurrentItem="True"/>
<map:Pushpin Location="65,-18" Content="Iceland"/>
<map:Pushpin Location="71,25" Content="Norway"/>
<map:Pushpin Location="35,33" Content="Cyprus"/>
<map:Pushpin Location="28.25,-16.5" Content="Tenerife"/>
<Path map:MapPanel.Location="53.5,8.2" Stroke="Blue" StrokeThickness="3" Fill="#1F007F00">
<Path.Data>
<EllipseGeometry RadiusX="1852" RadiusY="1852" Transform="{Binding ScaleTransform, ElementName=map}"/>
<EllipseGeometry RadiusX="1852" RadiusY="1852" Transform="{Binding ScaleRotateTransform, ElementName=map}"/>
</Path.Data>
</Path>
<map:MapPath Stroke="Blue" Fill="Aqua" Opacity="0.5">
<map:MapPath.Data>
<GeometryGroup FillRule="EvenOdd">
<EllipseGeometry Center="8.2,63.5" RadiusX="0.025" RadiusY="0.025"/>
<EllipseGeometry Center="8.2,63.51" RadiusX="0.015" RadiusY="0.015"/>
</GeometryGroup>
</map:MapPath.Data>
</map:MapPath>
<map:Pushpin Location="53.5,8.2" Background="Yellow" Foreground="Blue" Content="N 53° 30' E 8° 12'">
<map:Pushpin Location="53.5,8.2" Background="Yellow" Foreground="Blue" Content="N 53°30' E 8°12'">
<map:Pushpin.Visibility>
<MultiBinding Converter="{StaticResource LocationToVisibilityConverter}">
<Binding Path="(map:MapPanel.ParentMap)" RelativeSource="{RelativeSource Self}"/>
@ -244,7 +177,7 @@
</map:Map>
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#7FFFFFFF">
<TextBlock Margin="2" FontSize="10" map:HyperlinkText.InlinesSource="{Binding TileLayer.Description, ElementName=map}"/>
<TextBlock Margin="2" FontSize="10" map:HyperlinkText.InlinesSource="{Binding MapLayers.CurrentMapLayer.Description}"/>
</Border>
<Grid Grid.Row="1">
@ -273,19 +206,16 @@
</StackPanel>
<CheckBox ToolTip="Seamarks Overlay" Margin="7" VerticalAlignment="Bottom" Content="Seamarks"
Checked="SeamarksChecked" Unchecked="SeamarksUnchecked"/>
<ComboBox ToolTip="Tile Layer" Margin="5" VerticalAlignment="Bottom"
SelectedValuePath="Tag" SelectedValue="{Binding TileLayer, ElementName=map, Mode=TwoWay}">
<ComboBoxItem Tag="{StaticResource OpenStreetMap}">OpenStreetMap</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource OpenCycleMap}">OpenCycleMap</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource Landscape}">Landscape</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource Outdoors}">Outdoors</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource Transport}">Transport</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource TransportDark}">Transport Dark</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource MapQuest}">MapQuest Open</ComboBoxItem>
<!--<ComboBoxItem Tag="{StaticResource WorldOsm}">World OSM WMS</ComboBoxItem>-->
<!--<ComboBoxItem Tag="{StaticResource BingRoad}">Bing Maps Road</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource BingAerial}">Bing Maps Aerial</ComboBoxItem>
<ComboBoxItem Tag="{StaticResource BingHybrid}">Bing Maps Hybrid</ComboBoxItem>-->
<ComboBox ToolTip="Map Layer" Width="200" Margin="5" VerticalAlignment="Bottom"
ItemsSource="{Binding MapLayers.MapLayerNames}"
SelectedItem="{Binding MapLayers.CurrentMapLayerName}"/>
<ComboBox x:Name="projectionComboBox" ToolTip="Map Projection" Width="120" Margin="5" VerticalAlignment="Bottom"
SelectedValuePath="Tag" SelectedIndex="0">
<ComboBoxItem Content="Web Mercator" Tag="{StaticResource WebMercatorProjection}"/>
<ComboBoxItem Content="Equirectangular" Tag="{StaticResource EquirectangularProjection}"/>
<ComboBoxItem Content="Orthographic" Tag="{StaticResource OrthographicProjection}"/>
<ComboBoxItem Content="Gnomonic" Tag="{StaticResource GnomonicProjection}"/>
<ComboBoxItem Content="Stereographic" Tag="{StaticResource StereographicProjection}"/>
</ComboBox>
</StackPanel>
</Grid>

View file

@ -3,6 +3,7 @@ using System.Globalization;
using System.Windows;
using System.Windows.Input;
using MapControl;
using ViewModel;
namespace WpfApplication
{
@ -12,7 +13,6 @@ namespace WpfApplication
{
//TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheFolder);
//BingMapsTileLayer.ApiKey = "...";
InitializeComponent();
}
@ -21,8 +21,9 @@ namespace WpfApplication
{
if (e.ClickCount == 2)
{
map.ZoomMap(e.GetPosition(map), Math.Floor(map.ZoomLevel + 1.5));
//map.TargetCenter = map.ViewportPointToLocation(e.GetPosition(map));
//map.ZoomMap(e.GetPosition(map), Math.Floor(map.ZoomLevel + 1.5));
map.TargetCenter = map.ViewportPointToLocation(e.GetPosition(map));
//map.ZoomToBounds(new BoundingBox(53, 7, 54, 9));
}
}
@ -56,8 +57,8 @@ namespace WpfApplication
mouseLocation.Text = string.Format(CultureInfo.InvariantCulture,
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
latHemisphere, latitude / 60000, (double)(latitude % 60000) / 1000d,
lonHemisphere, longitude / 60000, (double)(longitude % 60000) / 1000d);
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
}
private void MapMouseLeave(object sender, MouseEventArgs e)
@ -79,12 +80,12 @@ namespace WpfApplication
private void SeamarksChecked(object sender, RoutedEventArgs e)
{
map.TileLayers.Add((TileLayer)Resources["Seamarks"]);
map.Children.Insert(map.Children.IndexOf(mapGraticule), ((MapViewModel)DataContext).MapLayers.SeamarksLayer);
}
private void SeamarksUnchecked(object sender, RoutedEventArgs e)
{
map.TileLayers.Remove((TileLayer)Resources["Seamarks"]);
map.Children.Remove(((MapViewModel)DataContext).MapLayers.SeamarksLayer);
}
}
}

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("XAML Map Control WPF Sample Application")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.14.0")]
[assembly: AssemblyFileVersion("2.14.0")]
[assembly: AssemblyVersion("3.1.0")]
[assembly: AssemblyFileVersion("3.1.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -52,8 +52,11 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="..\Common\ViewModel.cs">
<Link>ViewModel.cs</Link>
<Compile Include="..\Common\MapLayers.cs">
<Link>MapLayers.cs</Link>
</Compile>
<Compile Include="..\Common\MapViewModel.cs">
<Link>MapViewModel.cs</Link>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>