mapbox / mapbox/mapbox-gl-js

add touchTolerance: clickTolerance for touch events

Open
#10,061 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Motivation

A larger clickTolerance (like 20 pixels) makes sense for mobile/touch devices. Yet setting the same setting makes mouse usage really unpleasant, a simple panning starts with a "stutter", a slight freeze + jump.

Design Alternatives

Since clickTolerance is implemented in many levels already (MouseRotateWrapper, BoxZoomHandler, MouseHandler, TouchPanHandler) it'd be great to set it independently for click and touch events. For example, I'd like to set it to 20 pixels for touch events, while leaving it on 3 pixels for mouse events.

Alternatively, I'd be happy to use a workaround if there exists one. My only idea so far is to try to figure out device type using detect-it, like:

clickTolerance: detectIt.primaryInput === 'mouse' ? 3 : 20

The problem with this is that it is very much sub-optimal as it sets one global value for the whole device, with no idea how hybrid devices are used. Since Mapbox GL JS handles each event differently, it'd be great to specify this at init time, like:

clickTolerance: 3,
touchTolerance: 20,

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how clickTolerance is used in MouseRotateWrapper, BoxZoomHandler, MouseHandler, and TouchPanHandler, then inspect the map initialization options. The change should allow a separate touchTolerance while preserving the existing mouse clickTolerance behavior; verify that touch and mouse interactions use their respective thresholds.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.