Google has now stopped its Earth API and Maps API is a paid for API nowadays. Some capabilities have also been either removed or changed. Therefore, I had to remove all examples of VizMap applications I had created. I didn’t remove the entire topic as I thought some of the code may still be useful with some modifications. 

javaScript: Flying around and asynchronicity in google Earth

This relates to Data Driven Mapping applications and the Javascript HowTo section

Google Earth Api

You will find tons of content on Google Earth , most of which is described much better than I can. In this section I will cover the small items of interest that I found to be hard to track down when I was developing this application (now deprecated)

Checking if the the Google Earth Plugin is installed

Not everyone will have the google earth plug-in. Here is how to check whether it is installed
// mcpherEarth

   if ({  
    return this;
   else {
    alert("you need to install the google earth plug-in");
    return null;

Creating an Instance

Because I am using the same code for google maps and google earth, I have some wrapper objects so I can  add extra properties. In this case mcpherEarth is my wrapper object for the Earth Instance.
mcpherEarth.prototype.createInstance  = function (div) {
  var ve=this;
  var vm = this.vMap;
  ve.container = div;
  vm.statusUpdate('..creating google earth instance',true,null);,  
    initCallback, failureCallback);
I had originally planned for the success and failure callbacks to be methods of this wrapper object but I just could not get that to work, so i created a couple of regular functions which in turn called back the methods I had originally wanted to use.
function initCallback (instance) {;
 function failureCallback (errorCode) {;

Success Callback

In the google maps version of the application, it’s okay to create a bounding box and leave it to the user to select which marker to go to. On Google Earth it’s not so practical, so I decided to zoom into the the first data spot as the initial view.
mcpherEarth.prototype.success  = function (instance) {
  var ve = this;
  var vm = ve.vMap;
  // the first spot
  var spot = vm.spots[0]; = ge = instance;
  // add some layers
  ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
  vm.statusUpdate(' earth successfully created',false,null);
  // go to the first spot


Creating a lookAt

This is the position that we will look at, and will be associated with a placemark.
mcpherEarth.prototype.makeLookAt = function (spot) {
  var ve= this;
  var ge =;
  var vm = this.vMap;
  // look at something
  var lookAt = ge.getView().copyAsLookAt (ge.ALTITUDE_RELATIVE_TO_GROUND); 
  // Set the position values
  return (lookAt);

Note that the range and tilt have been supplied as part of the control framework

         "provider":"google maps",

Creating a placemark and using a custom icon

Each spot in our input data will get a marker placed on google earth. Each placemark is associated with a ‘lookAt’. I also provide the capability to change the marker to a link specified in the input data.
mcpherEarth.prototype.makePlacemark = function (spot) {
  var ge=;
  var vm = this.vMap;
  var uItem = vm.items[spot.usingIndex];
  var marker = vm.spotControl['earth marker'];

  var placemark = ge.createPlacemark('');

  // Create style map for placemark
   var image = uItem.cJobject[marker];
   if (image) {
    if (mcpherIsImage(image)){
     var icon = ge.createIcon('');
     var style = ge.createStyle('');
     // make marker bigger than usual
     if (vm.control.placemarkscale){
      var x;
    else {
     alert (image + ' is not a valid image link to use as a marker');

The marker image is specified in the spots framework

         "earth marker":"Venue Photo",
         "maps marker":""
Venue Photo refers to an entry in the VizMap Dictionary that will be used as the marker.

Putting all that together

Each spot in the input data needs a placemark and a lookAt
mcpherEarth.prototype.plotSpot = function (spot) {
  var ve = this;
  spot.lookAt = ve.makeLookAt(spot);
  spot.placemark = ve.makePlacemark (spot);

Viewing the LookAt

The final step is to view the lookAt.
mcpherEarth.prototype.showLookAt = function (spot) {
  var lookAt = spot.lookAt;;
  return (lookAt);

Marker click event

When one of my markers is clicked I bring up a tabbed infowindow. Tabbed infowindows are not supported directly by Google Maps V3. See Creating a tabbed Google Mapping InfoWindow for how to do this.
However, I also added a doubleclick event that caused me many problems. So much so I decided to create a sectino all of its own, see Click events in Google Earth

Creating a balloon

In the case of both Maps and Earth, it is possible to assign a div element to the content of a balloon or infoWindow. It is this capability that has allowed this application to embed controls, visualizations and other content in these info windows. Earth is simpler than Maps, in that we don’t need to deal with the domready event.
mcpherSpot.prototype.createInfoWindow = function (startTabIndex){
  //default is the first tab
  var vm = this.parent;
  var spot=this;
  var gMap =;
  var uItem = vm.items[spot.usingIndex];
  var infoTab = uItem.infoTabs[startTabIndex];

  vm.statusUpdate('..creating info for '+spot.title,true);
  // select the appropriate tab
  // set the content
  var iDiv = document.createElement('div');
  this.container = iDiv;
  iDiv.appendChild (uItem.container);
  iDiv.className = vm.cssShow + ' ' + vm.cssInfoWindow;

  switch (vm.provider){
  case 'maps':
   var iw = spot.infoWindow = new google.maps.InfoWindow (); 
   iw.setContent (iDiv);,spot.marker);
   var s= '..plotted info for '+spot.title;
   google.maps.event.addListener(iw, 'domready', function() {
  case 'earth':
   var ge =;
   var iw = spot.balloon = ge.createHtmlDivBalloon('');
   var s= '..plotted info for '+spot.title;
   alert ('createinfowindowinstanity');
  return (iw);

Deleting a balloon

In Maps, closing an infowindow deletes it. This is an action performed on the infoWindow. For Earth you use an instance level method – setBaloon(null)
mcpherInfoTab.prototype.gotoAnotherSpot = function (spot,newSpot) {  
        var vm = spot.parent;
  if (newSpot.spotIndex != spot.spotIndex ){
    vm.statusUpdate('change spot from '+
      spot.title + ' to '+ newSpot.title,true,null); 
   switch (vm.provider){
   case 'maps':
   case 'earth':
    var ve = vm.vEarth;;
   vm.statusUpdate('changed spot from '+
     spot.title + ' to '+ newSpot.title,false,null); 

As usual questions, feedback and comments are welcome at our forum. Now lets take a look at more javaScript snippets from this application

For help and more information join our forum, follow the blog, follow me on Twitter