1

I have the forEachFeatureAtPixel function and try to trigger an event on click on a point layer with a custom icon. However, the performance on touch devices is really bad. I need to click several times until it triggers the event (sometimes it doesn'tdo it at all..) . I also used the moveTolerence feature for the map, but still have the same issues. On mouse click on my desktop PC everything works like a charme. What am I missing to make the performance as smooth as on a desktop PC?

This is my code:

$(document).ready(function() {
map.on('singleclick', function(evt) {
    var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
        return feature;
    }, {hitTolerance:10});
    var layer = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
        return layer;
    }, {hitTolerance: 15});
    if (feature) {
        if (layer === vectorLayerFB) {
            window.open('https://www.example.com', '_blank');
        }
        if (layer === vectorLayerBlog) {
            window.location = 'www.example.com';
        }
    }
}); 
[...]
});
  • 1. which version to you use? v3.x.x? 2. have you tried to increase hitTolerance value as 30 something? – Chase Choi Aug 17 '18 at 0:38
  • My ol version is v3.11.2. And yes, I have tried with a higher hitTolerance (20 / 30 / 100). It is always out of 10 clicks only one or two are working. Using Samsung S9+ with chrome but had same issues with a S6 on chrome – JoeBe Aug 17 '18 at 3:07
2

hitTolerance parameter is introduced with version 3.20.0.
So, it's not working with version 3.11.2 because there's no hitTolerance.
Up-versioning to 3.20.0 will solve your problem.

  • Thanks. Would you suggest me to upgrade to the latest stable version? (If yes, which is it at the moment, if you know?) – JoeBe Aug 17 '18 at 5:26
  • 1
    Since version 5.0, there's huge changes on import things. The last 4.x.x version would be better to use for you. – Chase Choi Aug 17 '18 at 8:31

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.