contactjs icon indicating copy to clipboard operation
contactjs copied to clipboard

Add support for double tap and drag for zooming

Open cdrini opened this issue 2 years ago • 3 comments

This has become a very common interaction in mobile devices: Google maps, Apple.

The way it works:

  • double tapping zooms in
  • double tapping, and dragging upwards on the second tap zooms in proportional to distance from start tap
    • dragging downwards zooms out

It would be great if this was included in the library and easy to add!

cdrini avatar Oct 23 '22 19:10 cdrini

Thanks for bringing attention to this. I tried what you described in Apple maps and it worked as you described.

I will implement support for multiple taps. eg

const tap = new Tap(domElement, {
  taps: 2
});

The latter of what you described is a Tap followed by a Pan. A Tap requires the finger to be lifted from the surface. We could create something like a TapPan gesture, which then also would support tappanleft, tappanright tappanup and tappandown events.

biodiv avatar Oct 24 '22 19:10 biodiv

That seems good to me! I think a tappan would be enough for me, and then I could use the x/y coordinates to determine the amount of zoom. But tappan{left,right,up,down} would also work!

Thank you for the prompt reply!

cdrini avatar Oct 25 '22 17:10 cdrini

Meanwhile, you could try something like the following approach:

var TAP_ACTIVE = false;

function onTap(event){
    TAP_ACTIVE = true;
    setTimeout(function(){
        TAP_ACTIVE = false;
    }, 500);
}

pointerListener.on("tap", onTap);

function onPan(event){
    if (TAP_ACTIVE == true){
        if (event.detail.live.direction == "up") {
            // do something
        }
    }
}

pointerListener.on("pan", onPan);

biodiv avatar Nov 09 '22 10:11 biodiv