-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
There was a problem hiding this 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?
@SnailBones any chance to get this merged and released? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@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! |
There was a problem hiding this 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.
There was a problem hiding this 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}; |
There was a problem hiding this comment.
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.
Can anyone comment on the release cadence and when this particular fix might get released? |
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
After
Launch Checklist
mapbox-gl-js
changelog:<changelog>Canvas size evaluates to expected value when applying the css transform property</changelog>