getting features from networklinks within API

29 views
Skip to first unread message

tristan

unread,
Aug 26, 2008, 1:35:18 AM8/26/08
to KML Developer Support - Google Earth Browser Plugin
hello,

I'm loading a series of networklinks, and each contains several dozen
placemarks.

What I'd like to do is be able to modify the placemarks from within
the API, changing their icon styles and such.

KmlFolder's have the getFeatures() member, but networklinks do not
possess such a thing.

this is a spinoff of a function from fraser in another thread, seems
to be a good way to check what's going on...
--------------------------------------------------------------------------------------------
function regionKml() {
var node = ge.getFeatures().getFirstChild();

function traverseKml(node) {
if(node.getFeatures().hasChildNodes()) {
var subNodes = node.getFeatures().getChildNodes();
var length = subNodes.getLength();
for(var i = 0; i < length; i++) {
var eachSubNode = subNodes.item(i);
var nodeType = eachSubNode.getType();
var nodeName = eachSubNode.getName();
var nodeID = eachSubNode.getId();
switch(nodeType) {
case 'KmlNetworkLink' :
alert(eachSubNode.getKml())
break;
case 'KmlFolder' :
traverseKml(eachSubNode);
break;
}
}
}
}
traverseKml(node);
}
--------------------------------------------------------------------------------------------
unfortunately, it seems the furthest I can go into those networklinks
is to go:
networklink.getLink().getHref()
but that's not even close to the contents of the networklink...am I
missing something here?



The KML for one of these nwl's looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<NetworkLink id="1">
<name>North America</name>
<Camera id="1">
blah blah...
</Camera>
<Region id="1">
blah blah...
</Region>
<Link id="1">
<href>http://www.[URL to a bunch of placemarks].kml</href>
<viewRefreshMode>onRegion</viewRefreshMode>
</Link>
</NetworkLink>
</kml>


Any ideas appreciated!

shsavage

unread,
Aug 26, 2008, 11:37:59 AM8/26/08
to KML Developer Support - Google Earth Browser Plugin
Hi Tristan,

If you were to store your point data in a database instead of in
kml, you could manipulate it on the fly. See http://gaialab.asu.edu/exoplanets
for an example. The very long list of planets is loaded up by a very
short php routine that writes the javascript dynamically into the
loadPlanets function. You could set up all the different icons as the
example shows, and then assign them based on the contents of one of
the table columns (in the example, I use the star's main spectral type
as the icon determinate, and I've set up the style maps with the same
names as the values in the table column, so it's a breeze. If you did
something similar, you could change them at will. Note that the
example also uses Ajax calls to load the top and right hand divs on
the page with information when the user clicks a star icon on the
map. It's deceptively simple to do with the loadAjax function and a
very short php program that fetches and formats the data on the
server, then sends it back to the browser.

-Steve

On Aug 25, 10:35 pm, tristan wrote:
> hello,
>
> I'm loading a series of networklinks, and each contains several dozen
> placemarks.
>
> What I'd like to do is be able to modify the placemarks from within
> the API, changing their icon styles and such.
>
> KmlFolder's have the getFeatures() member, but networklinks do not
> possess such a thing.
>
> this is a spinoff of a function from fraser in another thread, seems
> to be a good way to check what's going on...
> ---------------------------------------------------------------------------­-----------------
> function regionKml() {
>         var node = ge.getFeatures().getFirstChild();
>
>         function traverseKml(node) {
>                 if(node.getFeatures().hasChildNodes()) {
>                         var subNodes = node.getFeatures().getChildNodes();
>                         var length = subNodes.getLength();
>                         for(var i = 0; i < length; i++) {
>                                 var eachSubNode = subNodes.item(i);
>                                 var nodeType = eachSubNode.getType();
>                                 var nodeName = eachSubNode.getName();
>                                 var nodeID = eachSubNode.getId();
>                                 switch(nodeType) {
>                                         case 'KmlNetworkLink' :
> alert(eachSubNode.getKml())
>                                         break;
>                                         case 'KmlFolder' :
>                                                 traverseKml(eachSubNode);
>                                         break;
>                                 }
>                         }
>                 }
>         }
>         traverseKml(node);}
>
> ---------------------------------------------------------------------------­-----------------
> unfortunately, it seems the furthest I can go into those networklinks
> is to go:
> networklink.getLink().getHref()
> but that's not even close to the contents of the networklink...am I
> missing something here?
>
> The KML for one of these nwl's looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://earth.google.com/kml/2.2">
> <NetworkLink id="1">
>         <name>North America</name>
>         <Camera id="1">
> blah blah...
>         </Camera>
>         <Region id="1">
> blah blah...
>         </Region>
>         <Link id="1">
>                 <href>http://www.[URLto a bunch of placemarks].kml</href>
Message has been deleted

fraser

unread,
Aug 26, 2008, 3:01:46 PM8/26/08
to KML Developer Support - Google Earth Browser Plugin
Hey Tristan,

The reason that you can't access the placemarks from your network link
is because they are not features of it...

The placemarks are in fact features of the kml file loaded from the
<href> element of your networklink (i.e. http://www.[URL to a bunch
of placemarks].kml)...
To access the placemarks/features of this file you can use fetchKml()
on the url returned by getHref()...

