Remove loaded network link

395 views
Skip to first unread message

mickmel

unread,
Jun 10, 2008, 11:31:14 PM6/10/08
to KML Developer Support - Google Earth Browser Plugin
I have a page that loads a network link when a link on the page is
clicked. How can I make it un-load that network link? What kind of
code does that need?

marquies

unread,
Jun 11, 2008, 2:41:48 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin

mickmel

unread,
Jun 11, 2008, 6:17:25 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin
That's getting me closer, but it's not working. I'm using a checkbox
to try to control the network link status. Checking the box turns it
on, but removing the check doesn't remove the network link. Here is
my code:

function shownlink()
{
var form = document.options;
var networkLink = ge.createNetworkLink("");
networkLink.setDescription("NetworkLink open to fetched content");
networkLink.setName("Open NetworkLink");
networkLink.setFlyToView(true);
var link = ge.createLink("");
link.setHref("http://www.mysite.com/mykml.kml");
networkLink.setLink(link);
if (form.mycheckbox.checked) {
ge.getGlobe().getFeatures().appendChild(networkLink);
} else {
ge.getGlobe().getFeatures().removeChild(networkLink);
}
}




On Jun 11, 2:41 am, marquies wrote:
> Seehttp://groups.google.com/group/google-earth-browser-plugin/browse_thr...
>
> Could help.
>
> regards
> marquieswww.GONICUS.de

jpwade_bsu

unread,
Jun 11, 2008, 6:41:07 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin
mickmel do you have an example page where remove.Child works?

.removeChild does not work on either of the 2 pages below



http://czmartin.com/jpw/asp_arcmap/gem_3d_netlink_multiple2.html


checked boxes at page load


if = ge.getFeatures().appendChild(networkLink);
else = ge.getFeatures().removeChild(networkLink);


**************


http://czmartin.com/jpw/asp_arcmap/gem_3d_netlink_multiple222.html


unchecked boxes at page load


if = ge.getGlobe().getFeatures().appendChild(networkLink);
else = ge.getGlobe().getFeatures().removeChild(networkLink);


joe


On Jun 9, 1:02 am, ManoM wrote:
> > > code does that need?- Hide quoted text -
>
> - Show quoted text -

mickmel

unread,
Jun 11, 2008, 8:19:32 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin
That's precisely my problem -- I can't get it to work.

sylehc

unread,
Jun 11, 2008, 8:51:20 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin
Hi mickmel, the "networkLink" variable is local to the showlink
"function". If you want to keep it local you need to use the Features
to scan the tree and find the correct child (network link). Otherwise
you must declare the variable outside the function (global). For
example insert the line
var networkLink = null;
at the beginning of your javascript removing the declaration inside
the function
--> var <-- networkLink = ge.createNetworkLink("");

sylehc

sylehc

unread,
Jun 11, 2008, 9:04:44 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin
Sorry mickmel, you have to check also the allocation of the network
link to avoid to make it several times:

function shownlink()
{
var form = document.options;
if (networkLink == null) {
networkLink = ge.createNetworkLink("");
networkLink.setDescription("NetworkLink open to fetched
content");
networkLink.setName("Open NetworkLink");
networkLink.setFlyToView(true);
var link = ge.createLink("");
link.setHref("http://www.mysite.com/mykml.kml");
networkLink.setLink(link);
}
if (form.mycheckbox.checked) {
ge.getGlobe().getFeatures().appendChild(networkLink);
} else {
ge.getGlobe().getFeatures().removeChild(networkLink);
}

}

The best solution should be to put the creation of the network link
outside and to use the function only to toggle the visibility.

sylehc.

mickmel

unread,
Jun 11, 2008, 9:08:44 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin
sylehc,

Perfect! It works exactly how I wanted it to. Thanks!

Mickey

Gerardo64

unread,
Jun 11, 2008, 11:42:40 AM6/11/08
to KML Developer Support - Google Earth Browser Plugin
Hi sylehc

Is necessary to say I don´t know javascript at all (just learning
now...)

I wanted to activate/desactivate trough check boxes, differents kml
files in the same GE map.

I already have some code working. And have the same problem as
mickmel: I check the box, see the kml file but when I uncheck it, he´s
still there..=)

I didn´t understand your previous explanation (I tried something with
that but didn´t work). So here is the code I have:

function updateOptions() {
var options = ge.getOptions();
var form = document.options;
options.setStatusBarVisibility(form.statusbar.checked);

The status bar works fine. Check=it shows, Uncheck=Dissapear - I don´t
know if I missing something there related with the NL....I mean, do I
need one "options" per object I want to check/uncheck?


Then I have the NL code:

if (form.barrios.checked) {
var networkLink = ge.createNetworkLink("");
networkLink.setDescription("NetworkLink open to fetched content");
networkLink.setName("Open NetworkLink");

var link = ge.createLink("");
link.setHref("http://My_KMZ_File.kmz");
networkLink.setLink(link);
ge.getFeatures().appendChild(networkLink);
}
else {
link.setHref("http://My_KMZ_File.kmz");
networkLink.setLink(link);
ge.getGlobe().getFeatures().removeChild(networkLink);
} }


And below, I have a div with this:

