forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormDemoDrawGeometries.cs
More file actions
139 lines (104 loc) · 4.46 KB
/
FormDemoDrawGeometries.cs
File metadata and controls
139 lines (104 loc) · 4.46 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GeoAPI.Geometries;
using SharpMap.Layers;
using SharpMap.Data;
using SharpMap.Styles;
using SharpMap.Rendering.Thematics;
using BruTile.Web;
using BruTile.Predefined;
using SharpMap.Data.Providers;
using GeometryTransform = GeoAPI.CoordinateSystems.Transformations.GeometryTransform;
namespace WinFormSamples
{
public partial class FormDemoDrawGeometries : Form
{
private SharpMap.Data.Providers.GeometryProvider geoProvider;
public FormDemoDrawGeometries()
{
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
private void FormDemoDrawGeometries_Load(object sender, EventArgs e)
{
//this.mapBox1.Map = ShapefileSample.InitializeMap(0);
//Google Background
TileAsyncLayer bingLayer = new TileAsyncLayer(KnownTileSources.Create(KnownTileSource.BingRoadsStaging), "TileLayer - Bing");
this.mapBox1.Map.BackgroundLayer.Add(bingLayer);
SharpMap.Layers.VectorLayer vl = new VectorLayer("My Geometries");
geoProvider = new SharpMap.Data.Providers.GeometryProvider(new List<IGeometry>());
vl.DataSource = geoProvider;
this.mapBox1.Map.Layers.Add(vl);
var mathTransform = LayerTools.Wgs84toGoogleMercator.MathTransform;
var geom = GeometryTransform.TransformBox(
new Envelope(-9.205626, -9.123736, 38.690993, 38.740837),
mathTransform);
this.mapBox1.Map.ZoomToExtents(); //(geom);
this.mapBox1.Refresh();
this.mapBox1.GeometryDefined += new SharpMap.Forms.MapBox.GeometryDefinedHandler(mapBox1_GeometryDefined);
this.mapBox1.ActiveToolChanged += new SharpMap.Forms.MapBox.ActiveToolChangedHandler(mapBox1_ActiveToolChanged);
this.mapBox1.MouseMove += new SharpMap.Forms.MapBox.MouseEventHandler(mapBox1_MouseMove);
}
void mapBox1_MouseMove(GeoAPI.Geometries.Coordinate worldPos, MouseEventArgs imagePos)
{
this.label2.Text = worldPos.X.ToString("N4") + "/" + worldPos.Y.ToString("N4");
}
void mapBox1_ActiveToolChanged(SharpMap.Forms.MapBox.Tools tool)
{
this.label1.Text = this.mapBox1.ActiveTool.ToString();
}
void mapBox1_GeometryDefined(GeoAPI.Geometries.IGeometry geometry)
{
MessageBox.Show("Geometry defined!\r\n"+geometry);
geoProvider.Geometries.Add(geometry);
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
this.mapBox1.Refresh();
}
private void button4_Click(object sender, EventArgs e)
{
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
}
private void button3_Click(object sender, EventArgs e)
{
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.ZoomIn;
}
private void button2_Click(object sender, EventArgs e)
{
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.ZoomOut;
}
private void Form2_SizeChanged(object sender, EventArgs e)
{
this.mapBox1.Refresh();
}
private void button7_Click(object sender, EventArgs e)
{
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.DrawPoint;
}
private void button8_Click(object sender, EventArgs e)
{
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.DrawLine;
}
private void button9_Click(object sender, EventArgs e)
{
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.DrawPolygon;
}
private void button1_Click(object sender, EventArgs e)
{
this.geoProvider.Geometries.Clear();
this.mapBox1.Refresh();
}
private void button5_Click(object sender, EventArgs e)
{
this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.ZoomWindow;
}
private void button6_Click(object sender, EventArgs e)
{
}
}
}