Google Earth JavaScript API v1.009 new features not working

272 views
Skip to first unread message

NitrousDigital

unread,
Jan 28, 2012, 11:48:14 AM1/28/12
to google-earth-...@googlegroups.com
I am having problems executing most of the new Google Earth JavaScript API v1.009  features mentioned in the release notes found here: http://code.google.com/apis/earth/documentation/releasenotes.html.

I have created the following JavaScript demo that can be executed by pasting it into the Google Code playground code editor found here: http://code.google.com/apis/ajax/playground/#playing_tours

My environment is:
* Mac OS X 10.6.8
* Firefox 9.0.1
* GE API 1.009
* GE plugin 6.2.0.5905

The results of my tests are as follows:

         // result: FAILURE - Error calling method on NPObject!
    ge.getTourPlayer().setLoop(1);

    // result: FAILURE - geTourPlayer.getSpeed is not a function
    ge.getTourPlayer().getSpeed();

    // result: FAILURE - geTourPlayer.setSpeed is not a function
    ge.getTourPlayer().setSpeed(1);

    // result: SUCCESS - returns 0 or 1 depending on the current visibility of the tour player control
    ge.getTourPlayer().getControl().getVisibility();

    // result: SUCCESS - shows the tour player control
    ge.getTourPlayer().getControl().setVisibility(1);



Here is the code that can be pasted in to the Google Code playground to test the new features of the 1.009 API:

    var ge;
   
    var tour = null;
   
    google.load("earth", "1");
   
    function init() {
      google.earth.createInstance('map3d', initCallback, failureCallback);
   
      addSampleButton('Enter Tour', enterTour);
      addSampleButton('Play', playTour);
      addSampleButton('Pause', pauseTour);
      addSampleButton('Stop/Reset', resetTour);
      addSampleButton('Exit Tour', exitTour);
     
      // API 1.009 test buttons
      addSampleButton('Version Info', showVersion);
      addSampleButton('Set Loop', setLoop);
      addSampleButton('Get Speed', getSpeed);
      addSampleButton('Set Speed', setSpeed);
      addSampleButton('Get Control Visibility', getVisibility);
      addSampleButton('Set Control Visibility', setVisibility);
      }
   
    function initCallback(instance) {
      ge = instance;
      ge.getWindow().setVisibility(true);
   
      // add a navigation control
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
   
      // add some layers
      ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
      ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
   
      // create the tour by fetching it out of a KML file
      var href = 'http://earth-api-samples.googlecode.com/svn/trunk/examples/' +
                 'static/grandcanyon_tour.kmz';
   
      google.earth.fetchKml(ge, href, function(kmlObject) {
        if (!kmlObject) {
          // wrap alerts in API callbacks and event handlers
          // in a setTimeout to prevent deadlock in some browsers
          setTimeout(function() {
            alert('Bad or null KML.');
          }, 0);
          return;
        }
   
        // Show the entire KML file in the plugin.
        ge.getFeatures().appendChild(kmlObject);
   
        // Walk the DOM looking for a KmlTour
        walkKmlDom(kmlObject, function() {
          if (this.getType() == 'KmlTour') {
            tour = this;
            return false; // stop the DOM walk here.
          }
        });
      });
   
      document.getElementById('installed-plugin-version').innerHTML =
        ge.getPluginVersion().toString();
    }
   
    function failureCallback(errorCode) {
    }
   
    function enterTour() {
      if (!tour) {
        alert('No tour found!');
        return;
      }
   
      ge.getTourPlayer().setTour(tour);
    }
   
    function playTour() {
      ge.getTourPlayer().play();
    }
   
    function pauseTour() {
      ge.getTourPlayer().pause();
    }
   
    function resetTour() {
      ge.getTourPlayer().reset();
    }
   
    function exitTour() {
      ge.getTourPlayer().setTour(null);
    }
   

  /**
   * GE API 1.009 Test functions
   */

 
 function setLoop() {
     var geTourPlayer = ge.getTourPlayer();

     // result: Error calling method on NPObject!
     geTourPlayer.setLoop(1);
   }

   function getSpeed() {
     var geTourPlayer = ge.getTourPlayer();

     // result: geTourPlayer.getSpeed is not a function
     var speed = geTourPlayer.getSpeed();
     alert("Speed is " + speed);
   }

   function setSpeed() {
     var geTourPlayer = ge.getTourPlayer();

     // result: geTourPlayer.setSpeed is not a function
     geTourPlayer.setSpeed(3);
   }

   function getVisibility() {
     var geTourPlayer = ge.getTourPlayer();
     var geTourPlayerControl = geTourPlayer.getControl();
     
     var vis = geTourPlayerControl.getVisibility();
     alert("Tour Player Control Visibility is "+vis);
   }

   function setVisibility() {
     var geTourPlayer = ge.getTourPlayer();
     var geTourPlayerControl = geTourPlayer.getControl();
       
     var vis = geTourPlayerControl.getVisibility();
     geTourPlayerControl.setVisibility(vis == 0 ? 1 : 0);
   }

   function showVersion() {
     // output in my environment is "api version=1.009 plugin version=6.2.0.5905"
     alert("api version=" + ge.getApiVersion() + " plugin version=" + ge.getPluginVersion());

   }

     
   
 

