Changed map tile download order, added Pushpin class, changed default MapItem style.

This commit is contained in:
ClemensF 2012-06-13 17:33:23 +02:00
parent a0e0403c90
commit bb3a9cf8c3
9 changed files with 79 additions and 39 deletions

View file

@ -42,7 +42,8 @@ namespace MapControl
public static readonly DependencyProperty TileLayersProperty = DependencyProperty.Register(
"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(
"MainTileLayer", typeof(TileLayer), typeof(Map), new FrameworkPropertyMetadata(
@ -105,6 +106,7 @@ namespace MapControl
MinZoomLevel = 1;
MaxZoomLevel = 20;
AddVisualChild(tileContainer);
TileLayers = new TileLayerCollection();
SetValue(ParentMapProperty, this);
}
@ -483,19 +485,28 @@ namespace MapControl
private void TileLayersPropertyChanged(TileLayerCollection tileLayers)
{
tileContainer.TileLayers = tileLayers;
MainTileLayer = tileLayers.Count > 0 ? tileLayers[0] : null;
if (tileLayers != 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)
{
if (mainTileLayer != null)
{
if (tileContainer.TileLayers == null)
{
TileLayers = new TileLayerCollection(mainTileLayer);
}
else if (tileContainer.TileLayers.Count == 0)
if (tileContainer.TileLayers.Count == 0)
{
tileContainer.TileLayers.Add(mainTileLayer);
}
@ -508,7 +519,7 @@ namespace MapControl
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];
}

View file

@ -53,6 +53,7 @@
<Compile Include="MapPanel.cs" />
<Compile Include="MapPolygon.cs" />
<Compile Include="MapPolyline.cs" />
<Compile Include="Pushpin.cs" />
<Compile Include="TileImageLoader.cs" />
<Compile Include="MapTransform.cs" />
<Compile Include="Map.cs" />

View file

@ -36,11 +36,11 @@ namespace MapControl
static MapItem()
{
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem),
new FrameworkPropertyMetadata(typeof(MapItem)));
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem)));
UIElement.IsEnabledProperty.OverrideMetadata(typeof(MapItem),
new FrameworkPropertyMetadata((o, e) => ((MapItem)o).CommonStateChanged()));
UIElement.IsEnabledProperty.OverrideMetadata(
typeof(MapItem), new FrameworkPropertyMetadata((o, e) => ((MapItem)o).CommonStateChanged()));
}
public event RoutedEventHandler Selected

29
MapControl/Pushpin.cs Normal file
View 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); }
}
}
}

View file

@ -11,6 +11,20 @@
</Setter>
</Style>
<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="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
@ -18,7 +32,7 @@
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type map:MapItem}">
<ControlTemplate TargetType="{x:Type map:Pushpin}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
@ -34,14 +48,6 @@
</Storyboard>
</VisualState>
</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>
<Grid.RowDefinitions>
<RowDefinition/>

View file

@ -8,7 +8,6 @@ using System.Linq;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace MapControl
{

View file

@ -12,15 +12,6 @@ namespace MapControl
{
private string name;
public TileLayerCollection()
{
}
public TileLayerCollection(TileLayer tileLayer)
{
Add(tileLayer);
}
public string Name
{
get { return !string.IsNullOrEmpty(name) ? name : (Count > 0 ? this[0].Name : string.Empty); }