namespace DrawTool { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.IO; using System.Threading; using System.Windows; using System.Windows.Forms; using FC.GEPluginCtrls; using OpenTraffic.Interfaces; using OpenTraffic.Model; public partial class DrawToolForm : Form { private dynamic ge; int clickButton; int clickX; int clickY; double clickLat; double clickLon; public DrawToolForm(IEventLog iEventLog, IApplyData iApplyData, TrafficModel trafficModel) { InitializeComponent(); geWebBrowser1.LoadEmbeddedPlugin(); geWebBrowser1.Navigating += new WebBrowserNavigatingEventHandler(geWebBrowser1_Navigating); geWebBrowser1.KmlEvent += new EventHandler(geWebBrowser1_KmlEvent); } private void ActiveControl_MouseMove(object sender, MouseEventArgs e) { Cursor.Current = Cursors.Cross; } private void geWebBrowser1_KmlEvent(object sender, GEEventArgs e) { switch (e.EventId) { case EventId.MouseMove: mouseMoved(e); break; case EventId.MouseDown: break; } if (e.EventId == EventId.MouseDown) { mouseClickDown(e); } } private void mouseClickDown(GEEventArgs e) { this.clickButton = e.ApiObject.getButton(); this.clickX = e.ApiObject.getClientX(); this.clickY = e.ApiObject.getClientY(); this.clickLat = e.ApiObject.getLatitude(); this.clickLon = e.ApiObject.getLongitude(); if (this.clickButton == 2) { contextMenuStrip1.Show(Cursor.Position); } } private void mouseMoved(GEEventArgs e) { int x = e.ApiObject.getClientX(); int y = e.ApiObject.getClientY(); double lat = e.ApiObject.getLatitude(); double lon = e.ApiObject.getLongitude(); //// Continue... } private void geWebBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { } private void geWebBrowser1_PluginReady(object sender, GEEventArgs e) { ge = e.ApiObject; object obj = ge.getGlobe(); this.ActiveControl.MouseMove += new MouseEventHandler(ActiveControl_MouseMove); // geWebBrowser1.AddEventListener(ge.getGlobe(), EventId.MouseMove); geWebBrowser1.AddEventListener(ge.getGlobe(), EventId.MouseDown); geStatusStrip1.SetBrowserInstance(geWebBrowser1); geToolStrip1.SetBrowserInstance(geWebBrowser1); // Here you can now use 'ge' exactly as you would // in the native javascript api. Whenever you make a // call to an api member, you should check for any RuntimeBinderExceptions try { var type = ge.getType(); var version = ge.getPluginVersion(); } catch (Exception ex) { MessageBox.Show(ex.GetType().ToString() + ": " + ex.Message + "\r\n" + ex.StackTrace, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void button1_Click(object sender, EventArgs e) { if (ge != null) { // Create a new LookAt. var lookAt = ge.createLookAt(""); // Set the position values. lookAt.setLatitude(57.72388692164629); lookAt.setLongitude(11.98473852180515); lookAt.setRange(10000.0); //default is 0.0 ge.getView().setAbstractView(lookAt); } } private void button2_Click(object sender, EventArgs e) { if (ge != null) { string buf = string.Empty; using (Stream stream = new FileStream(@"Y:\pics\Trafik\Trackidea_4 - Copy\doc.kml", FileMode.Open)) { StreamReader sr = new StreamReader(stream); string line; try { while ((line = sr.ReadLine()) != null) { buf += line; } } catch (Exception ex) { MessageBox.Show(ex.GetType().ToString() + ": " + ex.Message + "\r\n" + ex.StackTrace, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (!string.IsNullOrEmpty(buf)) { object obj = geWebBrowser1.ParseKml(buf); geWebBrowser1.ParseKmlObject(obj); } } } private PointF addMarker(PointF position, string pointIcon) { // Create the placemark. var placemark = ge.createPlacemark(""); // Define a custom icon. var icon = ge.createIcon(""); icon.setHref("http://www.bedug.com/pics/Trafik/" + pointIcon); var style = ge.createStyle(""); //create a new style style.getIconStyle().setIcon(icon); //apply the icon to the style placemark.setStyleSelector(style); //apply the style to the placemark // Set the placemark's location. var point = ge.createPoint(""); point.setLatitude(position.X); point.setLongitude(position.Y); placemark.setGeometry(point); // Add the placemark to Earth. ge.getFeatures().appendChild(placemark); return position; } private void junctionToolStripMenuItem_Click(object sender, EventArgs e) { PointF position = new PointF((float)this.clickLat, (float)this.clickLon); string pointIcon = "node.png"; position = addMarker(position, pointIcon); } private void startToolStripMenuItem1_Click(object sender, EventArgs e) { PointF position = new PointF((float)this.clickLat, (float)this.clickLon); string pointIcon = "source.png"; position = addMarker(position, pointIcon); } private void endToolStripMenuItem1_Click(object sender, EventArgs e) { PointF position = new PointF((float)this.clickLat, (float)this.clickLon); string pointIcon = "destination.png"; position = addMarker(position, pointIcon); } private void button3_Click(object sender, EventArgs e) { } } }