2014-07-01 18:57:44 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using MapControl;
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
using Windows.UI.Xaml.Data;
|
|
|
|
|
|
using Windows.UI.Xaml.Input;
|
|
|
|
|
|
using Windows.UI.Xaml.Navigation;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PhoneApplication
|
|
|
|
|
|
{
|
|
|
|
|
|
public sealed partial class MainPage : Page
|
|
|
|
|
|
{
|
2014-10-19 21:50:23 +02:00
|
|
|
|
private TileLayerCollection tileLayers;
|
2014-07-01 18:57:44 +02:00
|
|
|
|
private bool manipulationActive;
|
|
|
|
|
|
|
|
|
|
|
|
public MainPage()
|
|
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
//BingMapsTileLayer.ApiKey = "...";
|
2014-07-09 21:27:28 +02:00
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
InitializeComponent();
|
2014-07-09 21:27:28 +02:00
|
|
|
|
|
2014-10-19 21:50:23 +02:00
|
|
|
|
tileLayers = (TileLayerCollection)Resources["TileLayers"];
|
|
|
|
|
|
SetTileLayer(tileLayers[0].SourceName);
|
2014-07-09 21:27:28 +02:00
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
DataContext = new ViewModel(Dispatcher);
|
|
|
|
|
|
NavigationCacheMode = NavigationCacheMode.Required;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-19 21:50:23 +02:00
|
|
|
|
private void SetTileLayer(string tileLayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TileLayer = tileLayers[tileLayer];
|
|
|
|
|
|
|
|
|
|
|
|
mapLegend.Inlines.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var inline in map.TileLayer.DescriptionInlines)
|
|
|
|
|
|
{
|
|
|
|
|
|
mapLegend.Inlines.Add(inline);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
private void SeamarksChecked(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TileLayers.Add((TileLayer)tileLayers["Seamarks"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SeamarksUnchecked(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TileLayers.Remove((TileLayer)tileLayers["Seamarks"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapMenuItemClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2014-10-19 21:50:23 +02:00
|
|
|
|
var selectedItem = (MenuFlyoutItem)sender;
|
|
|
|
|
|
SetTileLayer((string)selectedItem.Tag);
|
2014-07-01 18:57:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CenterButtonClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
manipulationActive = false;
|
|
|
|
|
|
map.TargetCenter = ((ViewModel)DataContext).Location;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
manipulationActive = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
manipulationActive = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (manipulationActive)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Complete();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class ObjectReferenceConverter : IValueConverter
|
|
|
|
|
|
{
|
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (targetType == typeof(Visibility))
|
|
|
|
|
|
{
|
|
|
|
|
|
return value != null ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return value != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|