簡體   English   中英

是否有在OpenLayers 3中選擇功能的事件?

[英]Is there an event for when features are selected in 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 !
        }
    });

在地圖上觸發單擊事件時,您可以將預合成事件綁定到圖層。 從這里,您可以在選擇的互動上發送更改事件。

yourmap.on('singleclick',function(event)){
    layer.once('precompose',function(event){
        yourSelectInteraction.dispatchChangeEvent();
    }
}

yourSelectInteraction.on('change',function(){
    //Do stuff with your selected features here
}

您想使用featureselected事件處理程序:

此示例位於Vector圖層上:

featuresLayer.events.on({
    'featureselected': function (e) {
        console.log(e);
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM