Hey Thanks so much for the reply, Yeah since the treed I drastically
modified the first example to basically give me multiple boxes to
click. but when I did that the problem is both boxes call the same
file. I am stuck on how to tell javascript to grab the second file
path.
The second example I thought for sure was going to help but basicly
what is happening is the same kml file keeps loads when I check each
of the different boxes.
Thanks again Fraser for the reply
With your help I am now closer then I was so Thanks Again Fraser for
the reply
I put the code that is on the playground with some minor alteration to
show you what I am having trouble with. I have written a couple of
solutions that I thought would work but in reality they either do
nothing or keep the code from running.
I think my main problem is the size of my kml and the way its
configured File not sure tho.
!--
Copyright (c) 2009 Google inc.
You are free to copy and use this sample.
License can be found here:
http://code.google.com/apis/ajaxsearch/faq/#license
-->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/
>
<title>Google Earth API Sample</title>
<script src="
http://www.google.com/jsapi?
key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></
script>
<script type="text/javascript">
function addSampleButton(caption, clickHandler) {
var btn = document.createElement('input');
btn.type = 'button';
btn.value = caption;
if (btn.attachEvent)
btn.attachEvent('onclick', clickHandler);
else
btn.addEventListener('click', clickHandler, false);
// add the button to the Sample UI
document.getElementById('sample-ui').appendChild(btn);
}
function addSampleUIHtml(html) {
document.getElementById('sample-ui').innerHTML += html;
}
</script>
<script type="text/javascript">
var ge;
// store the object loaded for the given file... initially none of
the objects
// are loaded, so initialize these to null
var currentKmlObjects = {
'red': null,
'yellow': null,
'green': null
};
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCallback,
failureCallback);
addSampleUIHtml(
'<h2>Toggle KML Files:</h2>' +
'<input type="checkbox" id="kml-red-check" onclick="toggleKml
(\'red\');"/><label for="kml-red-check">Fire History 1990 2003</
label><br/>' +
'<input type="checkbox" id="kml-yellow-check"
onclick="toggleKml(\'yellow\');"/><label for="kml-yellow-check">Fire
History 1980 1989</label><br/>' +
'<input type="checkbox" id="kml-green-check" onclick="toggleKml
(\'green\');"/><label for="kml-green-check">Green Placemarks</
label><br/>'
);
}
function initCallback(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
// add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
// add some layers
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
// fly to set location (smm)
var la = ge.createLookAt('');
la.set(34.1, -118.69,
0, // altitude
ge.ALTITUDE_RELATIVE_TO_GROUND,
0, // heading
30, // straight-down tilt at 30%
48000 // range (inverse of zoom)
);
ge.getView().setAbstractView(la);
// if the page loaded with checkboxes checked, load the
appropriate
// KML files
if (document.getElementById('kml-red-check').checked)
loadKml('red');
if (document.getElementById('kml-yellow-check').checked)
loadKml('yellow');
if (document.getElementById('kml-green-check').checked)
loadKml('green');
document.getElementById('installed-plugin-version').innerHTML =
ge.getPluginVersion().toString();
}
function failureCallback(errorCode) {
}
function toggleKml(file) {
// remove the old KML object if it exists
if (currentKmlObjects[file]) {
ge.getFeatures().removeChild(currentKmlObjects[file]);
currentKmlObject = null;
}
// if the checkbox is checked, fetch the KML and show it on
Earth
var kmlCheckbox = document.getElementById('kml-' + file + '-
check');
if (kmlCheckbox.checked)
loadKml(file);
}
function loadKml(file) {
var kmlUrl = '
http://sbroussard.yolasite.com/resources/
1990-2003FH.kml';
// fetch the KML
google.earth.fetchKml(ge, kmlUrl, function(kmlObject) {
// NOTE: we still have access to the 'file' variable (via JS
closures)
if (kmlObject) {
// show it on Earth
currentKmlObjects[file] = kmlObject;
ge.getFeatures().appendChild(kmlObject);
} else {
// bad KML
currentKmlObjects[file] = null;
// wrap alerts in API callbacks and event handlers
// in a setTimeout to prevent deadlock in some browsers
setTimeout(function() {
alert('Bad or null KML.');
}, 0);
// uncheck the box
document.getElementById('kml-' + file + '-check').checked =
'';
}
});
}
</script>
</head>
<body onload="init()" style="font-family: arial, sans-serif; font-
size: 13px; border: 0;">
<div id="sample-ui"></div>
<div id="map3d" style="width: 500px; height: 380px;"></div>
<br>
<div>Installed Plugin Version: <span id="installed-plugin-version"
style="font-weight: bold;">Loading...</span></div>
</body>
</html>
> Multiple Kml with checkboxeshttp://
code.google.com/apis/ajax/playground/?exp=earth#fetch_kml_(int...)
>
> They, along with the other examples, should help you a lot.
>
> F.
>
> On Oct 15, 11:10 pm, Shea wrote:
>
> > I have some coding experience but am new to thisgoogleapi(kml,
> >JavaScript, etc) I am a graduate student and recently starting
> > learning how to code, to i guess get myself in more trouble.. , I
> > think the what I am trying to do is simple but having some troublen. I
> > am havign trouble knowing when and were to input different langauges
> > in to html like javescript or KML .
> > basically I have just created anapion a web page and am trying to
> > // wrap alerts inAPIcallbacks and event handlers