Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid mousewheel/finger trap in the map #4768

Closed
wants to merge 5 commits into from
Closed

Conversation

Senen
Copy link
Member

@Senen Senen commented Jan 11, 2022

References

This fixes usability issues when scrolling pages with a map and more content below. card-74165431

Objectives

Make it easier for users to scroll the page to the bottom by:

  1. Disable the map mouse wheel event to zoom the map on desktop devices
  2. Disable map dragging and tap events on mobile devices
  3. Add controls to the map so desktop and mobile users can move around the map

Visual Changes

Before
map-pan-control-before

After
map-pan-control-after-mobile
map-pan-control-after

Notes

Alternative solutions

The first solution I tried was to install a Leaflet plugin that adds a similar behaviour to Google Maps Gesture Handling plugin. During mobile testing, I found it works nicely in Chrome, Edge, Opera and Safari, while the user experience when using two fingers to move or zoom the map is annoying in Firefox. Unfortunately, it seems to conflict in some way with the page scroll, so I finally chose to use controls to allow users to move the map. Here is a work in progress branch with the Leatflet.GestureHandling plugin installed in CONSUL.

@Senen Senen self-assigned this Jan 11, 2022
@Senen Senen added this to Reviewing in Consul Democracy via automation Jan 11, 2022
@Senen Senen moved this from Reviewing to Doing in Consul Democracy Jan 11, 2022
@Senen Senen added the UX label Jan 11, 2022
@Senen Senen force-pushed the map-pan-control branch 2 times, most recently from 0e460bb to 0e01219 Compare January 12, 2022 14:40
Solve a usability issue when a user's scrolls on pages
with a map and additional content below. When the user
is scrolling, and the mouse goes over the map, the
window stops scrolling, and the map starts moving; this
behaviour annoys the users as they expect to keep
scrolling the page to the bottom. A similar problem
occurs when browsing the page on touchable devices
like phones or tablets.

We are disabling the mouse wheel map listener to keep
scrolling to the page bottom on desktop devices. We are
disabling the dragging and the tap features for mobile
devices, although as the user can not move the map, we
need arrow controls to allow users to change the map pan.

Credits for the mobile solution are for SimonEast [1].

[1] Check Github Leaflet/leaflet project issue 5425#issuecomment-342055520.
We needed to adapt the original code so it works with
the Rails asset pipeline.
We only need the new controls for the mobile
version as it is impossible to move map panes after
disabling `dragging` and `tap` options. In contrast,
desktop users can drag the map by clicking and
dragging the mouse. However, I finally decided to
show the pan controls for desktop and mobile
devices to keep consistency and considering that
some users can browse the website through both
kind on devices.
Using a fixed offset for all screen sizes does not
work nice. For example, when using mobile devices
(usually small), the default offset value (500px by
default) moves the map pan to a too far pan and
makes the user lose the reference point from the
previous pan.

Using the same offset for the vertical and horizontal
pan controls does not work nicely when the map does not
have an square shape.

To better control the vertical and horizontal offsets
and considering we show maps with all the shapes,
we will use different offsets for vertical and
horizontal panning calculated from the map
dimensions, so we can move the pan as much as
possible without losing the reference point.
@Senen
Copy link
Member Author

Senen commented Mar 27, 2023

Closing in favor of #5096.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant