-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormMap.cs
320 lines (281 loc) · 11.4 KB
/
FormMap.cs
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
Gamma Analyzer - Controlling application for Burn
Copyright (C) 2016 Norwegian Radiation Protection Authority
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Authors: Dag robole,
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using GMap.NET;
using GMap.NET.MapProviders;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using log4net;
namespace crash
{
public partial class FormMap : Form
{
private FormContainer parent = null;
private GASettings settings = null;
private ILog log = null;
private Session currentSession = null;
private GMapOverlay overlay = new GMapOverlay();
public FormMap(FormContainer p, GASettings s, ILog l)
{
InitializeComponent();
MdiParent = parent = p;
settings = s;
log = l;
}
private void FormMap_Load(object sender, EventArgs e)
{
try
{
gmnMap.Overlays.Add(overlay);
gmnMap.Position = new PointLatLng(59.946534, 10.598574);
gmnMap.MapProvider = ArcGIS_World_Topo_MapProvider.Instance;
int idx = cboxMapProvider.FindString("ArcGIS World Topo");
if (idx >= 0)
cboxMapProvider.SelectedIndex = idx;
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
private void cboxMapMode_SelectedIndexChanged(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(cboxMapMode.Text))
{
switch (cboxMapMode.Text)
{
case "Server":
GMaps.Instance.Mode = AccessMode.ServerOnly;
break;
case "Cache":
GMaps.Instance.Mode = AccessMode.CacheOnly;
break;
default:
GMaps.Instance.Mode = AccessMode.ServerAndCache;
break;
}
}
}
private void cboxMapProvider_SelectedIndexChanged(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(cboxMapProvider.Text))
{
switch (cboxMapProvider.Text)
{
case "Google Map":
gmnMap.MapProvider = GoogleMapProvider.Instance;
break;
case "Google Map Terrain":
gmnMap.MapProvider = GoogleTerrainMapProvider.Instance;
break;
case "Google Map Satellite":
gmnMap.MapProvider = GoogleSatelliteMapProvider.Instance;
GMaps.Instance.Mode = AccessMode.ServerAndCache;
gmnMap.Zoom = 5;
gmnMap.MaxZoom = 18;
gmnMap.MinZoom = 2;
gmnMap.Bearing = 0;
gmnMap.CanDragMap = true;
break;
case "Open Street Map":
gmnMap.MapProvider = OpenStreetMapProvider.Instance;
break;
case "Open Street Map Quest":
gmnMap.MapProvider = OpenStreetMapQuestProvider.Instance;
break;
case "ArcGIS World Topo":
gmnMap.MapProvider = ArcGIS_World_Topo_MapProvider.Instance;
break;
case "ArcGIS World 2D":
gmnMap.MapProvider = ArcGIS_Imagery_World_2D_MapProvider.Instance;
break;
case "ArcGIS World Shaded":
gmnMap.MapProvider = ArcGIS_World_Shaded_Relief_MapProvider.Instance;
break;
case "Bing Map":
gmnMap.MapProvider = BingMapProvider.Instance;
break;
case "Bing Map Hybrid":
gmnMap.MapProvider = BingHybridMapProvider.Instance;
break;
case "Bing Map Satellite":
gmnMap.MapProvider = BingSatelliteMapProvider.Instance;
break;
case "Yahoo Map":
gmnMap.MapProvider = YahooMapProvider.Instance;
break;
case "Yahoo Map Hybrid":
gmnMap.MapProvider = YahooHybridMapProvider.Instance;
break;
case "Yahoo Map Satellite":
gmnMap.MapProvider = YahooSatelliteMapProvider.Instance;
break;
}
}
}
private void RemoveAllMarkers()
{
GMapPoint.MinDoserate = 0d;
GMapPoint.MaxDoserate = 0d;
if (overlay == null)
return;
for(int i = 0; i < overlay.Markers.Count; i++)
overlay.Markers.RemoveAt(i);
overlay.Markers.Clear();
overlay.Clear();
gmnMap.Overlays.Remove(overlay);
overlay = new GMapOverlay();
gmnMap.Overlays.Add(overlay);
gmnMap.Refresh();
}
public void SetSession(Session sess)
{
currentSession = sess;
RemoveAllMarkers();
foreach(Spectrum spec in currentSession.Spectrums)
AddMarker(spec);
if(currentSession.Spectrums.Count > 0)
gmnMap.Position = new GMap.NET.PointLatLng(currentSession.Spectrums[0].Latitude, currentSession.Spectrums[0].Longitude);
}
public void AddMarker(Spectrum s)
{
if (currentSession == null)
return;
double minDose = currentSession.Spectrums.Min(x => x.Doserate);
GMapPoint.MinDoserate = minDose <= 0 ? 0 : Math.Log(minDose);
double maxDose = currentSession.Spectrums.Max(x => x.Doserate);
GMapPoint.MaxDoserate = maxDose <= 0 ? 0 : Math.Log(maxDose);
// Add map marker
GMapPoint marker = new GMapPoint(new PointLatLng(s.Latitude, s.Longitude), new Size(12, 12));
marker.Tag = s;
marker.ToolTipText = s.ToString()
+ Environment.NewLine + "Latitude: " + s.Latitude.ToString("#00.0000000")
+ Environment.NewLine + "Longitude: " + s.Longitude.ToString("#00.0000000")
+ Environment.NewLine + "Altitude: " + s.Altitude.ToString("#####0.0#")
+ Environment.NewLine + "Doserate: " + String.Format("{0:###0.0##}", s.Doserate / 1000.0) + " μSv/h";
marker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
overlay.Markers.Add(marker);
}
private void gmap_OnMarkerClick(GMapMarker item, MouseEventArgs e)
{
Spectrum s = item.Tag as Spectrum;
parent.SetSelectedSessionIndex(s.SessionIndex);
}
public void SetSelectedSessionIndex(int index)
{
foreach (GMapPoint m in overlay.Markers)
{
Spectrum s = m.Tag as Spectrum;
if (s.SessionIndex == index)
m.ToolTipMode = MarkerTooltipMode.Always;
else
m.ToolTipMode = MarkerTooltipMode.OnMouseOver;
}
gmnMap.Refresh();
}
public void SetSelectedSessionIndices(int index1, int index2)
{
foreach (GMapPoint m in overlay.Markers)
{
Spectrum s = m.Tag as Spectrum;
if (s.SessionIndex >= index1 && s.SessionIndex <= index2)
m.ToolTipMode = MarkerTooltipMode.Always;
else
m.ToolTipMode = MarkerTooltipMode.OnMouseOver;
}
gmnMap.Refresh();
}
public void ClearSession()
{
currentSession = null;
RemoveAllMarkers();
}
private void btnZoomToMax_Click(object sender, EventArgs e)
{
gmnMap.Zoom = (double)gmnMap.MinZoom;
}
private void btnZoomToMin_Click(object sender, EventArgs e)
{
gmnMap.Zoom = (double)gmnMap.MaxZoom;
}
private void btnZoomOut_Click(object sender, EventArgs e)
{
gmnMap.Zoom -= 1.0;
}
private void btnZoomIn_Click(object sender, EventArgs e)
{
gmnMap.Zoom += 1.0;
}
private void menuItemIAEAColors_CheckedChanged(object sender, EventArgs e)
{
GMapPoint.UseIAEAColors = menuItemIAEAColors.Checked;
gmnMap.Refresh();
}
private void FormMap_FormClosing(object sender, FormClosingEventArgs e)
{
gmnMap.Manager.CancelTileCaching();
}
}
public class GMapPoint : GMapMarker
{
public static bool UseIAEAColors;
public static double MinDoserate;
public static double MaxDoserate;
public GMapPoint(PointLatLng pos, Size siz) : base(pos)
{
Size = siz;
Offset = new Point(-Size.Width / 2, -Size.Height / 2);
}
public override void OnRender(Graphics g)
{
Spectrum spec = Tag as Spectrum;
Color color = new Color();
if (UseIAEAColors)
{
double dose = spec.Doserate / 1000.0;
if (dose <= 1.0)
color = Color.FromArgb(255, 0, 0, 255);
else if (dose <= 5.0)
color = Color.FromArgb(255, 0, 255, 0);
else if (dose <= 10.0)
color = Color.FromArgb(255, 255, 255, 0);
else if (dose <= 20.0)
color = Color.FromArgb(255, 255, 165, 0);
else
color = Color.FromArgb(255, 255, 0, 0);
}
else
{
double dose = Math.Log(spec.Doserate);
color = Utils.MapColor(MinDoserate, MaxDoserate, dose);
}
using (SolidBrush brush = new SolidBrush(color))
{
g.FillEllipse(brush, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
}
}
public override void Dispose()
{
// Dispose
base.Dispose();
}
}
}