mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Changed map tile download order, added Pushpin class, changed default MapItem style.
This commit is contained in:
parent
a0e0403c90
commit
bb3a9cf8c3
|
|
@ -42,7 +42,8 @@ namespace MapControl
|
||||||
|
|
||||||
public static readonly DependencyProperty TileLayersProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty TileLayersProperty = DependencyProperty.Register(
|
||||||
"TileLayers", typeof(TileLayerCollection), typeof(Map), new FrameworkPropertyMetadata(
|
"TileLayers", typeof(TileLayerCollection), typeof(Map), new FrameworkPropertyMetadata(
|
||||||
(o, e) => ((Map)o).TileLayersPropertyChanged((TileLayerCollection)e.NewValue)));
|
(o, e) => ((Map)o).TileLayersPropertyChanged((TileLayerCollection)e.NewValue),
|
||||||
|
(o, v) => ((Map)o).CoerceTileLayersProperty((TileLayerCollection)v)));
|
||||||
|
|
||||||
public static readonly DependencyProperty MainTileLayerProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty MainTileLayerProperty = DependencyProperty.Register(
|
||||||
"MainTileLayer", typeof(TileLayer), typeof(Map), new FrameworkPropertyMetadata(
|
"MainTileLayer", typeof(TileLayer), typeof(Map), new FrameworkPropertyMetadata(
|
||||||
|
|
@ -105,6 +106,7 @@ namespace MapControl
|
||||||
MinZoomLevel = 1;
|
MinZoomLevel = 1;
|
||||||
MaxZoomLevel = 20;
|
MaxZoomLevel = 20;
|
||||||
AddVisualChild(tileContainer);
|
AddVisualChild(tileContainer);
|
||||||
|
TileLayers = new TileLayerCollection();
|
||||||
SetValue(ParentMapProperty, this);
|
SetValue(ParentMapProperty, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -483,19 +485,28 @@ namespace MapControl
|
||||||
|
|
||||||
private void TileLayersPropertyChanged(TileLayerCollection tileLayers)
|
private void TileLayersPropertyChanged(TileLayerCollection tileLayers)
|
||||||
{
|
{
|
||||||
tileContainer.TileLayers = tileLayers;
|
if (tileLayers != null)
|
||||||
MainTileLayer = tileLayers.Count > 0 ? tileLayers[0] : null;
|
{
|
||||||
|
tileContainer.TileLayers = tileLayers;
|
||||||
|
MainTileLayer = tileLayers.Count > 0 ? tileLayers[0] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TileLayerCollection CoerceTileLayersProperty(TileLayerCollection tileLayers)
|
||||||
|
{
|
||||||
|
if (tileLayers == null)
|
||||||
|
{
|
||||||
|
tileLayers = new TileLayerCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return tileLayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainTileLayerPropertyChanged(TileLayer mainTileLayer)
|
private void MainTileLayerPropertyChanged(TileLayer mainTileLayer)
|
||||||
{
|
{
|
||||||
if (mainTileLayer != null)
|
if (mainTileLayer != null)
|
||||||
{
|
{
|
||||||
if (tileContainer.TileLayers == null)
|
if (tileContainer.TileLayers.Count == 0)
|
||||||
{
|
|
||||||
TileLayers = new TileLayerCollection(mainTileLayer);
|
|
||||||
}
|
|
||||||
else if (tileContainer.TileLayers.Count == 0)
|
|
||||||
{
|
{
|
||||||
tileContainer.TileLayers.Add(mainTileLayer);
|
tileContainer.TileLayers.Add(mainTileLayer);
|
||||||
}
|
}
|
||||||
|
|
@ -508,7 +519,7 @@ namespace MapControl
|
||||||
|
|
||||||
private TileLayer CoerceMainTileLayerProperty(TileLayer mainTileLayer)
|
private TileLayer CoerceMainTileLayerProperty(TileLayer mainTileLayer)
|
||||||
{
|
{
|
||||||
if (mainTileLayer == null && tileContainer.TileLayers != null && tileContainer.TileLayers.Count > 0)
|
if (mainTileLayer == null && tileContainer.TileLayers.Count > 0)
|
||||||
{
|
{
|
||||||
mainTileLayer = tileContainer.TileLayers[0];
|
mainTileLayer = tileContainer.TileLayers[0];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@
|
||||||
<Compile Include="MapPanel.cs" />
|
<Compile Include="MapPanel.cs" />
|
||||||
<Compile Include="MapPolygon.cs" />
|
<Compile Include="MapPolygon.cs" />
|
||||||
<Compile Include="MapPolyline.cs" />
|
<Compile Include="MapPolyline.cs" />
|
||||||
|
<Compile Include="Pushpin.cs" />
|
||||||
<Compile Include="TileImageLoader.cs" />
|
<Compile Include="TileImageLoader.cs" />
|
||||||
<Compile Include="MapTransform.cs" />
|
<Compile Include="MapTransform.cs" />
|
||||||
<Compile Include="Map.cs" />
|
<Compile Include="Map.cs" />
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,11 @@ namespace MapControl
|
||||||
|
|
||||||
static MapItem()
|
static MapItem()
|
||||||
{
|
{
|
||||||
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem),
|
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
|
||||||
new FrameworkPropertyMetadata(typeof(MapItem)));
|
typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem)));
|
||||||
|
|
||||||
UIElement.IsEnabledProperty.OverrideMetadata(typeof(MapItem),
|
UIElement.IsEnabledProperty.OverrideMetadata(
|
||||||
new FrameworkPropertyMetadata((o, e) => ((MapItem)o).CommonStateChanged()));
|
typeof(MapItem), new FrameworkPropertyMetadata((o, e) => ((MapItem)o).CommonStateChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public event RoutedEventHandler Selected
|
public event RoutedEventHandler Selected
|
||||||
|
|
|
||||||
29
MapControl/Pushpin.cs
Normal file
29
MapControl/Pushpin.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
namespace MapControl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a pushpin at the geographic location provided by the Location property.
|
||||||
|
/// </summary>
|
||||||
|
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
|
||||||
|
[TemplateVisualState(Name = "MouseOver", GroupName = "CommonStates")]
|
||||||
|
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
|
||||||
|
public class Pushpin : ContentControl
|
||||||
|
{
|
||||||
|
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(Pushpin));
|
||||||
|
|
||||||
|
static Pushpin()
|
||||||
|
{
|
||||||
|
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
|
||||||
|
typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location Location
|
||||||
|
{
|
||||||
|
get { return (Location)GetValue(LocationProperty); }
|
||||||
|
set { SetValue(LocationProperty, value); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,20 @@
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="{x:Type map:MapItem}" TargetType="{x:Type map:MapItem}">
|
<Style x:Key="{x:Type map:MapItem}" TargetType="{x:Type map:MapItem}">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="{x:Type map:MapItem}">
|
||||||
|
<ContentPresenter Content="{TemplateBinding Content}"
|
||||||
|
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||||
|
Cursor="{TemplateBinding Cursor}"
|
||||||
|
Margin="{TemplateBinding Padding}"
|
||||||
|
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||||
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
<Style x:Key="{x:Type map:Pushpin}" TargetType="{x:Type map:Pushpin}">
|
||||||
<Setter Property="SnapsToDevicePixels" Value="True"/>
|
<Setter Property="SnapsToDevicePixels" Value="True"/>
|
||||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
|
|
@ -18,7 +32,7 @@
|
||||||
<Setter Property="Background" Value="White"/>
|
<Setter Property="Background" Value="White"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="{x:Type map:MapItem}">
|
<ControlTemplate TargetType="{x:Type map:Pushpin}">
|
||||||
<Grid>
|
<Grid>
|
||||||
<VisualStateManager.VisualStateGroups>
|
<VisualStateManager.VisualStateGroups>
|
||||||
<VisualStateGroup x:Name="CommonStates">
|
<VisualStateGroup x:Name="CommonStates">
|
||||||
|
|
@ -34,14 +48,6 @@
|
||||||
</Storyboard>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
<VisualStateGroup x:Name="SelectionStates">
|
|
||||||
<VisualState x:Name="Unselected"/>
|
|
||||||
<VisualState x:Name="Selected"/>
|
|
||||||
</VisualStateGroup>
|
|
||||||
<VisualStateGroup x:Name="CurrentStates">
|
|
||||||
<VisualState x:Name="NonCurrent"/>
|
|
||||||
<VisualState x:Name="Current"/>
|
|
||||||
</VisualStateGroup>
|
|
||||||
</VisualStateManager.VisualStateGroups>
|
</VisualStateManager.VisualStateGroups>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Markup;
|
using System.Windows.Markup;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,6 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
private string name;
|
private string name;
|
||||||
|
|
||||||
public TileLayerCollection()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileLayerCollection(TileLayer tileLayer)
|
|
||||||
{
|
|
||||||
Add(tileLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get { return !string.IsNullOrEmpty(name) ? name : (Count > 0 ? this[0].Name : string.Empty); }
|
get { return !string.IsNullOrEmpty(name) ? name : (Count > 0 ? this[0].Name : string.Empty); }
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
<local:SampleItemStyleSelector x:Key="SampleItemStyleSelector"/>
|
<local:SampleItemStyleSelector x:Key="SampleItemStyleSelector"/>
|
||||||
<Style x:Key="SamplePushpinItemStyle" TargetType="map:MapItem">
|
<Style x:Key="SamplePushpinItemStyle" TargetType="map:MapItem">
|
||||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
||||||
|
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||||
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
<Setter Property="Content" Value="{Binding Name}"/>
|
<Setter Property="Content" Value="{Binding Name}"/>
|
||||||
<Style.Triggers>
|
<Style.Triggers>
|
||||||
<Trigger Property="IsSelected" Value="True">
|
<Trigger Property="IsSelected" Value="True">
|
||||||
|
|
@ -22,6 +24,8 @@
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="SamplePointItemStyle" TargetType="map:MapItem">
|
<Style x:Key="SamplePointItemStyle" TargetType="map:MapItem">
|
||||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
||||||
|
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||||
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="map:MapItem">
|
<ControlTemplate TargetType="map:MapItem">
|
||||||
|
|
@ -68,6 +72,8 @@
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="SampleShapeItemStyle" TargetType="map:MapItem">
|
<Style x:Key="SampleShapeItemStyle" TargetType="map:MapItem">
|
||||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
||||||
|
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||||
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="map:MapItem">
|
<ControlTemplate TargetType="map:MapItem">
|
||||||
|
|
@ -118,8 +124,6 @@
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="SamplePolylineItemStyle" TargetType="map:MapItem">
|
<Style x:Key="SamplePolylineItemStyle" TargetType="map:MapItem">
|
||||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
|
||||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="map:MapItem">
|
<ControlTemplate TargetType="map:MapItem">
|
||||||
|
|
@ -129,8 +133,6 @@
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="SamplePolygonItemStyle" TargetType="map:MapItem">
|
<Style x:Key="SamplePolygonItemStyle" TargetType="map:MapItem">
|
||||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
|
||||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="map:MapItem">
|
<ControlTemplate TargetType="map:MapItem">
|
||||||
|
|
@ -155,6 +157,7 @@
|
||||||
<map:MapItemsControl ItemsSource="{StaticResource SampleItems}"
|
<map:MapItemsControl ItemsSource="{StaticResource SampleItems}"
|
||||||
ItemContainerStyleSelector="{StaticResource SampleItemStyleSelector}"
|
ItemContainerStyleSelector="{StaticResource SampleItemStyleSelector}"
|
||||||
IsSynchronizedWithCurrentItem="True"/>
|
IsSynchronizedWithCurrentItem="True"/>
|
||||||
|
<map:Pushpin Location="53.5,8.25" Content="N 53° 30' E 8° 15'"/>
|
||||||
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="2,0,0,0" FontSize="10"
|
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="2,0,0,0" FontSize="10"
|
||||||
Text="{Binding ElementName=map, Path=MainTileLayer.Description}"/>
|
Text="{Binding ElementName=map, Path=MainTileLayer.Description}"/>
|
||||||
</map:Map>
|
</map:Map>
|
||||||
|
|
@ -186,12 +189,12 @@
|
||||||
IsCached="False"/>
|
IsCached="False"/>
|
||||||
<map:TileLayer Name="MapQuest OSM" Description="MapQuest OSM - © {y} MapQuest & OpenStreetMap Contributors"
|
<map:TileLayer Name="MapQuest OSM" Description="MapQuest OSM - © {y} MapQuest & OpenStreetMap Contributors"
|
||||||
TileSource="http://otile{n}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png"
|
TileSource="http://otile{n}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png"
|
||||||
IsCached="False" MaxZoomLevel="20"/>
|
IsCached="False"/>
|
||||||
<!--<map:TileLayer Name="Google Maps" Description="Google Maps - © {y} Google"
|
<!--<map:TileLayer Name="Google Maps" Description="Google Maps - © {y} Google"
|
||||||
TileSource="http://mt{i}.google.com/vt/x={x}&y={y}&z={z}"
|
TileSource="http://mt{i}.google.com/vt/x={x}&y={y}&z={z}"
|
||||||
IsCached="False" MaxZoomLevel="20"/>
|
IsCached="False" MaxZoomLevel="20"/>
|
||||||
<map:TileLayer Name="Google Images" Description="Google Maps - © {y} Google"
|
<map:TileLayer Name="Google Images" Description="Google Maps - © {y} Google"
|
||||||
TileSource="http://khm{i}.google.com/kh/v=108&x={x}&y={y}&z={z}"
|
TileSource="http://khm{i}.google.com/kh/v=113&x={x}&y={y}&z={z}"
|
||||||
IsCached="False" MaxZoomLevel="20" HasDarkBackground="True"/>
|
IsCached="False" MaxZoomLevel="20" HasDarkBackground="True"/>
|
||||||
<map:TileLayer Name="Bing Maps" Description="Bing Maps - © {y} Microsoft Corporation"
|
<map:TileLayer Name="Bing Maps" Description="Bing Maps - © {y} Microsoft Corporation"
|
||||||
TileSource="http://ecn.t{i}.tiles.virtualearth.net/tiles/r{q}.png?g=0&stl=h"
|
TileSource="http://ecn.t{i}.tiles.virtualearth.net/tiles/r{q}.png?g=0&stl=h"
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ namespace MapControlTestApp
|
||||||
items.Add(
|
items.Add(
|
||||||
new SampleShape
|
new SampleShape
|
||||||
{
|
{
|
||||||
Name = "N 53°30' E 8°12'",
|
Name = "N 53° 30' E 8° 12'",
|
||||||
Location = new Location(53.5, 8.2),
|
Location = new Location(53.5, 8.2),
|
||||||
RadiusX = 200d, // meters
|
RadiusX = 200d, // meters
|
||||||
RadiusY = 300d, // meters
|
RadiusY = 300d, // meters
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue