Google Earth API Samples - Batch function calls

Last Modified:
08/25/2009
Installed Plugin Version:
...
-- --

Relevant Resources:

Relevant Code Excerpt:

function runUnbatched() {
  // Run the function unbatched and measure run time.
  var startTime = new Date().getTime();
  run();
  document.getElementById('status-unbatched').innerHTML =
      (new Date().getTime() - startTime) + 'ms';
}

function runBatched() {
  // Run the function batched and measure run time.

  // NOTE: google.earth.executeBatch is guaranteed
  // to be synchronous.
  var startTime = new Date().getTime();
  google.earth.executeBatch(ge, function() {
    run();
    document.getElementById('status-batched').innerHTML =
        (new Date().getTime() - startTime) + 'ms';
  });
}
var placemark;
function run() {
  // Create a swirly line string with 1000 coordinates, all in JavaScript.
  if (placemark)
    ge.getFeatures().removeChild(placemark);

  var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
  placemark = ge.createPlacemark('');
  var lineString = ge.createLineString('');
  lineString.setTessellate(true);

  var coords = lineString.getCoordinates();
  for (var i = 0; i < 1000; i++) {
    coords.pushLatLngAlt(
        lookAt.getLatitude() + Math.cos(i / 10) * i / 10,
        lookAt.getLongitude() + Math.sin(i / 10) * i / 10,
        0);
  }

  placemark.setGeometry(lineString);
  ge.getFeatures().appendChild(placemark);
}