【问题标题】:select feature in Openlayer is not working, selected feature doesn't highlight?Openlayer 中的选择功能不起作用,所选功能不突出显示?
【发布时间】:2014-07-02 15:16:58
【问题描述】:
我设法通过其属性搜索功能..问题是,它没有突出显示功能..
将显示一个弹出窗口,但所选功能未突出显示...下面是我的代码:
this.showparcel = function(getpin){
for(var f=0;f<layer_agao.features.length;f++) {
if(layer_agao.features[f].attributes.newpin === getpin) {
featsel = layer_agao.features[f];
selectControl.select(featsel);
break;
}
else{
selectControl.unselect(featsel);
}
}
}
【问题讨论】:
标签:
javascript
openlayers
【解决方案1】:
使用 jquery 并将 selectControl.select(featsel); 更改为 selectControl.clickFeature(featsel); 应该可以正常工作,以避免在搜索时多次选择功能..
代码如下:
$("#forminput").change(function(){
for (var f = 0; f < layer_agao.features.length; f++) {
if (layer_agao.features[f].attributes.newpin == this.value) {
featsel = layer_agao.features[f];
$("#mybutton").click(function(){
selectControl.clickFeature(featsel);
});
break;
}
}
});
应该放在init()函数里面,下面是html标记。
<form class="navbar-form navbar-right">
{% csrf_token %}
<select name="q" class="form-control" id="forminput">
<option type="text" value=""><b>Select Land PIN</b></option>
{% for getlandpins in query_map %}
<option type="text" value="{{ getlandpins.newpin }}">{{ getlandpins.newpin }}</option>
{% endfor %}
</select>
<input type="button" class="btn btn-primary" value="Show Info" id="mybutton">
</form>