[GIS] Order of KML Layers in Google Maps API V3

google mapsgoogle-maps-apikml

I'm working on a website that when finished will allow the user to turn on and off a number of different KML layers using checkboxes, the layers are parsed through geoXML3 and I want to know how to control the order which the layers appear.

Currently if I have 2 polygon layers (layer A and B) and I click the checkbox to load layer A then I click the checkbox to load layer B layer B will be on top as it should be. However if I then uncheck both boxes, and select B first and then A, B is still drawn on top.

I assume this is because I parse the data only the first time the boxes are checked and afterwards I just show or hide them, but is there a way to manage which layer is on top?

Below is an example of the function I use to parse the layer and then turn it on or off.

function boundaryToggle_FOS() {
if (boundaryIsLoaded_FOS == 0)
{
boundaryIsLoaded_FOS = 1;
    if (firstLoadFOS == 0)
        {
        kml_FOS.parse('FOS_Boundary_v03.kml');
        firstLoadFOS = 1;
        }
    else
        {
        kml_FOS.showDocument();
        }
}
else
{
    kml_FOS.hideDocument();
    boundaryIsLoaded_FOS = 0;
}}

Best Answer

In this example KML is coming from Fusion Tables

http://www.geocodezip.com/geoxml3_test/www_advocacy_ucla_edu_Assembly_MapC.html

        function changeLayer(tableidselections) {

if (tableidselections == 1265695){
     if (document.getElementById("layer").checked == true) {
       if(layer.getMap() == null) { layer.setMap(map); }
     }

     if (document.getElementById("layer").checked == false) {
         layer.setMap(null); /*layersetoff*/
     }
}

if (tableidselections == 1261953){
     if (document.getElementById("layer2").checked == true) {
       if(layer2.getMap() == null) { layer2.setMap(map); }
     }

     if (document.getElementById("layer2").checked == false) {
         layer2.setMap(null);  /*layersetoff*/
     }

if both layers are on - layer1 is at the bottom then layer2 on top.

Related Question