mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Simplified sample application, set default TileLayer in Map.Loaded handler.
This commit is contained in:
parent
bb3a9cf8c3
commit
f74f4bf404
|
|
@ -108,6 +108,18 @@ namespace MapControl
|
||||||
AddVisualChild(tileContainer);
|
AddVisualChild(tileContainer);
|
||||||
TileLayers = new TileLayerCollection();
|
TileLayers = new TileLayerCollection();
|
||||||
SetValue(ParentMapProperty, this);
|
SetValue(ParentMapProperty, this);
|
||||||
|
|
||||||
|
Loaded += (o, e) =>
|
||||||
|
{
|
||||||
|
if (MainTileLayer == null)
|
||||||
|
{
|
||||||
|
MainTileLayer = new TileLayer
|
||||||
|
{
|
||||||
|
Description = "© {y} OpenStreetMap Contributors, CC-BY-SA",
|
||||||
|
TileSource = new OpenStreetMapTileSource { UriFormat = "http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png" }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,13 @@
|
||||||
Name="Seamarks" Description="© {y} OpenSeaMap Contributors, CC-BY-SA"
|
Name="Seamarks" Description="© {y} OpenSeaMap Contributors, CC-BY-SA"
|
||||||
TileSource="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
|
TileSource="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
|
||||||
IsCached="False" MinZoomLevel="10" MaxZoomLevel="18"/>
|
IsCached="False" MinZoomLevel="10" MaxZoomLevel="18"/>
|
||||||
<local:SampleItemCollection x:Key="SampleItems"/>
|
<local:SampleItemCollection x:Key="Polylines"/>
|
||||||
<local:SampleItemStyleSelector x:Key="SampleItemStyleSelector"/>
|
<local:SampleItemCollection x:Key="Points"/>
|
||||||
<Style x:Key="SamplePushpinItemStyle" TargetType="map:MapItem">
|
<local:SampleItemCollection x:Key="Pushpins"/>
|
||||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
<DataTemplate x:Key="PolylineItemTemplate">
|
||||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
<map:MapPolyline Locations="{Binding Locations}" Stroke="Red" StrokeThickness="3"/>
|
||||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
</DataTemplate>
|
||||||
<Setter Property="Content" Value="{Binding Name}"/>
|
<Style x:Key="PointItemStyle" TargetType="map:MapItem">
|
||||||
<Style.Triggers>
|
|
||||||
<Trigger Property="IsSelected" Value="True">
|
|
||||||
<Setter Property="Foreground" Value="OrangeRed"/>
|
|
||||||
</Trigger>
|
|
||||||
</Style.Triggers>
|
|
||||||
</Style>
|
|
||||||
<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="HorizontalAlignment" Value="Left"/>
|
||||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
|
|
@ -62,7 +55,7 @@
|
||||||
</Path.Data>
|
</Path.Data>
|
||||||
</Path>
|
</Path>
|
||||||
<Grid Canvas.Left="10" Canvas.Bottom="3">
|
<Grid Canvas.Left="10" Canvas.Bottom="3">
|
||||||
<Rectangle Name="labelBackground" Fill="White" Opacity="0.5"/>
|
<Rectangle Name="labelBackground" Fill="White" Opacity="0.7"/>
|
||||||
<TextBlock Margin="2,0,2,1" Text="{Binding Name}"/>
|
<TextBlock Margin="2,0,2,1" Text="{Binding Name}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
|
|
@ -70,76 +63,22 @@
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="SampleShapeItemStyle" TargetType="map:MapItem">
|
<Style x:Key="PushpinItemStyle" 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="HorizontalAlignment" Value="Left"/>
|
||||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="map:MapItem">
|
<ControlTemplate>
|
||||||
<Canvas>
|
<map:Pushpin Content="{Binding Name}"/>
|
||||||
<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"/>
|
|
||||||
</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="path" StrokeThickness="2" Fill="#50FFA500">
|
|
||||||
<Path.RenderTransform>
|
|
||||||
<RotateTransform Angle="{Binding Rotation}"/>
|
|
||||||
</Path.RenderTransform>
|
|
||||||
<Path.Stroke>
|
|
||||||
<SolidColorBrush Color="Gray"/>
|
|
||||||
</Path.Stroke>
|
|
||||||
<Path.Data>
|
|
||||||
<EllipseGeometry RadiusX="{Binding RadiusX}" RadiusY="{Binding RadiusY}"
|
|
||||||
Transform="{Binding ScaleRotateTransform, ElementName=map}"/>
|
|
||||||
</Path.Data>
|
|
||||||
</Path>
|
|
||||||
<Line Stroke="Gray" StrokeThickness="4" StrokeStartLineCap="Round" StrokeEndLineCap="Round"/>
|
|
||||||
<Grid Canvas.Left="3" Canvas.Bottom="3">
|
|
||||||
<Rectangle Name="labelBackground" Fill="White" Opacity="0.5"/>
|
|
||||||
<TextBlock Margin="2,0,2,1" Text="{Binding Name}"/>
|
|
||||||
</Grid>
|
|
||||||
</Canvas>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
<Style x:Key="SamplePolylineItemStyle" TargetType="map:MapItem">
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="map:MapItem">
|
|
||||||
<map:MapPolyline Stroke="Blue" StrokeThickness="2" Locations="{Binding Locations}"/>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
<Style x:Key="SamplePolygonItemStyle" TargetType="map:MapItem">
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="map:MapItem">
|
|
||||||
<map:MapPolygon Stroke="Green" StrokeThickness="2" Locations="{Binding Locations}"/>
|
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
<Style.Triggers>
|
||||||
|
<Trigger Property="IsSelected" Value="True">
|
||||||
|
<Setter Property="Foreground" Value="OrangeRed"/>
|
||||||
|
</Trigger>
|
||||||
|
</Style.Triggers>
|
||||||
</Style>
|
</Style>
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|
@ -154,10 +93,15 @@
|
||||||
ManipulationInertiaStarting="MapManipulationInertiaStarting"
|
ManipulationInertiaStarting="MapManipulationInertiaStarting"
|
||||||
MouseMove="MapMouseMove" MouseLeave="MapMouseLeave">
|
MouseMove="MapMouseMove" MouseLeave="MapMouseLeave">
|
||||||
<map:MapGraticule Opacity="0.6"/>
|
<map:MapGraticule Opacity="0.6"/>
|
||||||
<map:MapItemsControl ItemsSource="{StaticResource SampleItems}"
|
<map:MapItemsControl ItemsSource="{StaticResource Polylines}"
|
||||||
ItemContainerStyleSelector="{StaticResource SampleItemStyleSelector}"
|
ItemTemplate="{StaticResource PolylineItemTemplate}"/>
|
||||||
|
<map:MapItemsControl ItemsSource="{StaticResource Points}"
|
||||||
|
ItemContainerStyle="{StaticResource PointItemStyle}"
|
||||||
IsSynchronizedWithCurrentItem="True"/>
|
IsSynchronizedWithCurrentItem="True"/>
|
||||||
<map:Pushpin Location="53.5,8.25" Content="N 53° 30' E 8° 15'"/>
|
<map:MapItemsControl ItemsSource="{StaticResource Pushpins}"
|
||||||
|
ItemContainerStyle="{StaticResource PushpinItemStyle}"
|
||||||
|
IsSynchronizedWithCurrentItem="True"/>
|
||||||
|
<map:Pushpin Location="53.5,8.2" Background="Yellow" Foreground="Blue">N 53° 30' E 8° 12'</map:Pushpin>
|
||||||
<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>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
@ -14,87 +15,80 @@ namespace MapControlTestApp
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
SampleItemCollection items = (SampleItemCollection)Resources["SampleItems"];
|
ICollection<object> polylines = (ICollection<object>)Resources["Polylines"];
|
||||||
items.Add(
|
polylines.Add(
|
||||||
new SamplePolyline
|
new SamplePolyline
|
||||||
{
|
{
|
||||||
Name = "WHV - Eckwarderhörne",
|
|
||||||
Locations = LocationCollection.Parse("53.5140,8.1451 53.5123,8.1506 53.5156,8.1623 53.5276,8.1757 53.5491,8.1852 53.5495,8.1877 53.5426,8.1993 53.5184,8.2219 53.5182,8.2386 53.5195,8.2387")
|
Locations = LocationCollection.Parse("53.5140,8.1451 53.5123,8.1506 53.5156,8.1623 53.5276,8.1757 53.5491,8.1852 53.5495,8.1877 53.5426,8.1993 53.5184,8.2219 53.5182,8.2386 53.5195,8.2387")
|
||||||
});
|
});
|
||||||
items.Add(
|
polylines.Add(
|
||||||
new SamplePolygon
|
new SamplePolyline
|
||||||
{
|
{
|
||||||
Name = "JadeWeserPort",
|
Locations = LocationCollection.Parse("53.5978,8.1212 53.6018,8.1494 53.5859,8.1554 53.5852,8.1531 53.5841,8.1539 53.5802,8.1392 53.5826,8.1309 53.5867,8.1317 53.5978,8.1212")
|
||||||
Locations = LocationCollection.Parse("53.5978,8.1212 53.6018,8.1494 53.5859,8.1554 53.5852,8.1531 53.5841,8.1539 53.5802,8.1392 53.5826,8.1309 53.5867,8.1317")
|
|
||||||
});
|
});
|
||||||
items.Add(
|
|
||||||
new SamplePushpin
|
ICollection<object> points = (ICollection<object>)Resources["Points"];
|
||||||
{
|
points.Add(
|
||||||
Name = "WHV - Eckwarderhörne",
|
|
||||||
Location = new Location(53.5495, 8.1877)
|
|
||||||
});
|
|
||||||
items.Add(
|
|
||||||
new SamplePushpin
|
|
||||||
{
|
|
||||||
Name = "JadeWeserPort",
|
|
||||||
Location = new Location(53.5914, 8.14)
|
|
||||||
});
|
|
||||||
items.Add(
|
|
||||||
new SamplePushpin
|
|
||||||
{
|
|
||||||
Name = "Kurhaus Dangast",
|
|
||||||
Location = new Location(53.447, 8.1114)
|
|
||||||
});
|
|
||||||
items.Add(
|
|
||||||
new SamplePushpin
|
|
||||||
{
|
|
||||||
Name = "Eckwarderhörne",
|
|
||||||
Location = new Location(53.5207, 8.2323)
|
|
||||||
});
|
|
||||||
items.Add(
|
|
||||||
new SamplePoint
|
new SamplePoint
|
||||||
{
|
{
|
||||||
Name = "Steinbake Leitdamm",
|
Name = "Steinbake Leitdamm",
|
||||||
Location = new Location(53.51217, 8.16603)
|
Location = new Location(53.51217, 8.16603)
|
||||||
});
|
});
|
||||||
items.Add(
|
points.Add(
|
||||||
new SamplePoint
|
new SamplePoint
|
||||||
{
|
{
|
||||||
Name = "Buhne 2",
|
Name = "Buhne 2",
|
||||||
Location = new Location(53.50926, 8.15815)
|
Location = new Location(53.50926, 8.15815)
|
||||||
});
|
});
|
||||||
items.Add(
|
points.Add(
|
||||||
new SamplePoint
|
new SamplePoint
|
||||||
{
|
{
|
||||||
Name = "Buhne 4",
|
Name = "Buhne 4",
|
||||||
Location = new Location(53.50468, 8.15343)
|
Location = new Location(53.50468, 8.15343)
|
||||||
});
|
});
|
||||||
items.Add(
|
points.Add(
|
||||||
new SamplePoint
|
new SamplePoint
|
||||||
{
|
{
|
||||||
Name = "Buhne 6",
|
Name = "Buhne 6",
|
||||||
Location = new Location(53.50092, 8.15267)
|
Location = new Location(53.50092, 8.15267)
|
||||||
});
|
});
|
||||||
items.Add(
|
points.Add(
|
||||||
new SamplePoint
|
new SamplePoint
|
||||||
{
|
{
|
||||||
Name = "Buhne 8",
|
Name = "Buhne 8",
|
||||||
Location = new Location(53.49871, 8.15321)
|
Location = new Location(53.49871, 8.15321)
|
||||||
});
|
});
|
||||||
items.Add(
|
points.Add(
|
||||||
new SamplePoint
|
new SamplePoint
|
||||||
{
|
{
|
||||||
Name = "Buhne 10",
|
Name = "Buhne 10",
|
||||||
Location = new Location(53.49350, 8.15563)
|
Location = new Location(53.49350, 8.15563)
|
||||||
});
|
});
|
||||||
items.Add(
|
|
||||||
new SampleShape
|
ICollection<object> pushpins = (ICollection<object>)Resources["Pushpins"];
|
||||||
|
pushpins.Add(
|
||||||
|
new SamplePoint
|
||||||
{
|
{
|
||||||
Name = "N 53° 30' E 8° 12'",
|
Name = "WHV - Eckwarderhörne",
|
||||||
Location = new Location(53.5, 8.2),
|
Location = new Location(53.5495, 8.1877)
|
||||||
RadiusX = 200d, // meters
|
});
|
||||||
RadiusY = 300d, // meters
|
pushpins.Add(
|
||||||
Rotation = 30d
|
new SamplePoint
|
||||||
|
{
|
||||||
|
Name = "JadeWeserPort",
|
||||||
|
Location = new Location(53.5914, 8.14)
|
||||||
|
});
|
||||||
|
pushpins.Add(
|
||||||
|
new SamplePoint
|
||||||
|
{
|
||||||
|
Name = "Kurhaus Dangast",
|
||||||
|
Location = new Location(53.447, 8.1114)
|
||||||
|
});
|
||||||
|
pushpins.Add(
|
||||||
|
new SamplePoint
|
||||||
|
{
|
||||||
|
Name = "Eckwarderhörne",
|
||||||
|
Location = new Location(53.5207, 8.2323)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,20 @@
|
||||||
using System;
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using MapControl;
|
using MapControl;
|
||||||
|
|
||||||
namespace MapControlTestApp
|
namespace MapControlTestApp
|
||||||
{
|
{
|
||||||
class SampleItem
|
class SamplePoint
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
|
||||||
|
|
||||||
class SamplePoint : SampleItem
|
|
||||||
{
|
|
||||||
public Location Location { get; set; }
|
public Location Location { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class SamplePushpin : SamplePoint
|
class SamplePolyline
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class SampleShape : SamplePoint
|
|
||||||
{
|
|
||||||
public double RadiusX { get; set; }
|
|
||||||
public double RadiusY { get; set; }
|
|
||||||
public double Rotation { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
class SamplePolyline : SampleItem
|
|
||||||
{
|
{
|
||||||
public LocationCollection Locations { get; set; }
|
public LocationCollection Locations { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class SamplePolygon : SampleItem
|
class SampleItemCollection : ObservableCollection<object>
|
||||||
{
|
|
||||||
public LocationCollection Locations { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
class SampleItemCollection : ObservableCollection<SampleItem>
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class SampleItemStyleSelector : StyleSelector
|
|
||||||
{
|
|
||||||
public override Style SelectStyle(object item, DependencyObject container)
|
|
||||||
{
|
|
||||||
if (item is SamplePolyline)
|
|
||||||
{
|
|
||||||
return Application.Current.Windows[0].Resources["SamplePolylineItemStyle"] as Style;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item is SamplePolygon)
|
|
||||||
{
|
|
||||||
return Application.Current.Windows[0].Resources["SamplePolygonItemStyle"] as Style;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item is SampleShape)
|
|
||||||
{
|
|
||||||
return Application.Current.Windows[0].Resources["SampleShapeItemStyle"] as Style;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item is SamplePushpin)
|
|
||||||
{
|
|
||||||
return Application.Current.Windows[0].Resources["SamplePushpinItemStyle"] as Style;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Application.Current.Windows[0].Resources["SamplePointItemStyle"] as Style;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue