[GIS] Touch ‘tap’ event not available on openlayers 2.11 map (update: click works fine)

iosipadmobileopenlayers-2

According to Will mousedown events fire with Touch events on OpenLayers mobile?, openlayers 2.11 supports click-like behaviour for vector layers only.

Separate from that, regular pinching/zooming/panning works on the whole map. Weird thing, though, is that zooming on the ipad triggers a click event…

My problem: I don't have a vector layer, but I do want to handle click events on an ipad. I tried attaching 'touchstart' in addition to 'click' to my existing click handler, but that doesn't give any reaction.

So my question is: can I have an OpenLayers.Handler.Click handler on the whole map that reacts to touch taps?

Update: click events work anyway, see below.

Best Answer

The main problem is the conflict with TouchNavigation Handler.Click controls: when you are panning, sometimes the "tap" (aka click) is not catched.

This solution has worked to me, in order to be able to have tap support in recent android devices and with newer Chrome for Android releases. As you can see, I added double click (tap) event, to "force" calling the handler :-)

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
    defaultHandlerOptions: {
        'single': true,
        'double': true,
        'pixelTolerance': 1,
        'stopSingle': false,
        'stopDouble': false,
        'delay': 10
    },
    initialize: function(options) {
        this.handlerOptions = OpenLayers.Util.extend(
            {}, this.defaultHandlerOptions
        );
        OpenLayers.Control.prototype.initialize.apply(
            this, arguments
        );
        this.handler = new OpenLayers.Handler.Click(
            this, {
                'click': this.trigger
            }, this.handlerOptions
        );
    }
});
Related Question