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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With