2

I'm having an issue getting a map click event to fire properly on a Samsung Galaxy S6 device using Chrome for Android. I have not seen this issue on other devices (yet). I'm using v3.19.1 of the OpenLayers API.

Here's how I create my map and register my click event

        CreateMap : function() {
            this.bLayer = new ol.layer.Tile({ source: new ol.source.OSM() });
            this.vLayer = new ol.layer.Vector({ style:styleFn, source:new ol.source.Vector() });

            var controls = ol.control.defaults({ attributionOptions: { collapsible: true }});
            var view = new ol.View(this.options.view);

            this.map = new ol.Map({
                layers  : [this.bLayer, this.vLayer ],
                controls: controls,
                view    : view
            });

            this.map.on("singleclick", this.onMap_Click.bind(this));

            function styleFn(f) {                   
                return Styles[f.getGeometry().getType()];
            }
        },

I tried debugging my device, the code never goes into the onMap_Click function. I've also tried a regular click event.

One thing I noticed is that most of the time, when I'm trying to tap on the map, the map pans a little. If I start tapping furiously on the map, at some point one click event will register properly.

Would moving to the most recent version of OpenLayers help at all?

  • Seems you need up versioning. check moveTolerance option on ol.Map: github.com/openlayers/openlayers/blob/… – Chase Choi Aug 16 '17 at 14:52
  • the moveTolerance option in OL4 fixed my issue. Thanks Chase, I'll choose your answer if you make your reply into an actual answer – Ggilmann Aug 17 '17 at 18:09
4

Openlayers added moveTolerance option into ol.Map to give better click experience on touch devices. check the change log and documents for details.

Version up your Openlayers to use moveTolerance option.

new ol.Map({
    ...
    moveTolerance: 5
})

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.