1

I want to add selec interactions to my OL3 map. Adding two different select interactions like this is not working. Only the second one works. Like this:

 var select = new ol.interaction.Select({
 layers: [clusters]
 });
select.getFeatures().on('add', function (e) {alert("orange")});
 map.addInteraction(select);
 var select2 = new ol.interaction.Select({
 layers: [clustersSarv]
 });
select2.getFeatures().on('add', function (e) {alert("blue")});
 map.addInteraction(select2);

Now I am trying to do something like this, but I am unable to get layer on which is clicked, to define different actions for different layers.

var select = new ol.interaction.Select({
 layers: [clusters,clusters2]
 });
select.getFeatures().on('add', function (e) {
 console.log(e.element);
// if layer is clusters alert("orange")});
 map.addInteraction(select);

Any suggestions? Main question is how to get a layer name by clicking on layer's features.

asked Oct 22, 2014 at 7:48

1 Answer 1

2

To answer your question about grabbing the layer from a clicked feature, you can do the following:

map.on(ol.MapBrowserEvent.EventType.SINGLECLICK, function (e) {
 map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
 ...
 });
}
answered Nov 13, 2014 at 22:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.