http://ol3js.org/en/master/examples/select-features.html在OpenLayers 3中選擇功能時是否有事件?
鑑於上面的例子,當選擇特徵時,有哪些擴展點用於鉤住?
http://ol3js.org/en/master/examples/select-features.html在OpenLayers 3中選擇功能時是否有事件?
鑑於上面的例子,當選擇特徵時,有哪些擴展點用於鉤住?
您可以將precompose事件綁定到你的層時被觸發你的地圖上singleclick事件。從這裏,您可以在選擇的交互中發送更改事件。
yourmap.on('singleclick',function(event)){
layer.once('precompose',function(event){
yourSelectInteraction.dispatchChangeEvent();
}
}
yourSelectInteraction.on('change',function(){
//Do stuff with your selected features here
}
您要使用的featureselected
事件處理程序:
這個例子是一個矢量層:
featuresLayer.events.on({
'featureselected': function (e) {
console.log(e);
}
});
是的OpenLayers 3?事件沒有定義。 –
這裏是一個可能比丹尼的更直觀的解決方案,也似乎是「官方」的方式,請參閱this issue on ol3's 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 !
}
});
正如GitHub問題所述,您還可以訂閱功能集合中的「添加」和「刪除」事件。 –
您可以使用'e.target.getLength()'而不是'e.target.getArray().length' – congusbongus
謝謝,+1。你知道爲什麼每次選擇(未)選項時都不會自動調度change事件嗎? –