Reputation: 10624
I am trying to get the Google Earth callbacks to work, but they don't seem to be firing for me. I've used the View Change Example at the Google Earth API site as a reference, and see no difference between it and my code... yet mine doesn't work!
Here are the important bits of my code:
<script type="text/javascript">
var ge;
google.load("earth", "1");
function init() {
document.getElementById('map3d').innerHTML = '';
google.earth.createInstance('map3d', initCallback, failureCallback);
}
function initCallback(pluginInstance) {
ge = pluginInstance;
ge.getWindow().setVisibility(true);
// add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
// Set the FlyTo speed.
ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
// add some layers
//ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
//ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
throw (new Error("InitCallback!"));
google.earth.addEventListener(ge.getView(), 'viewchange', function () {
throw (new Error("EVENT!"));
});
}
function failureCallback(errorCode) {
}
</script>
The "InitCallback!" error is thrown properly, but I never see the "EVENT!" error thrown -- no matter how much I move the globe around.
Does anyone see what I'm doing wrong? Any help is greatly appreciated!
Upvotes: 0
Views: 493
Reputation: 1265
lifeIsGood is right - when you throwing an error like you have above without a try catch block will cause the js after the thrown error not to execute.
instead use console.log('Error');
if you are simply trying to use a "quick-dirty way" to print something in the console...
function initCallback(pluginInstance) {
ge = pluginInstance;
ge.getWindow().setVisibility(true);
//throw (new Error("InitCallback!")); -- change this to
console.log('InitCallback!');
google.earth.addEventListener(ge.getView(), 'viewchange', function () {
//throw (new Error("EVENT!")); -- change this to
console.log('EVENT!');
});
}
Upvotes: 1
Reputation: 1229
I'm no expert on javascript stuff, but if you replace:
throw (new Error("EVENT!"));
with an alert instead eg:
alert('EVENT!');
I bet you will find it will work. ie the eventListener IS working, it just doesn't seem to like the 'throw' command
Upvotes: 2