parseKml / Error calling method on NPObject!

618 views
Skip to first unread message

Dakine83

unread,
Jan 19, 2010, 10:21:50 PM1/19/10
to KML Developer Support - Google Earth Plug-in
Aloha all,

I'm attempting to use the parseKml function to load up a tour to the
google earth object. Below is the code. I'm getting an "Error calling
method on NPObject!" on the "var kmlObject = ge.parseKml(kmlString);"
line, in the PreviewTour function. I am using my own KML string, but
as a result of this error I have been testing using the KML from the
API Docs just in case my string is incorrectly formatted or something.

Not sure what else to include here. Please let me know what other
information I might need to provide.

Thanks,
Chris

----------------------------------------------------------------------------------------
google.load("earth", "1");
var ge;
var tour;

function init() {
google.earth.createInstance("map3d", initCallback,
failureCallback);
}

function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
var layerRoot = ge.getLayerRoot();
layerRoot.enableLayerById(ge.LAYER_TERRAIN, true);
layerRoot.enableLayerById(ge.LAYER_ROADS, false);
layerRoot.enableLayerById(ge.LAYER_BUILDINGS, true);
layerRoot.enableLayerById(ge.LAYER_BUILDINGS_LOW_RESOLUTION,
true);
layerRoot.enableLayerById(ge.LAYER_BORDERS, false);
var navControl = ge.getNavigationControl();
navControl.setVisibility(ge.VISIBILITY_SHOW);
var la = ge.createLookAt('');
la.set(12.345678, 12.345678, 0,
ge.ALTITUDE_RELATIVE_TO_GROUND, 50, 60, 1500);
ge.getView().setAbstractView(la);
}

function failureCallback(errorCode) {
alert("Failure loading the Google Earth Plugin: " +
errorCode);
}

function PreviewTour() {
var kmlString = ''
+ '<?xml version="1.0" encoding="UTF-8"?>'
+ '<kml xmlns="http://www.opengis.net/kml/
2.2">'

+ '<Document>'
+ ' <Camera>'
+ ' <longitude>-122.444633</longitude>'
+ ' <latitude>37.801899</latitude>'
+ ' <altitude>139.629438</altitude>'
+ ' <heading>-70.0</heading>'
+ ' <tilt>75</tilt>'
+ ' </Camera>'

+ ' <Placemark>'
+ ' <name>Placemark from KML string</
name>'
+ ' <Point>'
+ '
<coordinates>-122.448425,37.802907,0</coordinates>'
+ ' </Point>'
+ ' </Placemark>'

+ '</Document>'
+ '</kml>';

var kmlObject = ge.parseKml(kmlString); //this line throws the
error
tour = ge.getFeatures().appendChild(kmlObject);
ge.getTourPlayer().setTour(tour);
ge.getTourPLayer().play();
}

Dakine83

unread,
Jan 20, 2010, 5:55:22 PM1/20/10
to KML Developer Support - Google Earth Plug-in
I wanted to update this with a portion of the KML string I'm actually
using. This string is directly copied out of a .kml file that works
perfectly fine for this task.

Any help is appreciated. Thanks.
- Chris

<script>
google.load("earth", "1");
var ge;
var tour;


/*-------------------------GoogleEarth
Javascript------------------------------------------*/

function init() {
google.earth.createInstance("map3d", initCallback,
failureCallback);
}

function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
var layerRoot = ge.getLayerRoot();
layerRoot.enableLayerById(ge.LAYER_TERRAIN, true);
layerRoot.enableLayerById(ge.LAYER_ROADS, false);
layerRoot.enableLayerById(ge.LAYER_BUILDINGS, true);
layerRoot.enableLayerById(ge.LAYER_BUILDINGS_LOW_RESOLUTION,
true);
layerRoot.enableLayerById(ge.LAYER_BORDERS, false);
var navControl = ge.getNavigationControl();
navControl.setVisibility(ge.VISIBILITY_SHOW);
var la = ge.createLookAt('');
la.set(12.3456789,12.3456789, 0,
ge.ALTITUDE_RELATIVE_TO_GROUND, 50, 60, 1500);
ge.getView().setAbstractView(la);
}

function failureCallback(errorCode) {
alert("Failure loading the Google Earth Plugin: " +
errorCode);
}

function PreviewTour() {
var kmlString = ''
+ '<?xml version="1.0" encoding="UTF-8"?>'
+ '<kml xmlns="http://www.opengis.net/kml/
2.2">'
+ ' <gx:Tour>'
+ ' <name>Bounce tour example</name>'
+ ' <gx:Playlist>'
+ ' <gx:FlyTo>'
+ ' <gx:duration>4.0</gx:duration>'
+ ' <LookAt>'
+ ' <longitude>12.3456789</longitude>'
+ ' <latitude>12.3456789</latitude>'
+ ' <altitude>0</altitude>'
+ ' <range>94.16461321487679</range>'
+ ' <tilt>78.21836769986142</tilt>'
+ ' <heading>60.84999771501919</heading>'
+ ' <altitudeMode>relativeToGround</
altitudeMode>'
+ ' <gx:altitudeMode>relativeToSeaFloor</
gx:altitudeMode>'
+ ' </LookAt>'
+ ' </gx:FlyTo>'
+ ' </gx:Playlist>'
+ ' </gx:Tour>'
+ '</kml>';
var kmlObject = ge.parseKml(kmlString);
tour = ge.getFeatures().appendChild(kmlObject);
ge.getTourPlayer().setTour(tour);
ge.getTourPLayer().play();
}
/*-------------------------[END] GoogleEarth Javascript
[END]--------------------------------------*/

Dakine83

unread,
Jan 21, 2010, 4:57:12 PM1/21/10
to KML Developer Support - Google Earth Plug-in
For anyone who's interested, it seems that the "Error calling method
on NPObject!" error is thrown when there is a problem with the
formatting of the KML String. the <kml> tag should have looked like
this:

+ '<kml xmlns="http://www.opengis.net/kml/2.2"'
+ ' xmlns:gx="http://www.google.com/kml/ext/2.2">'

Notice I was missing the xmlns:gx declaration.

Side Note:
The other odd thing was that I fixed this line, and tested it several
times and it still didn't work. I got frustrated and worked on
something else, restarted the computer to install an update, and then
this just worked, like there's some weird caching going on. I noticed
the same behavior with fetchKml - I was loading up a KML file and
after manipulating the file in notepad, the tour I was working on
would not reflect the changes. I even deleted the file entirely, and
still the tour worked. I closed the browser, re-opened it (FireFox,
btw) and still the tour played. Only after Ending the firefox task
completely and reopening the browser did it fail.

hope this helps someone out in the future.

- Chris
Reply all
Reply to author
Forward
0 new messages