4

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.

1

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

It turns out that the click event works just fine on an ipad anyway. Provided you add the click handler after setting the extent. I don't know why, but that little change made my code work...

Hurray for my colleague that found it out :-)

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.