Google Earth API Samples - Toggling Event Listeners

Last Modified:
06/08/2009
Installed Plugin Version:
...


Relevant Resources:

Relevant Code Excerpt:

// global state
var eventListenerActive;

function enableListener() {
  if (!eventListenerActive) {
    google.earth.addEventListener(placemark, 'click', myEventHandler);
    eventListenerActive = true;
  }
}

function disableListener() {
  if (eventListenerActive) {
    google.earth.removeEventListener(placemark, 'click', myEventHandler);
    eventListenerActive = false;
  }
}

function myEventHandler(event) {
  // wrap alerts in API callbacks and event handlers
  // in a setTimeout to prevent deadlock in some browsers
  setTimeout(function() {
    alert('You clicked the placemark!');
  }, 0);
}