[GIS] OpenLayers Map Click won’t fire on Android Chrome (Samsung S6 device)

mobileopenlayers

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?

Best Answer

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
})