Friday, June 06, 2008

Thoughts on the Google earth plugin API

Good job Google earth/maps team.

While it feels like they rushed the introduction of the earth plugin a bit, leaving pretty spotty documentation of the API and only a Windows version, it is indeed a great first step. Putting javascript tendrils deep into the control structure of the plugin was inspired and will be transformative.

However, the programmer in me can't help but be a little offended by the size and verbosity of the interface. Am I to understand that the very first example of creating a placemark is what will be needed for such a simple task?

var placemark = ge.createPlacemark('');
placemark.setName("You are at Google");
ge.getFeatures().appendChild(placemark);

// Create style map for placemark
var normal = ge.createIcon('');
normal.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
var iconNormal = ge.createStyle('');
iconNormal.getIconStyle().setIcon(normal);
var highlight = ge.createIcon('');
highlight.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
var iconHighlight = ge.createStyle('');
iconHighlight.getIconStyle().setIcon(highlight);
var styleMap = ge.createStyleMap('');
styleMap.setNormalStyle(iconNormal);
styleMap.setHighlightStyle(iconHighlight);
placemark.setStyleSelector(styleMap);

// Create point
var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
var point = ge.createPoint('');
point.setLatitude(la.getLatitude());
point.setLongitude(la.getLongitude());
placemark.setGeometry(point);


Admittedly it uses the super-annoying StyleMap which I feel should be abolished. Don't you think it is too much to ask to perform this kind of operation for every placemark? I suppose someone could create a wrapper library for this to simplify common tasks.

How about implementing this in your API instead:
ge.addPlacemark({
name:'You are at Google',
Style:{IconStyle:{Icon:{href:'http://maps.google.com/mapfiles/kml/paddle/red-circle.png'}}},
Point:{coordinates:{lon,lat,alt}}
});


Could the maps/earth team create the nicer interface wrapper?

6 comments:

Tristan said...

I'm really loving the new Earth API, but youre right, the documentation is spotty at best.

i really like your idea about simplifying the whole style/stylemap process!!
i messed around with it for a bit, but then decided it was a good time to change all my xml and loading crap to kml which has really cleaned things up a lot. doesnt do much for 'on demand' editing after the page loads tho, which i think is where your idea would be really handy.

Darrell said...

Agreed on the lack of documentation - I'm surprised that Google haven't shown the basic example of how to generate a DIV balloon (old style htmlinfowindow) on clicking a placemark. If anybody has the solution already then I'd appreciate an update - I'll have a look at it today and post back again if it comes together successfully.

Great plugin though for website integration - rushed to market maybe as you say.

Darrell said...

So I got it working after a few hours of head-banging. For those interested, you can take a look at my associated page link below and view source to see the code (I'm not claiming to be the most efficient coder in the world - any tips welcome):

www.grundlefly.com/travel_earth.html

For my Earth map I use an xml file to hold all of the world locations, coordinates etc. - similar to how it is done in the similar google maps code on the normal travel page. This works well with similar code.

One refinement still to work out is how to have the placemark labels {as achieved by "placemark.setName(title);"} but to suppress the associated popup window on click as it interferes with the workings of the htmldivballoon. Anybody got any ideas?

Darrell said...

I found the answer on another forum some time ago, but will include here also for those interested:

Within the function in google.earth.addEventListener, add the following line:
event.preventDefault();

batty699 said...

3d videos becoming very popular right now. You know, the one you can turn over yourself to choose the spot from which you want to observe the whole picture, the whole scene, Soon the same thing might be added on the teen xxx zone. Just imagine, the sex where you can be everywhere!

Taylor Bell said...

his is my first time i visit here. http://www.hinegologtruskavets.com I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.