使用jquery调用openlayers函数
我试图让 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”不是函数。
我怎样才能解决这个问题,因为我有更多层,这将是最简单的方法?
I am trying to get OpenLayers to set visibility for a Layer whe users selects input element using jQuery.
Here is a part of code where are layers defined:
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]);
Hers is part of html code:
<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>`
And than 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);
});
});
I get:
"sloj[vri].setVisibility" is not a function.
How could I solve this problem because I have more layers and this would be the easiest way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
Use: