Improved MapPanel.ViewportPosition, added moving item to sample application.

This commit is contained in:
ClemensF 2012-08-09 23:41:47 +02:00
parent ac107641d2
commit 022e246ebe
8 changed files with 141 additions and 51 deletions

View file

@ -65,7 +65,7 @@
</Style>
<Style x:Key="PushpinItemStyle" TargetType="map:MapItem">
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
<Setter Property="Visibility" Value="{Binding (map:MapPanel.IsInsideMapBounds), Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
<Setter Property="Visibility" Value="{Binding (map:MapPanel.ViewportPosition).IsInside, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Template">
@ -103,7 +103,7 @@
ItemContainerStyle="{StaticResource PushpinItemStyle}"
IsSynchronizedWithCurrentItem="True"/>
<map:Pushpin Location="53.5,8.2" Background="Yellow" Foreground="Blue" Content="N 53° 30' E 8° 12'"
Visibility="{Binding (map:MapPanel.IsInsideMapBounds), Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
Visibility="{Binding (map:MapPanel.ViewportPosition).IsInside, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="2,0,0,0" FontSize="10"
Text="{Binding MainTileLayer.Description, ElementName=map}"/>
</map:Map>
@ -119,7 +119,7 @@
<Slider Name="headingSlider" ToolTip="Heading" Margin="4,0,4,0" Width="100" Minimum="0" Maximum="360" SmallChange="10" LargeChange="45"
Value="{Binding TargetHeading, ElementName=map}"/>
<CheckBox ToolTip="Map Overlay" Margin="4,0,4,0" VerticalAlignment="Center" Content="Seamarks" Click="SeamarksClick"/>
<ComboBox Name="tileLayerComboBox" ToolTip="Main Tile Layer" Margin="4,0,4,0" DisplayMemberPath="Name" SelectedIndex="0">
<ComboBox Name="tileLayerComboBox" ToolTip="Main Tile Layer" Margin="4,0,0,0" DisplayMemberPath="Name" SelectedIndex="0">
<ComboBox.Items>
<map:TileLayer Name="OpenStreetMap" Description="© {y} OpenStreetMap Contributors, CC-BY-SA"
TileSource="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"/>

View file

@ -1,7 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Caching;
using MapControl;
@ -9,6 +11,12 @@ namespace SampleApplication
{
public partial class MainWindow : Window
{
private SamplePoint movingPoint = new SamplePoint
{
Name = "Moving",
Location = new Location(53.5, 8.25)
};
public MainWindow()
{
if (Properties.Settings.Default.UsePersistentCache)
@ -67,6 +75,7 @@ namespace SampleApplication
Name = "Buhne 10",
Location = new Location(53.49350, 8.15563)
});
points.Add(movingPoint);
ICollection<object> pushpins = (ICollection<object>)Resources["Pushpins"];
pushpins.Add(
@ -93,6 +102,22 @@ namespace SampleApplication
Name = "Eckwarderhörne",
Location = new Location(53.5207, 8.2323)
});
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(0.05);
timer.Tick += MovePoint;
timer.Start();
}
private void MovePoint(object sender, EventArgs e)
{
movingPoint.Location = new Location(movingPoint.Location.Latitude + 0.0005, movingPoint.Location.Longitude + 0.001);
if (movingPoint.Location.Latitude > 54d)
{
movingPoint.Name = "Stopped";
((DispatcherTimer)sender).Stop();
}
}
private void MapManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)

View file

@ -1,12 +1,43 @@
using System.Collections.ObjectModel;
using MapControl;
using System.ComponentModel;
namespace SampleApplication
{
class SamplePoint
class SamplePoint : INotifyPropertyChanged
{
public string Name { get; set; }
public Location Location { get; set; }
private string name;
private Location location;
public event PropertyChangedEventHandler PropertyChanged;
public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged("Name");
}
}
public Location Location
{
get { return location; }
set
{
location = value;
OnPropertyChanged("Location");
}
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
class SamplePolyline