0

Seems simple but I seem to be missing something. When the page loads I am not sure which layers will be created (scripted). I could have multiple layers on. I have a radio button group that is created when each layer is created. I want these to be able to allow the user to view them individually. Lets say I have three map layers

layer1.setMap(map1);
layer2.setMap(map1);   
layer3.setMap(map1);  

I build my dynamic radio button like this (see below. Example for layer1 but is done the same for the rest)

 $('#tools').append('Layer1<input name="Layer1" type="radio" value="layer1" onClick="toggleLayer(layer1)"><br />');
}

My toggleLayer is where I am having issues? How can I just hide them all and make the one clicked show.

function toggleLayer(this_layer){

if (typeof layer1 === 'undefined') {
// variable is undefined
     }else
  {layer1.setMap(null);

}

if (typeof layer2 === 'undefined') {
// variable is undefined
     }else
  {layer2.setMap(null);

}

if (typeof layer3 === 'undefined') {
// variable is undefined
     }else
  {layer3.setMap(null);
}


    //alert(this_layer);
    this_layer.setMap(map1);

} 

I am trying to find out which layers are on and if they are, hide them. can't I just disable the whole map instead of going through layer by layer? Example page here. Notice on my example page I am trying it with two maps. My current technique works when I try and set the layer of only one map but breaks when I try and do it with both. Seems to be too complicated a script for what I need.

http://wrestore.iupui.edu/Jon/mapScriptTry.html

jeynon
  • 322
  • 6
  • 16
  • http://wrestore.iupui.edu/Jon/mapScriptTry.html I essentially lose my first map everytime I try and redraw both maps. Confusion! – jeynon Oct 02 '12 at 21:43

2 Answers2

1

Here's an answer I posted a while ago https://stackoverflow.com/a/11108342/1211981 which shows a simple way to toggle Fusion Table layers. I.E. see if it's on and if not turn it on, if on turn it off. Hopefully you can modify it for your purposes. It works on any FT layer.

Community
  • 1
  • 1
Eric Bridger
  • 3,751
  • 1
  • 19
  • 34
0

I was missing one variable to make it work with two maps. The error wasn't in the on and off of the layers but reassigning the layer name!

BenMorel
  • 34,448
  • 50
  • 182
  • 322
jeynon
  • 322
  • 6
  • 16