Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openlayers 3 - Interaction and pointermove

I'm trying to activate an interaction when the mouseover is inside some feature.

It is working so so... the problem is if you move your mouse slowly the interaction keep active.

Is it a bug on OL3, or should I do in a different way?

Code: http://jsfiddle.net/gmaq54dm/3/

olMap.on("pointermove", function (e) {
    if (e.dragging) {
        return;
    }
    var map = e.map;
    console.log(e.pixel);
    var feature = map.forEachFeatureAtPixel(e.pixel, function(feature, layer) {
      return feature;
    });
    var hit = (feature) ? true : false;
    console.log(hit);
    olDraw.setActive(hit);
});

Thanks

like image 576
Marcos Oto Avatar asked Oct 15 '25 07:10

Marcos Oto


1 Answers

This is a bug in your application, not in OpenLayers. You need to make sure you only hit-detect features from your vector layer, not from the draw layer. Change your forEachFeatureAtPixel function to

var feature = map.forEachFeatureAtPixel(e.pixel, function(feature, layer) {
  return feature;
}, null, function(layer) {
  return layer == vectorLayer
});

The last argument adds a layer filter to only hit-detect features on the vector layer.

Updated, working JSFiddle: http://jsfiddle.net/gmaq54dm/4/

like image 58
ahocevar Avatar answered Oct 18 '25 08:10

ahocevar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!