Josh L

unread,
Jan 30, 2012, 6:23:42 PM1/30/12
to KML Developer Support - Google Earth Plug-in
Hi,

Thanks for the detailed report on this. The release notes had a typo,
and the reason get/setSpeed did not work is because the method is
actually get/setCurrentSpeed. The release notes will be updated
shortly with the correct syntax; thanks again for pointing this out.

In addition, these methods, like setLoop(), will only work if you have
already entered a tour -- if you attempt to call these without the
TourPlayer actually being loaded and ready, you will get an error.

Cheers,

-Josh

On Jan 28, 8:48 am, NitrousDigital wrote:
> I am having problems executing most of the new Google Earth JavaScript API
> v1.009  features mentioned in the release notes found here:http://code.google.com/apis/earth/documentation/releasenotes.html.
>
> I have created the following JavaScript demo that can be executed by
> pasting it into the Google Code playground code editor found here:http://code.google.com/apis/ajax/playground/#playing_tours
>
> My environment is:
> * Mac OS X 10.6.8
> * Firefox 9.0.1
> * *GE API 1.009 *
> * *GE plugin 6.2.0.5905*
>
> The results of my tests are as follows:
>
>          // result: FAILURE - Error calling method on NPObject!
>     ge.getTourPlayer().*setLoop*(1);
>
>     // result: FAILURE - geTourPlayer.getSpeed is not a function
>     ge.getTourPlayer().*getSpeed*();
>
>     // result: FAILURE - geTourPlayer.setSpeed is not a function
>     ge.getTourPlayer().*setSpeed*(1);
>
>     // result: SUCCESS - returns 0 or 1 depending on the current visibility
> of the tour player control
>     ge.getTourPlayer().getControl().*getVisibility*();
>
>     // result: SUCCESS - shows the tour player control
>     ge.getTourPlayer().getControl().*setVisibility*(1);
>   */****
>    * GE API 1.009 Test functions
>    */
>
>  *  function setLoop() {

NitrousDigital

unread,
Jan 30, 2012, 9:53:20 PM1/30/12
to google-earth-...@googlegroups.com
Thanks Josh,

I've noticed that the loop button in the tour controls does not update to reflect the state when modified via setLoop().
Is this something that is likely to be fixed?

Regards,

Nick

Josh L

unread,
Feb 3, 2012, 6:29:12 PM2/3/12
to KML Developer Support - Google Earth Plug-in
Can you file an issue in the public issue tracker?

Thanks,

-Josh
Reply all
Reply to author
Forward
0 new messages