1
votes

I have exported the KML file(ICBC.kml)of the 3D model from google earth, and I want to load the 3D model to the google earth plugin, but I can't get the result, many thanks for your suggestion.

javascript code for loading the kml

// Create the placemark.
var placemark = ge.createPlacemark('');
// Get the current view`enter code here`
var myCamera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);

// Set new latitude and longitude values
myCamera.setLatitude(30.55552076525944);
myCamera.setLongitude(114.3344795151639);
myCamera.setAltitude(500);

// Placemark/Model/Location
var loc = ge.createLocation('');
loc.setLatitude(myCamera.getLatitude());
loc.setLongitude(myCamera.getLongitude());


// Update the view in Google Earth
ge.getView().setAbstractView(myCamera);

var fso = new ActiveXObject("Scripting.FileSystemObject");

var f = fso.OpenTextFile("http://localhost/ICBC.kml",1,true);

var kmlobject = ge.parseKml(f.ReadAll());
ge.getFeatures().appendChild(kmlobject);
var la = ge.createLookAt('');
la.set(30.55552076525944, 114.3344795151639, 500, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 45, 900);
ge.getView().setAbstractView(la);
1

1 Answers

2
votes

If you have the KML file, you shouldn't use parseKml, it's a better practice to use fetchKml, that doesn't need the string of the Kml to be passed, just the URL of the KML.

In your case you should use this line:

var href = UrlOfKML;

google.earth.fetchKml(googleEarthInstance, href, function(kmlObject) {
      if (kmlObject)
         ge.getFeatures().appendChild(kmlObject);
});

If you have more doubts about the differences of fetchKml and parseKml check this link: Importing KML - GE docs