sagulnet / winforms-geplugin-control-library

Automatically exported from code.google.com/p/winforms-geplugin-control-library
GNU General Public License v3.0
0 stars 0 forks source link

How do I get the Lat/Long #42

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What should this feature enhancement do?
I'm just trying to figure out how to get the Lat/Long from a mouse click event 
on the globe.

Are there any known workarounds that produce the similar results?

Please provide any additional information below.
A while back I played with your lib and I recall it was a matter of calling the 
KMLMouseEvent, but that seems to be gone in the latest version.

Original issue reported on code.google.com by psh...@yahoo.com on 24 Apr 2011 at 10:10

GoogleCodeExporter commented 8 years ago
Hi,

Take a look at the AddEventListener method.

http://code.google.com/p/winforms-geplugin-control-library/wiki/AddEventListener

Basically you would get the lat/lng like so...

namespace EventsTest
{
    using System;
    using System.Windows.Forms;
    using FC.GEPluginCtrls;

    public partial class Form1 : Form
    {
        private dynamic ge;

        public Form1()
        {
            InitializeComponent();

            geWebBrowser1.LoadEmbededPlugin();
            geWebBrowser1.PluginReady += (o, e) =>
            {
                ge = e.ApiObject;

                // add a click event listner to the globe
                geWebBrowser1.AddEventListener(ge.getGlobe(), EventId.Click);
            };

            geWebBrowser1.KmlEvent += (o, e) =>
            {
                // show the event data...
                MessageBox.Show(e.Data, e.Message); //KmlMouseEvent click

                //double lat = e.ApiObject.getLatitude();
                //double lng = e.ApiObject.getLongitude();

                // remove the event
                geWebBrowser1.RemoveEventListener(ge.getGlobe(), EventId.Click);
            };
        }
    }
}

Original comment by fraser.c...@gmail.com on 25 Apr 2011 at 11:12

GoogleCodeExporter commented 8 years ago
Thank you, that worked. However, I do have two followup questions.
1. How do I know what ApiObject is going to be, so I can check out the 
available methods?

2. Because I am new to "dynamic", I am wondering if there is a way to get 
intellesence to work on these objects when writing the code?

Original comment by psh...@yahoo.com on 27 Apr 2011 at 12:49

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi,

1) The ApiObject member of the GEEventArgs class is the actual object returned 
from the plug-in - so you can use the native getType() method.

string type = e.ApiObject.getType();

You can conditionally check this in a managed way using the defined ApiType 
constants like so...

if(type == ApiType.KmlLineString) {}
if(type == ApiType.KmlPlacemark) {}
etc...

2) Yes, a few ways - easiest is to simply add a reference to the COM Google 
Earth Plug-in Type Library in your project.
If you wish to have intellesence for an object, simply cast it to its managed 
type.

i.e. 

IkmlPlacemark pm = GEHelpers.CreatePlacemark(ge);
//pm now supports intellesence 

As we don't really want to reference the type library (to avoid version 
dependence) when you are done coding - simply remove the reference to the COM 
Google Earth Plug-in Type Library.

On doing so you will get missing member exceptions on all the references to 
managed Api types - so, it is a breeze to simply replace them all with dynamic 
by clicking on each and replacing the type.

i.e.

dynamic pm = GEHelpers.CreatePlacemark(ge);
//pm is dynamic again

The other way involves using the full visual studio edition (rather than 
express versions) and is outside the scope of the comments here. I plan to 
write a blog post on this other method in the near future and will post the Url 
to that here.

Hope that helps,

F

Original comment by fraser.c...@gmail.com on 27 Apr 2011 at 11:56

GoogleCodeExporter commented 8 years ago
Thanks you.

Original comment by psh...@yahoo.com on 1 May 2011 at 4:41

GoogleCodeExporter commented 8 years ago
I have tried your code. the sample works perfect. 
but when I try fetchkmllocal(), it looks nothing happeded(test_7).
I can not get my mouse lat\lon\att when mouse move over gewebbrowse1
can you upload more code about this? Thanks

zgu

Original comment by zgj....@gmail.com on 29 Nov 2012 at 8:57