Google Earth API Samples - Toggling Event Listeners

Last Modified:
08/04/08


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) {
  alert('You clicked the placemark!');
}