Correct mouse/touch position for maps scaled with CSS transform #218
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When you scale the GL container using a CSS transform, i.e.
transform: scale(N)
, interacting with the map becomes difficult because theDOM.touchPos
andDOM.mousePos
functions do not correct for this scaling factorN
.This issue has been raised before (Nov. 2019) in the Mapbox GL repository, but the PRs [1, 2] were never accepted due to the development team at the time waiting for a more robust solution to be made. Sadly, this solution never came to be. For this reason, this piece of code has been something that I had to manually paste into my own version of GL every time I required the functionality. I would like to re-evaluate whether this could be added to the Maplibre GL project at this time for practical reasons.
Full disclosure: this code is based on a rejected PR in the Mapbox GL repository [2] of which I am not the author. This PR was submitted on Dec 3, 2019 for version 1.x.