Reputation: 39
How can I do to code with Openlayers 3 events management.
I have two features to manage and I have not found how to use ol.interaction.Select.
But maybe this is not the right method.
example with 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();
Upvotes: 0
Views: 53
Reputation: 14150
With OL 3 you can add an array
of layers to the ol.interaction.Select
constructor like this:
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
}
});
Upvotes: 1