<input type="checkbox" onchange='updateOptions()' name="barrios" /
>Barrios Capital&nbsp;&nbsp;&nbsp;
<input type="checkbox" onchange='updateOptions()' name="statusbar" /
>Status Bar&nbsp;&nbsp;&nbsp;

So, if you can help me out...that´s will be great!

Many thanks in advance..

Gerardo

jpwade_bsu

unread,
Jun 11, 2008, 8:07:52 PM6/11/08
to KML Developer Support - Google Earth Browser Plugin
Hello Mickey,

good to see someone has made progress, there must be at least 1/2
dozen different posts relative to removing a NL


if you would post an example am sure you would be helping many a
person who is banging their head on the desk.

I for one, tried the bits from sylehc without success,
> > > > > mickmel do you have an example page where remove.Child works?- Hide quoted text -

mickmel

unread,
Jun 11, 2008, 8:26:16 PM6/11/08
to KML Developer Support - Google Earth Browser Plugin
Mine is working on three different PCs (all XP, two with IE and one
with FF2), but the guy I'm working with still can't get them to turn
off. Not sure what the deal is.

Here's a whole bunch of code for you:

<script src="http://www.google.com/jsapi?key=MY_API_KEY"></script>
<script>
google.load("earth", "1");

var ge = null;
var networkLink = null;

function init() {
google.earth.createInstance("map3d", initCallback, failureCallback);
}

function initCallback(object) {
ge = object;

ge.getWindow().setVisibility(true);
var layerRoot = ge.getLayerRoot();
var terrainLayer = layerRoot.getLayerById(ge.LAYER_TERRAIN);

}


function finished(object) {
if (!object) {
alert('bad or NULL kml');
return;
}
ge.getFeatures().appendChild(object);
var la = ge.createLookAt('');
la.set(122.291762218843276, 13.8575388211722, 25,
ge.ALTITUDE_MODE_RELATIVE_TO_GROUND,
82, 63, 860); //180, 60, 500);
ge.getView().setAbstractView(la);
}

function jumpto5()
{
var la = ge.createLookAt('');
la.set(31.4454464207786, -132.066826493232, 0,
ge.ALTITUDE_MODE_RELATIVE_TO_GROUND,
-171.346347193686, 59.9999996101215, 321.826770253291); //
180, 60, 500);
ge.getView().setAbstractView(la);
document.getElementById('locdesc').innerHTML="Some descriptive
text";
}

function showsomethingelse()
{
var form = document.options;
if (networkLink == null) {
networkLink = ge.createNetworkLink("");
networkLink.setDescription("NetworkLink open to fetched content");
networkLink.setName("Open NetworkLink");
networkLink.setFlyToView(true);
var link = ge.createLink("");
link.setHref("http://www.mysite.com/networklink.kml");
networkLink.setLink(link);
}
if (form.thecheckbox.checked) {
ge.getGlobe().getFeatures().appendChild(networkLink);
} else {
ge.getGlobe().getFeatures().removeChild(networkLink);
}
}

</script>

--------- then the code on the page to toggle the network link
--------------

<form name="options" action='javascript:showsomethingelse();'>
<input type="checkbox" onclick='showsomethingelse()'
name="thecheckbox" /> Show something else on map<br />
</form>

----------------

Hope that helps.

Mickey

mickmel

unread,
Jun 12, 2008, 8:36:21 AM6/12/08
to KML Developer Support - Google Earth Browser Plugin
Now I'm trying to get a bit more complex, with multiple checkboxes for
various network links. It works pretty well, but it seems a bit
buggy.

For example:
- Turn on NetworkLink "A" and 10 items appear.
- Turn on NetworkLink "B" and 10 items appear.
- Turn off NetworkLink "B", and about 8 of those items disappear (but
a few remain).
- Turn off NetworkLink "A" and the map is clean.
- Turn NetworkLink "A" back on, and it reloads with those 10 items,
but the few extra from "B".

It's like the "removeChild" isn't completely removing the items. Is
there a way to just flush the data completely?

jpwade_bsu

unread,
Jun 13, 2008, 7:37:55 PM6/13/08
to KML Developer Support - Google Earth Browser Plugin
Hello Micky,

Thanks bunches for the example, It seems I and the guy you are working
with are in the same boat.
Hope quirks have gotten better for him. I will sit back and wait for
some of the loose quarks in the BETA to settle down.

I tried a barebones map with NL function for both api&v=2.x & jsapi?
without success.

IE (6.0.2900.2180) and FF (2.0.0.14) respond differently in all
instances.

Thanks again,
jpwade

jpwade_bsu

unread,
Jun 15, 2008, 8:09:22 AM6/15/08
to KML Developer Support - Google Earth Browser Plugin
Mat Fox posted an example with setVisibility check the post:

http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/f1f5c4a95420a627

example from Matt: http://www.barnabu.co.uk/geapi/test/checkboxes.html

example I tried pts,line,pgon,ovlay,3d checkboxes here:
http://czmartin.com/jpw/asp_arcmap/gem_3d_netlink_multiples.html

not removeChild/apendchild thou it does toggle layers without flaw

jpwade
http://www.czmartin.com/jpw
> > I for one, tried  the bits from sylehc without success,- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages