-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
114 lines (96 loc) · 4.21 KB
/
MainWindow.xaml.cs
File metadata and controls
114 lines (96 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using GeoAPI.Geometries;
using Application = System.Windows.Application;
using MenuItem = System.Windows.Controls.MenuItem;
namespace WPFSamples
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
var gss = GeoAPI.GeometryServiceProvider.Instance;
var css = new SharpMap.CoordinateSystems.CoordinateSystemServices(
new ProjNet.CoordinateSystems.CoordinateSystemFactory(),
new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(),
SharpMap.Converters.WellKnownText.SpatialReference.GetAllReferenceSystems());
GeoAPI.GeometryServiceProvider.Instance = gss;
SharpMap.Session.Instance
.SetGeometryServices(gss)
.SetCoordinateSystemServices(css)
.SetCoordinateSystemRepository(css);
}
private void MenuItem_OnClick(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void BgOSM_OnClick(object sender, RoutedEventArgs e)
{
WpfMap.BackgroundLayer = new SharpMap.Layers.TileAsyncLayer(BruTile.Predefined.KnownTileSources.Create(), "OSM");
foreach (var menuItem in Menu.Items.OfType<MenuItem>())
{
menuItem.IsChecked = false;
}
BgOsm.IsChecked = true;
WpfMap.ZoomToExtents();
e.Handled = true;
}
private void BgStamenWaterColor_Click(object sender, RoutedEventArgs e)
{
WpfMap.BackgroundLayer = new SharpMap.Layers.TileAsyncLayer(
BruTile.Predefined.KnownTileSources.Create(
BruTile.Predefined.KnownTileSource.StamenWatercolor), "Stamen Watercolor");
foreach (var menuItem in Menu.Items.OfType<MenuItem>())
{
menuItem.IsChecked = false;
}
BgStamenWaterColor.IsChecked = true;
WpfMap.ZoomToExtents();
e.Handled = true;
}
private void AddShapeLayer_OnClick(object sender, RoutedEventArgs e)
{
var ofd = new OpenFileDialog();
ofd.Filter = @"Shapefiles (*.shp)|*.shp";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var ds = new SharpMap.Data.Providers.ShapeFile(ofd.FileName);
var lay = new SharpMap.Layers.VectorLayer(System.IO.Path.GetFileNameWithoutExtension(ofd.FileName), ds);
if (ds.CoordinateSystem != null)
{
GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory fact =
new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
lay.CoordinateTransformation = fact.CreateFromCoordinateSystems(ds.CoordinateSystem,
ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
lay.ReverseCoordinateTransformation = fact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator,
ds.CoordinateSystem);
}
WpfMap.MapLayers.Add(lay);
if (WpfMap.MapLayers.Count == 1)
{
Envelope env = lay.Envelope;
WpfMap.ZoomToEnvelope(env);
}
}
e.Handled = true;
}
private void Rotation_OnClick(object sender, RoutedEventArgs e)
{
if (!(sender is MenuItem mi))
return;
WpfMap.MapRotation = float.Parse(mi.Name.Substring(3), NumberStyles.Integer);
foreach (MenuItem tmp in ((MenuItem)mi.Parent).Items)
tmp.IsChecked = tmp == mi;
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
}
}
}