XAML-Map-Control/SampleApps/WpfApplication/MainWindow.xaml

207 lines
13 KiB
Plaintext
Raw Normal View History

<Window x:Class="WpfApplication.MainWindow"
2012-05-04 12:52:20 +02:00
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"
xmlns:local="clr-namespace:WpfApplication"
Title="XAML MapControl - WPF Test Application" Height="600" Width="800">
2012-05-04 12:52:20 +02:00
<Window.Resources>
<map:TileLayerCollection x:Key="TileLayers">
<map:TileLayer SourceName="OpenStreetMap" Description="© {y} OpenStreetMap Contributors, CC-BY-SA"
TileSource="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"/>
<map:TileLayer SourceName="OpenCycleMap" Description="OpenCycleMap - © {y} Andy Allen &amp; OpenStreetMap Contributors, CC-BY-SA"
TileSource="http://{c}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png"/>
<map:TileLayer SourceName="OCM Transport" Description="OpenCycleMap Transport - © {y} Andy Allen &amp; OpenStreetMap Contributors, CC-BY-SA"
TileSource="http://{c}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png"/>
<map:TileLayer SourceName="OCM Landscape" Description="OpenCycleMap Landscape - © {y} Andy Allen &amp; OpenStreetMap Contributors, CC-BY-SA"
TileSource="http://{c}.tile3.opencyclemap.org/landscape/{z}/{x}/{y}.png"/>
<map:TileLayer SourceName="MapQuest OSM" Description="MapQuest OSM - © {y} MapQuest &amp; OpenStreetMap Contributors"
TileSource="http://otile{n}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png"/>
<!-- Note: The providers of the below TileLayers do not allow access to their
map content without using their APIs (i.e. Google Maps API or Bing Maps API).
Hence the declarations below are for demonstration purpose only. -->
<!--<map:TileLayer SourceName="Google Maps" Description="Google Maps - © {y} Google"
TileSource="http://mt{i}.google.com/vt/x={x}&amp;y={y}&amp;z={z}" MaxZoomLevel="20"/>
<map:TileLayer SourceName="Google Images" Description="Google Maps - © {y} Google"
TileSource="http://khm{i}.google.com/kh/v=119&amp;x={x}&amp;y={y}&amp;z={z}" MaxZoomLevel="20" HasDarkBackground="True"/>
<map:TileLayer SourceName="Bing Maps" Description="Bing Maps - © {y} Microsoft Corporation"
TileSource="http://ecn.t{i}.tiles.virtualearth.net/tiles/r{q}.png?g=0&amp;stl=h" MaxZoomLevel="20"/>
<map:TileLayer SourceName="Bing Images" Description="Bing Maps - © {y} Microsoft Corporation"
TileSource="http://ecn.t{i}.tiles.virtualearth.net/tiles/a{q}.jpeg?g=0" MaxZoomLevel="20" HasDarkBackground="True"/>
<map:TileLayer SourceName="Bing Hybrid" Description="Bing Maps - © {y} Microsoft Corporation"
TileSource="http://ecn.t{i}.tiles.virtualearth.net/tiles/h{q}.jpeg?g=0&amp;stl=h" MaxZoomLevel="20" HasDarkBackground="True"/>-->
<!-- The TileLayer below uses an ImageTileSource, which bypasses caching of map tile images -->
<!--<map:TileLayer SourceName="OSM Uncached" Description="© {y} OpenStreetMap Contributors, CC-BY-SA">
<map:TileLayer.TileSource>
<map:ImageTileSource UriFormat="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"/>
</map:TileLayer.TileSource>
</map:TileLayer>-->
</map:TileLayerCollection>
<CollectionViewSource x:Key="TileLayersView" Source="{StaticResource TileLayers}"/>
<local:LocationToVisibilityConverter x:Key="LocationToVisibilityConverter"/>
<map:TileLayer x:Key="SeamarksTileLayer" SourceName="Seamarks" Description="© {y} OpenSeaMap Contributors, CC-BY-SA"
TileSource="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png" MinZoomLevel="10" MaxZoomLevel="18"/>
<DataTemplate x:Key="PolylineItemTemplate">
<map:MapPolyline Locations="{Binding Locations}" Stroke="Red" StrokeThickness="3"/>
</DataTemplate>
<Style x:Key="PolylineItemStyle" TargetType="map:MapItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="map:MapItem">
<map:MapPolyline Locations="{Binding Locations}" Stroke="Red" StrokeThickness="3"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="PointItemStyle" TargetType="map:MapItem">
2012-05-04 12:52:20 +02:00
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
2012-05-04 12:52:20 +02:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="map:MapItem">
<Canvas>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="labelBackground" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.1"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.7" Duration="0:0:0.1"/>
</Storyboard>
</VisualState>
2012-05-04 12:52:20 +02:00
</VisualStateGroup>
<VisualStateGroup x:Name="CurrentStates">
<VisualState x:Name="NotCurrent"/>
<VisualState x:Name="Current">
<Storyboard>
<ColorAnimation Storyboard.TargetName="path" Storyboard.TargetProperty="Stroke.Color" To="Magenta" Duration="0:0:0.1"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Path Name="selectedPath" Fill="White" Opacity="0">
<Path.Data>
<EllipseGeometry RadiusX="15" RadiusY="15"/>
</Path.Data>
</Path>
2012-05-04 12:52:20 +02:00
<Path Name="path" StrokeThickness="2" Fill="Transparent">
<Path.Stroke>
<SolidColorBrush Color="Gray"/>
</Path.Stroke>
<Path.Data>
<EllipseGeometry RadiusX="8" RadiusY="8"/>
</Path.Data>
</Path>
<Grid Canvas.Left="15" Canvas.Top="-8">
<Rectangle Name="labelBackground" Fill="White" Opacity="0.7"/>
<TextBlock Margin="2,0,2,0" Text="{Binding Name}"/>
2012-05-04 12:52:20 +02:00
</Grid>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="PushpinItemStyle" TargetType="map:MapItem">
2012-05-04 12:52:20 +02:00
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource LocationToVisibilityConverter}">
<Binding Path="(map:MapPanel.ParentMap)" RelativeSource="{RelativeSource Self}"/>
<Binding Path="RenderTransform" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
2012-05-04 12:52:20 +02:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<map:Pushpin Content="{Binding Name}"/>
2012-05-04 12:52:20 +02:00
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="OrangeRed"/>
</Trigger>
</Style.Triggers>
2012-05-04 12:52:20 +02:00
</Style>
<local:SampleItemCollection x:Key="Polylines"/>
<local:SampleItemCollection x:Key="Points"/>
<local:SampleItemCollection x:Key="Pushpins"/>
2012-05-04 12:52:20 +02:00
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<map:Map Name="map" IsManipulationEnabled="True" Margin="2"
2012-05-04 12:52:20 +02:00
LightForeground="Black" LightBackground="White" DarkForeground="White" DarkBackground="#FF3F3F3F"
Center="53.5,8.2" ZoomLevel="11"
TileLayer="{Binding Source={StaticResource TileLayersView}, Path=CurrentItem}"
MouseLeftButtonDown="MapMouseLeftButtonDown" MouseRightButtonDown="MapMouseRightButtonDown"
MouseMove="MapMouseMove" MouseLeave="MapMouseLeave"
ManipulationInertiaStarting="MapManipulationInertiaStarting">
2012-05-04 12:52:20 +02:00
<map:MapGraticule Opacity="0.6"/>
2012-10-25 08:42:51 +02:00
<map:MapScale Margin="4" Opacity="0.8"/>
<!-- use ItemTemplate or ItemContainerStyle alternatively -->
<map:MapItemsControl ItemsSource="{StaticResource Polylines}"
ItemTemplate="{StaticResource PolylineItemTemplate}"/>
<!--<map:MapItemsControl ItemsSource="{StaticResource Polylines}"
ItemContainerStyle="{StaticResource PolylineItemStyle}"/>-->
<map:MapItemsControl ItemsSource="{StaticResource Points}"
ItemContainerStyle="{StaticResource PointItemStyle}"
IsSynchronizedWithCurrentItem="True"
SelectionMode="Extended"/>
<map:MapItemsControl ItemsSource="{StaticResource Pushpins}"
ItemContainerStyle="{StaticResource PushpinItemStyle}"
2012-05-04 12:52:20 +02:00
IsSynchronizedWithCurrentItem="True"/>
<map:Pushpin map:MapPanel.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}"/>
<Binding Path="RenderTransform" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</map:Pushpin.Visibility>
</map:Pushpin>
2012-10-25 08:42:51 +02:00
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="4" FontSize="10"
Text="{Binding TileLayer.Description, ElementName=map}"/>
2012-05-04 12:52:20 +02:00
</map:Map>
<Grid Grid.Row="1">
2012-05-04 12:52:20 +02:00
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Name="mouseLocation" Margin="4" VerticalAlignment="Center"/>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Slider ToolTip="Zoom Level" Margin="4" Width="100" SmallChange="0.01"
Minimum="{Binding MinZoomLevel, ElementName=map}"
Maximum="{Binding MaxZoomLevel, ElementName=map}"
Value="{Binding TargetZoomLevel, ElementName=map}"/>
<Slider ToolTip="Heading" Margin="4" Width="100" Minimum="0" Maximum="360" SmallChange="5" LargeChange="45"
2012-08-08 20:42:06 +02:00
Value="{Binding TargetHeading, ElementName=map}"/>
<CheckBox ToolTip="Map Overlay" Margin="4" VerticalAlignment="Center" Content="Seamarks" Click="SeamarksClick"/>
<ComboBox ToolTip="Main Tile Layer" Margin="4" DisplayMemberPath="SourceName" SelectedIndex="0"
ItemsSource="{Binding Source={StaticResource TileLayersView}}"/>
2012-05-04 12:52:20 +02:00
</StackPanel>
</Grid>
</Grid>
</Window>