Here's how I'm doing it with one KML. You could scale this for
multiple KML's with a few Javascript variables:
In your HTML, a checkbox:
<input type="checkbox" id="show_hide_KML_Layer_01"
onClick="toggleKMLLayer01();" />Show/Hide KML Layer
In your Javascript where you are creating the map:
var kmlLayer01URL = '
http://www.mySite.com/datafiles/myKMLFile01.kml';
var kmlOptions = {
preserveViewport: 1
};
kmlLayer01 = new google.maps.KmlLayer(kmlLayer01URL, kmlOptions);
kmlLayer01.setMap(map);
If the KML layer is initially visible when the map is opened, the
checkbox will need to be checked. Place this code right below the
above code, within the code creating the map:
// initailly show KML Layer 01
document.getElementById('show_hide_KML_Layer_01').checked = true;
In the Javascript OUTSIDE of where you are creating your map:
// toggle the display of the KML Layer 01
function toggleKMLLayer01() {
if (!document.getElementById('show_hide_KML_Layer_01').checked)
kmlLayer01.setMap(null);
else
kmlLayer01.setMap(map);
}
HTH
-- JF