7

I would like my KML layer in OpenLayers 3 (OL3) to respond to different types of click events.

I have a single click method working nicely. But how do I get it working for "shift-clicks" "double clicks" etc?

 map.on('singleclick', function(evt) {                         
   var feature = map.forEachFeatureAtPixel(evt.pixel,
     function(feature, layer) {
     // do stuff here with feature
     return [feature, layer];                                  
   });                                                         
 });                                                           

This was a good start, but I can't quite put the OL3 API documentation together.

9

ah ok dblclick is the answer

// set mode to current mode of double clicked feature                       
map.on('dblclick', function(evt) {
  console.log('doubled');
  var feature = map.forEachFeatureAtPixel(evt.pixel,
    function(feature, layer) {
      // do stuff here
    });
});                                                                    

and evt.originalEvent.altKey, evt.originalEvent.ctrlKey, evt.originalEvent.metaKey, evt.originalEvent.shitKey are all availabe within the handler!

3

Get clicked XY coordinates in ol3

map.on('click', function(evt) {
var coordinates = evt.coordinate;
alert(coordinates);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.