Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble attaching event listener to a kml layer's polygon
    text
    copied!<p>Using Google Earth I have a loaded kml layer that displays polygons of every county in the US. On click a balloon pop's up with some relevant info about the state (name, which state, area, etc) When a user clicks the polygon I want the information to also pop up on a DIV element somewhere else.</p> <p>This is my code so far.</p> <pre><code>var ge; google.load("earth", "1"); function init() { google.earth.createInstance('map3d', initCB, failureCB); } function initCB(instance) { ge = instance; ge.getWindow().setVisibility(true); ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO); ge.getNavigationControl().setStreetViewEnabled(true); ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true); //here is where im loading the kml file google.earth.fetchKml(ge, href, function (kmlObject) { if (kmlObject) { // show it on Earth ge.getFeatures().appendChild(kmlObject); } else { setTimeout(function () { alert('Bad or null KML.'); }, 0); } }); function recordEvent(event) { alert("click"); } // Listen to the mousemove event on the globe. google.earth.addEventListener(ge.getGlobe(), 'click', recordEvent); } function failureCB(errorCode) {} google.setOnLoadCallback(init); </code></pre> <p>My problem is that when I change <code>ge.getGlobe()</code> to kmlObject or <code>ge.getFeatures()</code> it doesn't work.</p> <p>My first question is what should I change ge.getGlobe() to to be able to get a click listener when a user clicks on a kml layer's polygon?</p> <p>After that I was planning on using <code>getDescription()</code> or <code>getBalloonHtml()</code> to get the polygons balloons information. Am I even on the right track?</p>
 

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