XAML-Map-Control/SampleApps/SilverlightApplication/MainPage.xaml.cs

59 lines
2 KiB
C#
Raw Normal View History

using System.Globalization;
2012-05-04 12:52:20 +02:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using MapControl;
2012-05-04 12:52:20 +02:00
namespace SilverlightApplication
2012-05-04 12:52:20 +02:00
{
public partial class MainPage : UserControl
2012-05-04 12:52:20 +02:00
{
public MainPage()
2012-05-04 12:52:20 +02:00
{
InitializeComponent();
tileLayerComboBox.SelectedIndex = 0;
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 TileLayerSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBox = (ComboBox)sender;
var tileLayers = (TileLayerCollection)Resources["TileLayers"];
map.TileLayer = tileLayers[(string)comboBox.SelectedItem];
}
2012-05-04 12:52:20 +02:00
private void SeamarksClick(object sender, RoutedEventArgs e)
{
var checkBox = (CheckBox)sender;
var tileLayers = (TileLayerCollection)Resources["TileLayers"];
var tileLayer = tileLayers["Seamarks"];
2012-05-04 12:52:20 +02:00
if ((bool)checkBox.IsChecked)
{
map.TileLayers.Add(tileLayer);
2012-05-04 12:52:20 +02:00
}
else
{
map.TileLayers.Remove(tileLayer);
2012-05-04 12:52:20 +02:00
}
}
}
}