Search code examples
javascriptgoogle-earth-plugin

Google Earth Plugin eager re-render


I'm trying to animate points in a GE Plugin. The issue is that it seems to re-render itself every time I change an underlying geometry which ends up freezing the plugin.

var lineString = ge.createLineString(''),
    placemark  = ge.createPlacemark(''),
    coords     = lineString.getCoordinates(),
    features   = ge.getFeatures();

placemark.setGeometry(lineString);
features.appendChild(placemark);

myPoints.forEach(function(point) {
  // google earth re-renders on every one of these calls
  coords.pushLatLngAlt(point.lat, point.lng, 0);
});

// I want something explicit, like this, instead
placemark.redraw();

Instead of applying all the changes to the LineString coordinates and then calling a re-render method on the placemark, it re-renders every time.

The first idea I had was to do some type of double buffering. But I'm loading LOTS of points and I can't afford to double my memory usage.

Is there any work around for this?

Edit:

I tried removing the geometry, editing it, and then adding it back. The placemarks just flashed... :/

placemark.setGeometry(null);

myPoints.forEach(function(point) {
  coords.pushLatLngAlt(point.lat, point.lng, 0);
});

placemark.setGeometry(lineString);

Edit:

I did manage to get a significant speed increase by using google.earth.executeBatch

google.earth.executeBatch(ge, function() {
  myPoints.forEach(function(point) {
    coords.pushLatLngAlt(point.lat, point.lng, 0);
  });
});

Solution

  • Some ideas:

    I see you edited your question to say you found the executeBatch function and that helped. You must be pushing a lot of points during every iteration to see the plugin hang.