вызовите функцию openlayers с помощью jquery - PullRequest
1 голос
/ 25 января 2012

Я пытаюсь заставить OpenLayers установить видимость для слоя, когда пользователи выбирают элемент ввода с помощью jQuery.

Вот часть кода, где определены слои:

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" не является функцией.

Как я могу решить эту проблему, потому что у меня больше слоев, и это будет самый простой способ?

1 Ответ

2 голосов
/ 26 января 2012

Использование:

map.getLayer(sloj[vri].id).setVisibility();
...