<!-- We'll need to walk the DOM looking for a KmlTour later --> <script src="http://earth-api-samples.googlecode.com/svn/trunk/lib/kmldomwalk.js" type="text/javascript"></script> <!-- Very basic slider --> <script src="static/simple-slider.js" type="text/javascript"></script> <link href="static/simple-slider.css" type="text/css" rel="stylesheet"/>
// create the tour by fetching it out of a KML file
var href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + '/';
href += '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') {
ge.getTourPlayer().setTour(this);
return false; // stop the DOM walk here.
}
});
// make the slider for dragging the tour timeline
var slider = new SimpleSlider(document.getElementById('slider-container'), {
onSlide: function(pos) {
ge.getTourPlayer().setCurrentTime(pos);
},
max: ge.getTourPlayer().getDuration(),
formatPosFn: formatTime
});
window.setInterval(function() {
slider.setPosition(ge.getTourPlayer().getCurrentTime());
}, 50);
}); function playTour() {
ge.getTourPlayer().play();
}
function pauseTour() {
ge.getTourPlayer().pause();
}
function resetTour() {
ge.getTourPlayer().reset();
}
function formatTime(sec) {
var pad2 = function(n) {
return (n < 10) ? '0' + n : n;
};
sec = Math.floor(sec);
var min = Math.floor(sec / 60);
sec = sec % 60;
var hrs = Math.floor(min / 60);
min = min % 60;
var str = '';
str += hrs
return (hrs ? (hrs + ':' + pad2(min)) : min) + ':' + pad2(sec);
}