gpt4 book ai didi

javascript - 两个或多个功能的事件管理

转载 作者:行者123 更新时间:2023-12-03 07:42:27 26 4
gpt4 key购买 nike

如何使用 Openlayers 3 事件管理进行编码。

我有两个功能需要管理,但我还没有找到如何使用 ol.interaction.Select。

但这也许不是正确的方法。

Openlayers2 示例

select = new OpenLayers.Control.SelectFeature([layer_1, layer_2]);
layer_1.events.on({"featureselected": do something...... });
layer_2.events.on({"featureselected": do something...... });
map.addControl(select);
select.activate();

最佳答案

使用 OL 3,您可以将图层数组添加到 ol.interaction.Select构造函数如下:

var selectInteraction = new ol.interaction.Select({
layers: [vectorLayer1]
});
var selectInteraction2 = new ol.interaction.Select({
layers: [vectorLayer2]
});

map.addInteraction(selectInteraction);
map.addInteraction(selectInteraction2);

// do the same with other interaction
selectInteraction.on('select', function(evt) {
if(evt.selected.length > 0){
// do something
}
});

关于javascript - 两个或多个功能的事件管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35348613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com