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

Correct mouse/touch position for elements scaled via CSS transform #9057

Closed
wants to merge 2 commits into from

Conversation

kkaefer
Copy link
Member

@kkaefer kkaefer commented Dec 3, 2019

Inspired by #9014, I looked at correcting mouse/touch interaction when the Map is transformed via the CSS transform: scale() property. It scales the screen pixel coordinates to logical map coordinates.

This is distinct from pixelRatio.

I tested in Safari, Chrome and Firefox on macOS.

@jingsam
Copy link
Contributor

jingsam commented Dec 4, 2019

How css transform affects el.clientLeft ? Does it return the original size or tranformed size?

@kkaefer
Copy link
Member Author

kkaefer commented Dec 4, 2019

Good catch, @jingsam. clientLeft does not have the transform applied, so I moved it to outside the multiplication. However, this only matters if a user applies a border or scrollbar to the <div class="mapboxgl-canvas-container"></div> that we use for tracking events, and I'm having a hard time seeing why anyone would do that.

@kkaefer
Copy link
Member Author

kkaefer commented Dec 4, 2019

Fixes #6079

@kkaefer
Copy link
Member Author

kkaefer commented Dec 4, 2019

Previous attempt to solve this was discarded in #8017. I tested this PR on iOS Safari and it works as expected.

@kkaefer
Copy link
Member Author

kkaefer commented Dec 4, 2019

Unfortunately, JSDom doesn't have a layout engine, so our unit tests fail due to division by zero.

@jingsam
Copy link
Contributor

jingsam commented Dec 5, 2019

@kkaefer great work. Does it affect performance?

Copy link
Contributor

@ryanhamley ryanhamley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I tested it with transform: scale(), padding and margins all set and it worked as expected. Do you have an idea on how to fix the tests?

@kkaefer
Copy link
Member Author

kkaefer commented Jan 6, 2020

Do you have an idea on how to fix the tests?

We could either mock the getters, but that kind of means we're only testing our mock values. I think a better approach would be to switch unit tests to run in a browser and e.g. use puppeteer on CI to run them.

@asheemmamoowala
Copy link
Contributor

Now that we have selenium tests (#9245), what are the next steps needed to land this PR?

@kkaefer
Copy link
Member Author

kkaefer commented Mar 19, 2020

what are the next steps needed to land this PR?

Write a selenium test that double clicks/taps, or sends mouse wheel events at a particular location and check that the resulting zoom correctly reflects the location when the container is zoomed via CSS.

@karimnaaji
Copy link
Contributor

@ryanhamley still good for release-d?

@ryanhamley
Copy link
Contributor

@kkaefer I tried to add a Selenium test and it works locally but fails on CI. Do you have any insight into what I might be doing wrong?

@kkaefer
Copy link
Member Author

kkaefer commented Apr 7, 2020

@ryanhamley it could be related to pixel ratio. I think our Selenium tests on CI are running at 1×, while your tests locally are running at 2×.

@karimnaaji karimnaaji modified the milestones: release-d, release-e Apr 7, 2020
@sgolbabaei
Copy link
Contributor

Is this good for release-e? @ryanhamley

@ryanhamley
Copy link
Contributor

@sgolbabaei I need to take a look at this tomorrow or Friday. The Selenium test I wrote fails on CI and I'm not sure how to get it to pass locally and on CI if the problem is the pixel ratio. Looks like it needs to be rebased against master too

@ryanhamley
Copy link
Contributor

After playing around with this some more, I'm not convinced that this fixes the issue. Or at least, I'm running into some confusing behavior. Compare this demo showing the bug and the behavior in this forked version which uses this branch. The click is correct, but zooming behaves differently. Similarly, in this demo which uses this branch, zooming appears to not work as expected. When I have basically the same set up in a local debug page though, things work as expected.

@ryanhamley
Copy link
Contributor

After consulting with the team, it looks like @karimnaaji is working on implementing dynamic scaling in a way that would make this change unnecessary. I'm going to close this PR in anticipation of that work being a more robust solution. If we find that the need for this still exists in the future, we can revisit it.

@ryanhamley ryanhamley closed this May 26, 2020
@ryanhamley ryanhamley removed this from the release-e milestone May 26, 2020
@adamcbrewer
Copy link

@ryanhamley @karimnaaji is there any update with regards to dynamic scaling?

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

Successfully merging this pull request may close these issues.

7 participants