Hello Everybody,
I am using the following JavaScript code to add the KML file
consisting of some polygon placemarks with unique IDs :
function loadKML(){
if(testLocation){
ge.getFeatures().removeChild(testLocation);
}
testLocation = ge.parseKml('<?xml version="1.0"
encoding="utf-8"?>'+
'<kml xmlns="
http://www.opengis.net/
kml/2.2">'+
'<Document>'+
'<name>dynamicKMLLayer</
name>'+
'<description>Dynamic KML
Layer</description>'+
'<NetworkLink>'+
'<flyToView>1</flyToView>'+
'<Link>'+
'<href>
http://dev12:8080/
locate/kml/polygon.kml</href>'+
'</Link>'+
'</NetworkLink>'+
'</Document>'+
'</kml>');
ge.getFeatures().appendChild(testLocation);
}
and using the following JavaScript function from :-
http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/5a3e09add9bd4a7b#
function getFeatureById(feature, id, recursive) {
var i;
var list;
var geom;
if (typeof recursive == 'undefined') {
recursive = false;
}
if (feature.getType() != 'GEPlugin' && feature.getId() == id)
{
return feature;
}
if ((feature.getType() == 'GEPlugin' || feature.getType() ==
'KmlFolder') && feature.getFeatures().hasChildNodes()) {
list = feature.getFeatures().getChildNodes();
for (i = 0; i < list.getLength(); i++) {
if (recursive) {
sub_feature = getFeatureById(list.item
(i), id, recursive);
if (sub_feature != null) return
sub_feature;
} else if (list.item(i).getId() == id) {
return list.item(i);
}
}
}
return null;
}
The above function iterates up to KmlNetworkLink object of the 1st
function listed above and then does not go in to KML file added
through the NetworkLink tag.
'polygon.kml' KML file
--------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="
http://www.opengis.net/kml/2.2" xmlns:gx="http://
www.google.com/kml/ext/2.2" xmlns:kml="
http://www.opengis.net/kml/2.2"
xmlns:atom="
http://www.w3.org/2005/Atom">
<Document>
<name>polygon.kml</name>
<StyleMap id="msn_ylw-pushpin">
<Pair>
<key>normal</key>
<styleUrl>#sn_ylw-pushpin</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_ylw-pushpin0</styleUrl>
</Pair>
</StyleMap>
<StyleMap id="msn_ylw-pushpin0">
<Pair>
<key>normal</key>
<styleUrl>#sn_ylw-pushpin0</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_ylw-pushpin</styleUrl>
</Pair>
</StyleMap>
<Style id="sh_ylw-pushpin">
<IconStyle>
<scale>1.3</scale>
<Icon>
<href>
http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</
href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<LineStyle>
<width>1.8</width>
</LineStyle>
<PolyStyle>
<fill>0</fill>
</PolyStyle>
</Style>
<Style id="sh_ylw-pushpin0">
<IconStyle>
<scale>1.3</scale>
<Icon>
<href>
http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</
href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<LineStyle>
<width>1.8</width>
</LineStyle>
<PolyStyle>
<fill>0</fill>
</PolyStyle>
</Style>
<Style id="sn_ylw-pushpin">
<IconStyle>
<scale>1.1</scale>
<Icon>
<href>
http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</
href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<LineStyle>
<width>1.8</width>
</LineStyle>
<PolyStyle>
<fill>0</fill>
</PolyStyle>
</Style>
<Style id="sn_ylw-pushpin0">
<IconStyle>
<scale>1.1</scale>
<Icon>
<href>
http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</
href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<LineStyle>
<width>1.8</width>
</LineStyle>
<PolyStyle>
<fill>0</fill>
</PolyStyle>
</Style>
<Folder>
<name>myKMLs</name>
<Placemark id="poly1">
<name>Kanteerava</name>
<styleUrl>#msn_ylw-pushpin0</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>
77.59330407645275,12.969115127324,0
77.59395709129615,12.96927809927677,0
77.59376065255988,12.9701214017215,0
77.59313949024327,12.97001275242579,0
77.59330407645275,12.969115127324,0 </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark id="poly2">
<name>Chinnaswamy</name>
<styleUrl>#msn_ylw-pushpin</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>
77.59940431173146,12.97835201657393,0
77.59997576416551,12.97835200545365,0
77.60004410734928,12.9791630749117,0
77.59923661887149,12.97919940696482,0
77.59940431173146,12.97835201657393,0 </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Folder>
</Document>
</kml>
How can I get the above function to get polygon.kml file's placemark
objects and their IDs? Is there any other way to achieve it?
Regards,
Shiva