views:

70

answers:

1

Hi Everyone!

I'm using the Google Earth Web-plugin API and I've got a 3d model of a helicopter, I can create a 3d model using the following code:

var placemark = ge.createPlacemark('');

placemark.setName('model');

// Placemark/Model (geometry)

var model = ge.createModel('heli'); placemark.setGeometry(model);

// Placemark/Model/Link

var link = ge.createLink('');

link.setHref('http://my.url/heli.dae');

model.setLink(link);

// Placemark/Model/Location

var loc = ge.createLocation('');

loc.setLatLngAlt(temp1,temp2,alt)

model.setLocation(loc);

model.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);

// add the model placemark to Earth

ge.getFeatures().appendChild(placemark);

So I've been creating a new model everytime new lat long coordinates come in, is there a way to simply move the 3d models to these coordinates instead of creating a new one, after about 50 renders, it becomes unresponsive! Any help would be appreciated

I assume that instead of createPlacemark I need to getPlacemark, but there's no mention of such a function in the reference.

+1  A: 

Rather than recreating the placemark each time - simply update its coordinates. You could easily use a function to do this. You could then simply call the moveModel function with the desired coordinates every time you wish to update the models position.

var placemark = ge.createPlacemark('');
var model = ge.createModel('heli'); 
var link = ge.createLink('');

placemark.setName('model');
placemark.setGeometry(model);
link.setHref('http://my.url/heli.dae');
model.setLink(link);

moveModel(temp1, temp2, alt); // your location...

ge.getFeatures().appendChild(placemark);

function moveModel(temp1, temp2, alt) {
  var loc = ge.createLocation('');
  loc.setLatLngAlt(temp1,temp2,alt)
  model.setLocation(loc);
  model.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);
}
Fraser