You can modify your current walkKmlDom
implementation as that is already walking the kml dom and checking for Placemarks. i.e.
walkKmlDom(fetchedKml, function() {
if (this.getType() == 'KmlPlacemark' && this.getID().toLowerCase() == curr_pm.toLowerCase()) {
obj_pm = this;
return false; // stop the DOM walk here.
}
Simply use that to build a list of links to the placemarks. You can use getUrl
on the placemark object to do this. See https://developers.google.com/earth/documentation/accessors
var links = [];
walkKmlDom(fetchedKml, function() {
if (this.getType() == 'KmlPlacemark') {
// create a link to the placemark
links.push('<a href="javascript:void(0);" onclick="flyto(' + this.getUrl() + ')"> ' + this.getName() + ' </a>');
// rest of your current conditional logic here
// if(this.getID().toLowerCase()) etc..
}
}
// do something with links...
for (index = 0; index < links.length; ++index) {
console.log(links[index]);
}
Then you need to implement the flyto
helper function to actually fly to the locations and open the balloons when the links are clicked. Something like the following should work.
var flyto = function(url) {
// close any currently open balloon.
ge.setBalloon(null);
// find the placemark from the url parameter
var placemark = ge.getElementByUrl(url);
if(placemark == null) {
console.log("Placemark is null: " + url);
return;
}
// create a lookat based on that feature's geometry
var lookAt = ge.createLookAt('');
lookAt.setLatitude(placemark.getGeometry().getLatitude());
lookAt.setLongitude(placemark.getGeometry().getLatitude())
// Update the view in Google Earth using the lookat
ge.getView().setAbstractView(lookAt);
// open the feature's balloon
ge.setBalloon(placemark.getBalloon());
}