Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>...what should I change ge.getGlobe() to...</p> </blockquote> <p>You don't need to change the event object from <code>GEGlobe</code>. Indeed it is the best option as you can use it to capture all the events and then check the target object in the handler. This means you only have to set up a single event listener in the API.</p> <p>The other option would be to somehow parse the KML and attach specific event handlers to specific objects. This means you have to create an event listener for each object.</p> <blockquote> <p>Am I even on the right track?</p> </blockquote> <p>So, yes you are on the right track. I would keep the generic <code>GEGlobe</code> event listener but extend your <code>recordEvent</code> method to check for the types of KML object you are interested in. You don't show your KML so it is hard to know how you have structured it (are your <code>&lt;Polygon&gt;</code>s nested in <code>&lt;Placemarks&gt;</code> or ` elements for example).</p> <p>In the simple case if your Polygons are in Placemarks then you could just do the following. Essentially listening for clicks on all objects, then filtering for all Placmark's (either created via the API or loaded in via KML).</p> <pre><code>function recordEvent(event) { var target = event.getTarget(); var type = target.getType(); if(type == "KmlPolygon") { } else if(type == "KmlPlacemark") { // get the data you want from the target. var description = target.getDescription(); var balloon = target.getBalloonHtml(); } else if(type == "KmlLineString") { //etc... } }; google.earth.addEventListener(ge.getGlobe(), 'click', recordEvent); </code></pre> <p>If you wanted to go for the other option you would iterate over the KML Dom once it has loaded and then add events to specific objects. You can do this using something like <a href="https://code.google.com/p/earth-api-samples/source/browse/trunk/lib/kmldomwalk.js" rel="nofollow">kmldomwalk.js</a>. Although I wouldn't really recommend this approach here as you will create a large number of event listeners in the api (one for each Placemark in this case). The up side is that the events are attached to each specific object from the kml file, so if you have other Plaemarks, etc, that shouldn't have the same 'click' behaviour then it can be useful.</p> <pre><code>function placeMarkClick(event) { var target = event.getTarget(); // get the data you want from the target. var description = target.getDescription(); var balloon = target.getBalloonHtml(); } google.earth.fetchKml(ge, href, function (kml) { if (kml) { parseKml(kml); } else { setTimeout(function () { alert('Bad or null KML.'); }, 0); } }); function parseKml(kml) { ge.getFeatures().appendChild(kml); walkKmlDom(kml, function () { var type = this.getType(); if (type == 'KmlPlacemark') { // add event listener to `this` google.earth.addEventListener(this, 'click', placeMarkClick); } }); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload