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.