-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoogleEarth.cs
230 lines (178 loc) · 7.72 KB
/
GoogleEarth.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using EARTHLib;
namespace DrRobot.JaguarControl
{
class GoogleEarth
{
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int X;
public int Y;
public int Width;
public int Height;
}
[DllImport("user32.dll", SetLastError = true)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
public delegate int EnumWindowsProc(IntPtr hwnd, int lParam);
[DllImport("user32", CharSet = CharSet.Auto)]
public extern static IntPtr GetParent(IntPtr hWnd);
[DllImport("user32", CharSet = CharSet.Auto)]
public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32", CharSet = CharSet.Auto)]
public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(
int hWnd,
int nCmdShow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static bool SetWindowPos(int hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32", CharSet = CharSet.Auto)]
public extern static IntPtr PostMessage(int hWnd, int msg, int wParam, int IParam);
readonly IntPtr HWND_BOTTOM = new IntPtr(1);
readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
readonly IntPtr HWND_TOP = new IntPtr(0);
readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly Int32 WM_QUIT = 0x0012;
private IntPtr GEHrender = (IntPtr)0;
private IntPtr GEParentHrender = (IntPtr)0;
public ApplicationGEClass googleEarth;
public CameraInfoGE cam = null;
public string centerLatitude = "43.855159";
public string centerLongitude = "-79.3615177";
public int cameraRange = 200;
public double preEstLatitude = 0;
public double preEstLongitude = 0;
public double preLatitude = 0;
public double preLongtitude = 0;
public double curLatitude = 0;
public double curLongitude = 0;
public string kmlFileStr1 = @"<?xml version=""1.0"" encoding=""utf-8""?><kml xmlns=""http://www.opengis.net/kml/2.2""><Document>";
public string kmlFileStyle = @"<Style id=""MyLineStyle""><LineStyle><color>7f0000ff</color><width>4</width></LineStyle></Style>";
//private string kmlFileLookAt = @"<LookAt><longitude>-79.3607666</longitude><latitude>43.855015</latitude><altitude>0</altitude><range>150</range><heading>0</heading></LookAt>";
public string kmlFilePlacemark = @"<Placemark><name>unextruded</name><styleUrl>#MyLineStyle</styleUrl><LineString><extrude>1</extrude><tessellate>1</tessellate>";
public string kmlFileCoordinate = @"<coordinates>-79.3607666,43.855015,0 -79.3608,43.855015,0</coordinates>";
public string kmlFileEnd = @"</LineString></Placemark></Document></kml>";
//private string kmlFileName = System.Environment.CurrentDirectory + "\\gpstest0.kml";
//private static double startLat = 0;
//private static double startLongitude = 0;
public SetColor setColor = new SetColor();
public class SetColor
{
public string SetRed = "0x7f0000ff";
public string SetGreen = "0x7f00ff00";
public string SetBlue = "0x7fff0000";
}
private void btnSetStartPoint_Click(JaguarCtrl jc, object sender, EventArgs e)
{
cam = new CameraInfoGE();
double centerLat = double.Parse(centerLatitude);
double centerLong = double.Parse(centerLongitude);
try
{
centerLat = double.Parse(jc.txtStartLat.Text);
}
catch
{
}
try
{
centerLong = double.Parse(jc.txtStartLong.Text);
}
catch
{
}
centerLat = (centerLat > 90 ? 90 : centerLat);
centerLat = (centerLat < -90 ? -90 : centerLat);
centerLong = (centerLong > 180 ? 180 : centerLong);
centerLong = (centerLong < -180 ? -180 : centerLong);
cam.FocusPointLatitude = centerLat;
cam.FocusPointLongitude = centerLong;
cam.FocusPointAltitude = 0;
cam.Range = cameraRange;
cam.Tilt = 0;
googleEarth.SetCamera(cam, 0.6);
}
//this is a zoom function
private void trackBarZoom_Scroll(JaguarCtrl jc, object sender, EventArgs e)
{
if (cam != null)
{
cameraRange = jc.trackBarZoom.Value;
cam.Range = cameraRange;
googleEarth.SetCamera(cam, 0.6);
}
}
// this function will set map center as default map start point
private void btnSetMapCenter_Click(JaguarCtrl jc, object sender, EventArgs e)
{
PointOnTerrainGE pointGe = new PointOnTerrainGE();
pointGe = googleEarth.GetPointOnTerrainFromScreenCoords(0, 0);
double lat = pointGe.Latitude;
double longitude = pointGe.Longitude;
jc.txtStartLat.Text = lat.ToString();
jc.txtStartLong.Text = longitude.ToString();
btnSetStartPoint_Click(jc, null, null);
}
public void Initialize(JaguarCtrl jc)
{
centerLatitude = jc.jaguarSetting.GoogleEarthStartLat.ToString();
centerLongitude = jc.jaguarSetting.GoogleEarthStartLong.ToString();
jc.txtStartLat.Text = centerLatitude;
jc.txtStartLong.Text = centerLongitude;
if (true)//(jc.DesignMode == false)
{
googleEarth = new ApplicationGEClass();
MessageBox.Show("Waiting for GoogleEarth to be loaded…. \n This may take a while.When the GoogleEarth is shown, click OK to continue.", "DrRobot Jaguar Control", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
//ShowWindowAsync(googleEarth.GetMainHwnd(), 0);
GEHrender = (IntPtr)googleEarth.GetRenderHwnd();
GEParentHrender = GetParent(GEHrender);
MoveWindow(GEHrender, 0, 0, jc.panelGE.Width, jc.panelGE.Height, true);
SetParent(GEHrender, jc.panelGE.Handle);
// don'tdo it now , we keep google earth window to clear the KML data in temporary node
//Hide the main GE window
//SetWindowPos(googleEarth.GetMainHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE + SWP_HIDEWINDOW);
}
}
public void Close(JaguarCtrl jc, RobotConfig robotCfg, string configFile)
{
double centerLat = double.Parse(centerLatitude);
double centerLong = double.Parse(centerLongitude);
try
{
centerLat = double.Parse(jc.txtStartLat.Text);
}
catch
{
}
try
{
centerLong = double.Parse(jc.txtStartLong.Text);
}
catch
{
}
jc.jaguarSetting.GoogleEarthStartLat = centerLat;
jc.jaguarSetting.GoogleEarthStartLong = centerLong;
try
{
robotCfg.WriteXml(configFile);
}
catch
{
}
try
{
PostMessage(googleEarth.GetMainHwnd(), WM_QUIT, 0, 0);
}
catch
{
}
}
}
}