-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGisViewerControl.cs
More file actions
272 lines (235 loc) · 7.32 KB
/
GisViewerControl.cs
File metadata and controls
272 lines (235 loc) · 7.32 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using DotSpatial.Data;
using DotSpatial.Projections;
using DotSpatial.Controls;
namespace GisViewer
{
public partial class GisViewerControl : UserControl
{
private string shp;
private string prj;
private AttributeTable atb;
private IFeatureSet shapefile;
private string path;
private string name;
private bool tnew, topen, tpan, tzoomin, tzoomout, tzoomextent, tidentify, tselect;
public GisViewerControl()
{
InitializeComponent();
toolPan.ToolTipText = "Pan\nShortcut: H";
toolZoomIn.ToolTipText = "Zoom In\nShortcut: —";
toolZoomOut.ToolTipText = "Zoom Out" + Environment.NewLine + "Shortcut: +";
toolZoomToMaxExtent.ToolTipText = "Zoom To Full Extent\nShortcut: E";
toolInfo.ToolTipText = "Identify\nShortcut: I (i)";
TNew = false;
TOpen = false;
TSelect = false;
//toolPan.ToolTipText = "Pan";
//toolZoomIn.ToolTipText = "Zoom In";
//toolZoomOut.ToolTipText = "Zoom Out";
//toolZoomToMaxExtent.ToolTipText = "Zoom To Full Extent";
//toolInfo.ToolTipText = "Identify";
}
//private void Map_Load(object sender, EventArgs e)
//{
// map.Refresh();
//}
public string SHP
{
get { return shp; }
set
{
shp = value;
if (File.Exists(shp))
{
shapefile = Shapefile.Open(shp);
if (shapefile.Projection.Name == null)
{
shapefile.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
}
toolStripStatusLabel1.Text = shp;
name = Path.GetFileNameWithoutExtension(shp);
path = Path.GetDirectoryName(shp);
var _prj = Path.Combine(path, name + ".prj");
//if (File.Exists(_prj)) PRJ = _prj;
map.AddLayer(shp);
}
}
}
public string PRJ
{
get { return prj; }
set
{
prj = value;
if (File.Exists(prj))
{
textProjection.Enabled = true;
textProjection.Visible = true;
textProjection.Text = File.ReadAllText(prj);
}
}
}
#region Set tools on and off
public bool TNew
{
set
{
tnew = value;
toolNew.Enabled = tnew;
toolNew.Visible = tnew;
}
}
public bool TOpen
{
set
{
topen = value;
toolOpen.Enabled = topen;
toolOpen.Visible = topen;
}
}
public bool TPan
{
set
{
tpan = value;
toolPan.Enabled = tpan;
toolPan.Visible = tpan;
}
}
public bool TZoomIn
{
set
{
tzoomin = value;
toolZoomIn.Enabled = tzoomin;
toolZoomIn.Visible = tzoomin;
}
}
public bool TZoomOut
{
set
{
tzoomout = value;
toolZoomOut.Enabled = tzoomout;
toolZoomOut.Visible = tzoomout;
}
}
public bool TZoomExtent
{
set
{
tzoomextent = value;
toolZoomToMaxExtent.Enabled = tzoomextent;
toolZoomToMaxExtent.Visible = tzoomextent;
}
}
public bool TIdentify
{
set
{
tidentify = value;
toolInfo.Enabled = tidentify;
toolInfo.Visible = tidentify;
}
}
public bool TSelect
{
set
{
tselect = value;
toolSelect.Enabled = tselect;
toolSelect.Visible = tselect;
}
}
#endregion
private void tabData_Enter(object sender, EventArgs e)
{
atb = new AttributeTable(SHP);
attributeGridView.DataSource = atb.Table;
}
#region tools
private void toolPan_Click(object sender, EventArgs e)
{
map.FunctionMode = DotSpatial.Controls.FunctionMode.Pan;
}
private void toolZoomIn_Click(object sender, EventArgs e)
{
//map.ZoomIn();
map.FunctionMode = DotSpatial.Controls.FunctionMode.ZoomIn;
}
private void toolZoomOut_Click(object sender, EventArgs e)
{
map.FunctionMode = DotSpatial.Controls.FunctionMode.ZoomOut;
}
private void toolZoomToMaxExtent_Click(object sender, EventArgs e)
{
map.ZoomToMaxExtent();
}
private void toolInfo_Click(object sender, EventArgs e)
{
map.FunctionMode = DotSpatial.Controls.FunctionMode.Info;
}
private void toolSelect_Click(object sender, EventArgs e)
{
map.FunctionMode = DotSpatial.Controls.FunctionMode.Select;
}
#endregion tools
#region mouse events
private void map_GeoMouseMove(object sender, DotSpatial.Controls.GeoMouseArgs e)
{
toolStripStatusLabelCoor.Text = " X: " + e.GeographicLocation.X.ToString("F6")
+ " Y: " + e.GeographicLocation.Y.ToString("F6");
}
private void tabMap_MouseUp(object sender, MouseEventArgs e)
{
map.ZoomIn();
}
private void tabMap_MouseDown(object sender, MouseEventArgs e)
{
map.ZoomOut();
}
#endregion mouse events
private void map_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.H:
map.FunctionMode = DotSpatial.Controls.FunctionMode.Pan;
break;
case Keys.I:
map.FunctionMode = DotSpatial.Controls.FunctionMode.Info;
break;
case Keys.E:
map.ZoomToMaxExtent();
break;
case Keys.Escape:
this.OnKeyDown(e);
break;
}
}
private void tabControl1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
this.OnKeyDown(e);
break;
default:
if (tabControl1.SelectedTab == tabMap)
map_KeyDown(sender, e);
break;
}
}
}
}