How can I get the KML feature objects & their IDs (point/polygon/line placemarks) when the KML is parsed and appended to GEPlugin through Network Link?

161 views
Skip to first unread message

Shiva

unread,
Jun 4, 2009, 1:27:32 AM6/4/09
to KML Developer Support - Google Earth Plug-in
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

Roman N

unread,
Jun 4, 2009, 9:34:28 PM6/4/09
to KML Developer Support - Google Earth Plug-in
Hi Shiva,

The current best workaround for the inability to traverse
KmlNetworkLinks is to get the network link's URL and manually get its
DOM using fetchKml.

Hope that helps,
Roman

>  and using the following JavaScript function from :-http://groups.google.com/group/google-earth-browser-plugin/browse_thr...

> <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"

Shiva

unread,
Jun 5, 2009, 12:13:52 AM6/5/09
to KML Developer Support - Google Earth Plug-in
Hello Roman N,

If we do as you have suggested above, will it be the same placemark
object that has been added to the GEPlugin through NetworkLink? I need
the placemark object to change its attributes such as color,linestyle,
etc..

Regards,
Shiva

Roman N

unread,
Jun 6, 2009, 12:26:04 AM6/6/09
to KML Developer Support - Google Earth Plug-in
Hi Shiva,

Ah, sorry, in that case no; there's no workaround yet. Also,
surprisingly, the feature request for network link DOM traversal isn't
posted in the issue tracker.

Would you like to request it at: http://code.google.com/p/earth-api-samples/issues/list
?

Thanks,
Roman
> ...
>
> read more »

Shiva

unread,
Jun 6, 2009, 5:59:45 AM6/6/09
to KML Developer Support - Google Earth Plug-in
Hello Roman N,

I have posted this feature request on Official Google Earth API
samples and Earth API Issue Tracker, ID/Issue No - 260.

Regards,
Shiva
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages