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

Fix canvas sizing with cases that use the css property transform #11310

Merged
merged 23 commits into from
Dec 14, 2021

Conversation

avpeery
Copy link
Contributor

@avpeery avpeery commented Nov 23, 2021

Issue #11085 demonstrates a regression introduced in v2.5.0. PR #10936 introduced using getBoundingClientRect to obtain the canvas width and height for more precise values; instead of using clientWidth and clientHeight. However, an edge case was discovered that getBoundingClientRect returns its values after CSS transformations.

In order to fix this issue, a check is done to see if getBoundingClientRect when rounded is not equal to clientWidth or clientHeight (this case would be indicative that a transform(scale) was used). The difference between getBoundingClientRect and clientWidth/clientHeight is calculated and applied to getBoundingClientRect to get the actual expected value.

Added properties _containerWidth and _containerHeight to map to eliminate need to reevaluate the transform difference in other areas where getBoundingClientRect is used to find container height and width.

The debug page was adapted to include transform, please manually test this page which is also a release testing page.

Before

Screen Shot 2021-11-23 at 3 51 42 PM

After

Screen Shot 2021-11-23 at 3 52 19 PM

Launch Checklist

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • manually test the debug page
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Canvas size evaluates to expected value when applying the css transform property</changelog>

Copy link
Contributor

@SnailBones SnailBones left a comment

Choose a reason for hiding this comment

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

Great work on this @avpeery!

Would it be possible to add one more unit test to check that the transform(scale) regression doesn't happen again?

src/ui/map.js Outdated Show resolved Hide resolved
@felix-ht
Copy link

felix-ht commented Dec 1, 2021

@SnailBones any chance to get this merged and released?

Copy link
Contributor

@SnailBones SnailBones left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@avpeery
Copy link
Contributor Author

avpeery commented Dec 1, 2021

@arindam1993 if you can give a review, that would be helpful too! is there potentially any case containerDimension() will get called when there is no container? If so, I can fix the removal of setting width and height to 0 before checking if there's a container. @SnailBones thanks for the review!

src/ui/map.js Outdated Show resolved Hide resolved
Copy link
Contributor

@arindam1993 arindam1993 left a comment

Choose a reason for hiding this comment

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

Approach itself looks good to me, but I think we should just make it very explicit that the container dimensions are something thats updated and cached on the Map.

src/ui/map.js Show resolved Hide resolved
src/ui/map.js Outdated Show resolved Hide resolved
src/ui/map.js Outdated Show resolved Hide resolved
src/ui/map.js Outdated Show resolved Hide resolved
test/unit/terrain/terrain.test.js Show resolved Hide resolved
@avpeery avpeery requested review from mourner and removed request for arindam1993 December 13, 2021 04:53
Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

👍

src/ui/map.js Outdated
* @returns {object}
*/
_getContainerDimensions(): {width: number, height: number} {
return {width: this._containerWidth, height: this._containerHeight};
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we could use map._containerWidth and map. _containerHeight directly instead of adding one more method that wraps them to simplify the code — we always unwrap the values when using them anyway.

@avpeery avpeery merged commit f295ee9 into main Dec 14, 2021
@avpeery avpeery deleted the avpeery/fix-canvas-sizing-alternate branch December 14, 2021 00:16
@treehousetim
Copy link

Can anyone comment on the release cadence and when this particular fix might get released?

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.

Map canvas sizing broken when contained in a transform scale container in v2.5.0
6 participants