Sigh, more bugs, more new versions:
/**
* Search a geometry hierarchy for a geometry with the given id.
*
* @param geometry The geometry to start the search from.
* @param id The id of the geometry to find.
* @return The found geometry or null if not found.
*/
function getGeometryById(geometry, id) {
var geom;
var list;
var i;
if (geometry.getId() == id) return geometry;
if (geometry.getType() == "KmlMultiGeometry") {
if (geometry.getGeometries().hasChildNodes()) {
list = geometry.getGeometries().getChildNodes();
for (i = 0; i < list.getLength(); i++) {
geom = list.item(i);
geom = getGeometryById(geom, id);
if (geom != null) return geom;
}
}
} else if (geometry.getType() == "KmlPolygon") {
if (geometry.getOuterBoundary().getId() == id) return
geometry.getOuterBoundary();
if (geometry.getInnerBoundaries().hasChildNodes()) {
list = geometry.getInnerBoundaries().getChildNodes();
for (i = 0; i < list.getLength(); i++) {
geom = list.item(i);
geom = getGeometryById(geom, id);
if (geom != null) return geom;
}
}
}
return null;
}
/**
* Search a feature hierarchy for a feature or geometry with the given
id.
*
* @param feature The toplevel feature (or a GEPlugin) to search.
* @param id The id of the feature or geometry to find.
* @return The found feature or geometry or null if not found.
*/
function getItemById(feature, id) {
var i;
var list;
var geom;
var sub_feature;
if (feature.getType() != "GEPlugin") {
if (feature.getId() == id) return feature;
if (feature.getType() != "KmlFolder") {
geom = getGeometryById(feature.getGeometry(), id);
if (geom != null) return geom;
}
}
if ((feature.getType() == "GEPlugin" || feature.getType() ==
"KmlFolder" || feature.getType() == "KmlDocument") &&
feature.getFeatures().hasChildNodes()) {
list = feature.getFeatures().getChildNodes();
for (i = 0; i < list.getLength(); i++) {
sub_feature = getItemById(list.item(i), id);
if (sub_feature != null) return sub_feature;
}
}
return null;
}
/**
* Search a feature hierarchy for a feature with the given id.
*
* @param feature The toplevel feature (or a GEPlugin) to search.
* @param id The id of the feature to find.
* @param recursive true = search the whole hierarchy,
* false = search just the children of the given feature.
* @return The found feature or null if not found.
*/
function getFeatureById(feature, id, recursive) {
var i;
var list;
var sub_feature;
if (typeof recursive == 'undefined') {
recursive = false;
}
if (feature.getType() != 'GEPlugin' && feature.getId() == id) {
return feature;
}
if ((feature.getType() == 'GEPlugin' || feature.getType() ==
'KmlFolder' || feature.getType() == 'KmlDocument') &&