2012-01-25 9 views
1

jQueryを使用して、ユーザーが入力要素を選択するときに、OpenLayersにレイヤーの可視性を設定しようとしています。ここでjQueryを使ってopenlayers関数を呼び出す

は、層が定義されているコードの一部です:

stars = new OpenLayers.Layer.Vector("stars", { 
    strategies: [new OpenLayers.Strategy.Fixed()], 
    protocol: new OpenLayers.Protocol.HTTP({ 
     url: "textfile.txt", 
     format: new OpenLayers.Format.Text() 
    }) 
}); 

home = new OpenLayers.Layer.Vector("home", { 
    strategies: [new OpenLayers.Strategy.Fixed()], 
    protocol: new OpenLayers.Protocol.HTTP({ 
     url: "textfile1.txt", 
     format: new OpenLayers.Format.Text() 
    }) 
}); 
map.addLayers([stars, home]); 

彼女のベッドには、HTMLコードの一部です:

<ul> 
    <li class="ls_sivi"> <input type="checkbox" value="1" style="width:auto"><label>stars</label></li> 
    <li class="ls_sivi"><input type="checkbox" value="2" style="width:auto"><label>home</label></li> 
</ul>` 

とjQueryより:

$(document).ready(function(){ 
var sloj = new Array(); 
sloj[1]=stars; 
sloj[2]=home; 

$('.ls_sivi input[type="checkbox"]').change(function(){ 
    var vri = $(this).val(); 

    if($(this).is(":checked")){ 
     sloj[vri].setVisibility(true); 
     return 
     } 
     sloj[vri].setVisibility(false); 
    }); 
    }); 

私が手に:

"sloj [vri] .setVisibility"は関数ではありません。

もっと多くのレイヤーがあり、これが最も簡単な方法でこの問題を解決できますか?

+0

私はあなたのチェックボックスの参照を二重にチェックするべきだと思います。私はそれが機能ではないと言っている理由は、あなたが考えているものではないからだと思う。 –

+0

あなたは正しいですが、vriを私が得た数で置き換えてください。 'sloj [2]'をオブジェクト – user971146

+1

に変換できません...ありがとう – user971146

答えて

2

用途:

map.getLayer(sloj[vri].id).setVisibility(); 
関連する問題