svipxu / 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

Distinction between 'placemark click and 'linestring click' #46

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, 
How can Distinction between 'placemark click and 'linestring click' be achieved.

i've added placemarks and linestrings to the plugin - together with 
eventlistners like so:
pm1 = GEHelpers.CreatePlacemark(.....);
this.geWebBrowser1.AddEventListener(pm1, EventId.Click);

var lineString = GEHelpers.CreateLineString(.....);
this.geWebBrowser1.AddEventListener(lineString, EventId.Click);

in the kml event I would like to do different things depending on what 
kmlobject has been clicked on:

void geWebBrowser1_KmlEvent(object sender, GEEventArgs e)
        {
            e.ApiObject.preventDefault();
            dynamic kmlObject = e.ApiObject.getTarget();
            string type = kmlObject.getType();

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

However, the type is always kmlplacemark.

Should i check on id's instead ? 
string id = kmlObject.getId(); (if so the id should be added in the 
createlinestring() ?)

Regards,
Thomas
(TKM)

Original issue reported on code.google.com by tho...@gmail.com on 31 May 2011 at 10:59

GoogleCodeExporter commented 8 years ago
Hi,

The click returns a Placemark because...the object *is* a Placemark! When you 
create a line-string to display in the plug-in it is attached to a place-mark 
object. e.g.

var pm = ge.createPlacemark('');
var lineString = ge.createLineString('');
pm.setGeometry(lineString);

As you can see the line-string is set to the geometry property of the 
place-mark.
So, what you need to do is to detect the type of geometry within the placemark.

Something like the following should work (...although I just typed it here so 
there maybe typos).

void geWebBrowser1_KmlEvent(object sender, GEEventArgs e)
{
  e.ApiObject.preventDefault();
  dynamic kmlObject = e.ApiObject.getTarget();
  string type = kmlObject.getType();

  if (type == ApiType.KmlPlacemark)
  {
    dynamic geometry = kmlObject.getGeometry();
    switch(geometry)
    {
      case ApiType.KmlLineString :
        // Handle KmlLineStrings here...
        break;
      case ApiType.KmlPoint :
        break;
      case ApiType.KmlPolygon :
        break;
      default:
        break;
    }
  }
}

Failing that using IDs as you suggested is a good approach, indeed that is what 
generally do when I am using events in the api.

Hope that helps.

Fraser.

Original comment by fraser.c...@gmail.com on 1 Jun 2011 at 12:49

GoogleCodeExporter commented 8 years ago
Thanks for clarifying that for me! Great!

-------------
To the interest of others the following needed adjusted from

dynamic geometry = kmlObject.getGeometry(); to 

string geometry = kmlObject.getGeometry().getType();

Original comment by tho...@gmail.com on 4 Jun 2011 at 9:04

GoogleCodeExporter commented 8 years ago
Hey,

No worries - sorry for the typo, looks like you got it working though - good 
stuff.

F.

Original comment by fraser.c...@gmail.com on 4 Jun 2011 at 9:22