0

OK so I am hopping this is a simple issue that I am over complicating things...

So I have a complex json/jQuery function (3000 lines) that builds a DOM tree that resides in called js file that has a lot of other on page functions built in. This is called onload back to the page to do some realtime client side processing.

Right now the DOM tree is called using <div id="tree"></div> function that calls:

<style type="text/css" src="css/kmltree.css
<script src="css/kmltree.min.js"></script>
<script src="source/extensions.pack.js"></script>
<script type="text/javascript" src="source/gearth_public_d4_multi_son.js"></script>

This last call is the main function that calls:

    var tree1 = kmltree({
    url: 'kml/ca_son.kml',
    gex: gex,
    mapElement: $('#geeMap'),
    element: $('#tree')
});

tree.load();

For each tree you change the variable to tree1, tree2...

What I need to do is to fire each tree using a checkbox, not onload as the page loads too slow when all the trees are loaded at one time.

I have tried all the onClick examples I could find and none seem to work with the id call.

Any ideas as to what needs to change in the code to get the results I am looking for?

Thanks for your time!

3
  • What is kmltree? Can you put a bit more code so we can understand better?
    – Mimo
    Commented May 29, 2013 at 21:00
  • Basically the script is used to populate a google earth API website. A kml is a xml file that holds the info displayed on the map. kmltree is the part of the script that fires the creation of the DOM tree, it is just a variable. The var=tree is part of the called js file
    – Joe Wink
    Commented May 29, 2013 at 21:09
  • 1
    So full called code modified above, sorry first time posting here...
    – Joe Wink
    Commented May 29, 2013 at 21:11

2 Answers 2

0
<input type="checkbox" onchange="doTrees()"/>
<script>
function doTrees()
{
    //Load Trees, what ever they are
}
</script>
1
  • Thanks Isaac but I tried this in one of my earlier iterations to no avail. Firebug doesn't even give a reason, it just does nothing.
    – Joe Wink
    Commented May 30, 2013 at 14:49
0

You can try something like this on your HTML:

<input type="checkbox" name="selectTree" value="yourTree" />

and on your script use the value of the checkbox to dynamically load a tree:

var tree,
    selectURL,
    selectTree = $('[type="checkbox"][name="selectTree"]');

selectTree.on('change',function() {
    selectURL = $(this).val();
    tree = kmltree ({
        url: selectURL,
        element: $('#tree')
    });

    // use your tree
});
4
  • This looks interesting mimo, but it again does not appear to do anything, but it looks to be promising. Now the var tree function is actually nestled in a call back function, is it possible that this would cause the script to not do anything?
    – Joe Wink
    Commented May 30, 2013 at 14:56
  • After playing around with this it looks like the issue is with the $(this).val() as the js file resides on a different server than the HTML page (enterprise design) and the call back is looking for the wrong server. Still working on it but I am a new java programmer
    – Joe Wink
    Commented May 30, 2013 at 18:45
  • actually there was an issue with what I wrote yesterday. I changed it, now it should work.
    – Mimo
    Commented May 30, 2013 at 20:58
  • I will check this out Mimo as an exercise for another issue we are having with the page, however, I think that the issue might be with the way the API processes the KML. I reviewed something that I thought I remembered about the API and was right, the KML needs to be loaded into memory with the page for it to be active in the viewport. I might use it to fix a double click issue with the upper level folder structure. Will get back if this works. Thanks!
    – Joe Wink
    Commented May 31, 2013 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.