GMapsFX icon indicating copy to clipboard operation
GMapsFX copied to clipboard

Panning on touchscreen zooming in issue (Bug)

Open 05dfleming opened this issue 7 years ago • 4 comments

Hi, I am sorry to bother you but I am currently using this in a JavaFX app I'm making for the surface pro 4. Unfortunately, when I am wanting to pan using my finger on the touch screen the map zooms in and out. Is there any way to change this, so the map follows my finger and if possible pinch to zoom, please?

I've messed around with adding new touch event listeners, but with no luck.

Any help would be extremely appreciated!

Thanks :)

05dfleming avatar Jun 12 '17 19:06 05dfleming

So it seems to be related to touchscreen actions being miss-recognized as scroll wheel ones. A quick fix to the API could be to have a check when a scroll wheel is being used and if the screen is being touched then not fire the event for the scroll wheel? I've just set mapOptions.scrollWheel(false);, and that stops the zooming when trying to pan but also stops any of the cool pinch to zoom gestures on touchpads as you'd expect, which is a bit of shame tbh.

05dfleming avatar Jun 13 '17 16:06 05dfleming

Having this same issue

mhopey avatar Sep 07 '17 19:09 mhopey

We're intercepting events only enough to provide workarounds for specific issues, everything else is passed straight through to the map. Having looked around there doesn't seem to be explicit support for gestures, though there is the "gestureHandling" option now available that seems to be designed to deal with issues around scrolling and zooming within the context of the larger page.

https://developers.google.com/maps/documentation/javascript/interaction

Still, I wonder if Maps would know it was a touch gesture after we've passed it through?

As a first step I've added in the "gestureHandling" option to MapOptions, you can try those out and see if they make any difference, otherwise we can work on trying out other ways to deal with touchscreen devices. Hopefully I'll have one again some time in the future to test it out lol!

GeoffCapper avatar Nov 19 '17 12:11 GeoffCapper

I tried both gestureHandling() options (cooperative and greedy) and neither worked satisfactorily. Greedy works the same as before, where dragging is interpreted as a scroll event and causes the map to zoom. Cooperative is slightly better, with dragging causing the map to pan and ctrl+drag causing the map to zoom. However, when panning, it is clearly also still receiving scroll events because it often displays the message "Use ctrl + scroll to zoom the map".

I haven't looked into the code yet but I think this will have to be handled from the java side. We can block the erroneous zooming by consuming ScrollEvents when event.getTouchCount() is equal to 1. However, to get it to zoom properly on pinch you would have to intercept zoom events, convert their zoom factor to a deltaY, and then fire a ScrollEvent. I attempted this and successfully created scroll events, but for some reason they didn't cause the map to zoom. I don't want to spend too much time on that because I don't think that's a great solution, but I'm not sure how else to do it. You could use GoogleMap.setZoom(), but that only accepts integers and I'd like to be able to zoom smoothly. Does someone with more GMapsFX knowledge have a better solution?

ethanmdavidson avatar Jun 20 '18 20:06 ethanmdavidson