XAML-Map-Control/SampleApps/WpfApplication/MainWindow.xaml.cs

92 lines
3.2 KiB
C#
Raw Normal View History

using System;
using System.Globalization;
using System.Runtime.Caching;
2012-05-04 12:52:20 +02:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Caching;
using MapControl;
2012-05-04 12:52:20 +02:00
namespace WpfApplication
2012-05-04 12:52:20 +02:00
{
public partial class MainWindow : Window
{
public MainWindow()
{
switch (Properties.Settings.Default.TileCache)
{
case "MemoryCache":
TileImageLoader.Cache = MemoryCache.Default;
break;
case "FileDbCache":
TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheDirectory);
break;
case "ImageFileCache":
TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheDirectory);
break;
default:
break;
}
2012-05-04 12:52:20 +02:00
InitializeComponent();
}
private void MapMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
2012-05-04 12:52:20 +02:00
{
if (e.ClickCount == 2)
{
map.ZoomMap(e.GetPosition(map), Math.Floor(map.ZoomLevel + 1.5));
//map.TargetCenter = map.ViewportPointToLocation(e.GetPosition(map));
}
}
private void MapMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
map.ZoomMap(e.GetPosition(map), Math.Ceiling(map.ZoomLevel - 1.5));
}
2012-05-04 12:52:20 +02:00
}
private void MapMouseLeave(object sender, MouseEventArgs e)
{
mouseLocation.Text = string.Empty;
}
private void MapMouseMove(object sender, MouseEventArgs e)
{
var location = map.ViewportPointToLocation(e.GetPosition(map));
var longitude = Location.NormalizeLongitude(location.Longitude);
var latString = location.Latitude < 0 ?
string.Format(CultureInfo.InvariantCulture, "S {0:00.00000}", -location.Latitude) :
string.Format(CultureInfo.InvariantCulture, "N {0:00.00000}", location.Latitude);
var lonString = longitude < 0 ?
string.Format(CultureInfo.InvariantCulture, "W {0:000.00000}", -longitude) :
string.Format(CultureInfo.InvariantCulture, "E {0:000.00000}", longitude);
mouseLocation.Text = latString + "\n" + lonString;
2012-05-04 12:52:20 +02:00
}
private void MapManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
{
e.TranslationBehavior.DesiredDeceleration = 0.001;
}
private void MapItemTouchDown(object sender, TouchEventArgs e)
{
var mapItem = (MapItem)sender;
mapItem.IsSelected = !mapItem.IsSelected;
e.Handled = true;
}
private void SeamarksChecked(object sender, RoutedEventArgs e)
2012-05-04 12:52:20 +02:00
{
map.TileLayers.Add((TileLayer)Resources["SeamarksTileLayer"]);
}
2012-05-04 12:52:20 +02:00
private void SeamarksUnchecked(object sender, RoutedEventArgs e)
{
map.TileLayers.Remove((TileLayer)Resources["SeamarksTileLayer"]);
2012-05-04 12:52:20 +02:00
}
}
}