3

I'm new on OpenLayers and I'm developing an app for my final project career.

I develop a map viewer where you can tap the features displayed on it and a popup is shown. When I try the app in PC browser using click you can tap the feature with no difficulties.

The problem is when I want to tap one of this features in the mobile version. It's very difficult to tap and hit the feature.

My code:

        map.on('click'/*'touch'*/, function(evt) {

            popup.hide();
            popup.setOffset([0, 0]);

            var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature) {

                if (feature.getGeometry().getType() == 'Point'){
                return feature;}

            });

         });

I tried with different possible solutions but any of them solved the issue 100%:

var snap = new ol.interaction.Snap({
            source: source.getSource(),
            pixelTolerance: 30
            }); 
            map.addInteraction(snap);

or

hitTolerance: 15

or

getclosestfeature();

Do you know how to resolve it?

  • what version of Openlayers do you use? – Chase Choi Jun 29 '17 at 4:19
  • I'm using the cesium.js version. I also tried with 3.20 and 4.0.1 – VFA Jun 29 '17 at 6:49
1

Try setting the hitTolerance option when calling getFeaturesAtPixel.

Hit-detection tolerance in pixels. Pixels inside the radius around the given position will be checked for features. This only works for the canvas renderer and not for WebGL. Default is 0.

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.