Something like this....
-----------------------------------------------------------------------------
switch(nodeType) {
case 'KmlNetworkLink' :
google.earth.fetchKml(ge, eachSubNode.getLink().getHref(),
function(object) {
if (!object) {
alert('bad or NULL kml');
return;
}
//now we can access the features from the the kml file...
traverseKml(object);
});
break;
case 'KmlFolder' :
//etc...
-----------------------------------------------------------------------------

Sorry, there maybe some typos in there!

Anyway, I'm sure you get the idea, hope that helps...

Regards,

Fraser.

On Aug 26, 6:35 am, tristan wrote:
> hello,
>
> I'm loading a series of networklinks, and each contains several dozen
> placemarks.
>
> What I'd like to do is be able to modify the placemarks from within
> the API, changing their icon styles and such.
>
> KmlFolder's have the getFeatures() member, but networklinks do not
> possess such a thing.
>
> this is a spinoff of a function from fraser in another thread, seems
> to be a good way to check what's going on...
> ---------------------------------------------------------------------------­-----------------
> function regionKml() {
>         var node = ge.getFeatures().getFirstChild();
>
>         function traverseKml(node) {
>                 if(node.getFeatures().hasChildNodes()) {
>                         var subNodes = node.getFeatures().getChildNodes();
>                         var length = subNodes.getLength();
>                         for(var i = 0; i < length; i++) {
>                                 var eachSubNode = subNodes.item(i);
>                                 var nodeType = eachSubNode.getType();
>                                 var nodeName = eachSubNode.getName();
>                                 var nodeID = eachSubNode.getId();
>                                 switch(nodeType) {
>                                         case 'KmlNetworkLink' :
> alert(eachSubNode.getKml())
>                                         break;
>                                         case 'KmlFolder' :
>                                                 traverseKml(eachSubNode);
>                                         break;
>                                 }
>                         }
>                 }
>         }
>         traverseKml(node);}
>
> ---------------------------------------------------------------------------­-----------------
> unfortunately, it seems the furthest I can go into those networklinks
> is to go:
> networklink.getLink().getHref()
> but that's not even close to the contents of the networklink...am I
> missing something here?
>
> The KML for one of these nwl's looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://earth.google.com/kml/2.2">
> <NetworkLink id="1">
>         <name>North America</name>
>         <Camera id="1">
> blah blah...
>         </Camera>
>         <Region id="1">
> blah blah...
>         </Region>
>         <Link id="1">
>                 <href>http://www.[URLto a bunch of placemarks].kml</href>

tristan

unread,
Aug 26, 2008, 3:06:45 PM8/26/08
to KML Developer Support - Google Earth Browser Plugin
ahhh, thanks for the responses guys!
that helps a ton! back to work!

On Aug 26, 1:01 pm, fraser wrote:
> Hey Tristan,
>
> The reason that you can't access the placemarks from your network link
> is because they are not features of it...
>
> The placemarks are in fact features of the kml file loaded from the
> <href> element of your networklink  (i.e.http://www.[URLto a bunch
> >                 <href>http://www.[URLtoa bunch of placemarks].kml</href>

tristan

unread,
Aug 27, 2008, 3:27:10 PM8/27/08
to KML Developer Support - Google Earth Browser Plugin
looks like when using fetchKml() and recursively going thru the
contents of a networklink, it's just loading up a fresh copy of the
kml(placemarks incl), as opposed to referencing the data on the globe
currently...I wonder if the networklink's markers on the globe are
stored in a cache somewhere else?
who knows, but using php to quickly hard-code each marker into the
javascript should do the job nicely

On Aug 26, 1:06 pm, tristan wrote:
> ahhh, thanks for the responses guys!
> that helps a ton! back to work!
>
> On Aug 26, 1:01 pm, fraser wrote:
>
> > Hey Tristan,
>
> > The reason that you can't access the placemarks from your network link
> > is because they are not features of it...
>
> > The placemarks are in fact features of the kml file loaded from the
> > <href> element of your networklink  (i.e.http://www.[URLtoa bunch
> > >                 <href>http://www.[URLtoabunch of placemarks].kml</href>

TinyGrasshopper

unread,
Aug 27, 2008, 5:46:21 PM8/27/08
to KML Developer Support - Google Earth Browser Plugin
You could use fetchKml to load the placemarks and then add them to the
globe yourself via plugin.getFeatures().addChild(...) rather than
loading them via a network link
> > > >                 <href>http://www.[URLtoabunchof placemarks].kml</href>

Roman N

unread,
Aug 28, 2008, 2:07:08 PM8/28/08
to KML Developer Support - Google Earth Browser Plugin
Quick typo correction:

appendChild, not addChild :-)

Good thread, all around.

- Roman
> > > > >                 <href>http://www.[URLtoabunchofplacemarks].kml</href>
Reply all
Reply to author
Forward
0 new messages