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

4

2 に答える 2

1

これが私が少し前に投稿した回答ですhttps://stackoverflow.com/a/11108342/1211981これはFusionTableレイヤーを切り替える簡単な方法を示しています。IEは、オンになっているかどうかを確認し、オンになっていない場合はオフにします。うまくいけば、あなたはあなたの目的のためにそれを修正することができます。どのFTレイヤーでも機能します。

于 2012-10-03T00:09:13.783 に答える
0

2つのマップで機能させるために1つの変数がありませんでした。エラーはレイヤーのオンとオフではなく、レイヤー名の再割り当てにありました。

于 2012-10-02T22:38:56.527 に答える