Pou*_*sen 6 javascript openlayers-3
http://ol3js.org/en/master/examples/select-features.html
鉴于上面的例子,当选择功能时,有什么扩展点可以用于挂钩?
这个解决方案可能比Danny更直观,而且似乎也是"官方"方式,请参阅ol3的GitHub上的这个问题.
只需将监听器添加到所选功能的集合中:
mySelectInteraction.getFeatures().on('change:length', function(e) {
if (e.target.getArray().length === 0) {
alert("no selected feature");
} else {
var feature = e.target.item(0);
alert(feature.getId()); //or do something better with the feature !
}
});
Run Code Online (Sandbox Code Playgroud)
当地图上触发单击事件时,您可以将预合成事件绑定到图层。从这里您可以在您选择的交互上调度更改事件。
yourmap.on('singleclick',function(event)){
layer.once('precompose',function(event){
yourSelectInteraction.dispatchChangeEvent();
}
}
yourSelectInteraction.on('change',function(){
//Do stuff with your selected features here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4616 次 |
| 最近记录: |