-
Notifications
You must be signed in to change notification settings - Fork 2.3k
preferred Popup anchor point can be customised for when anchor is dynamically anchoring #11055
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
base: main
Are you sure you want to change the base?
Conversation
A preference for where the anchor is set when there is space
d80f965
to
d397c8d
Compare
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.
Thank you for the contribution @anthony-hull! I like this feature, and I've experienced this same pain point.
I'm not sure what behavior a developer should expect if they have anchor
and anchorPreference
options enabled with different directions. I think there's a more intuitive way to implement this: a boolean value ( maybe fixedAnchor
as proposed in Issue #6965) that enables/disables adaptive anchor placement while placement always defaults to anchor
.
To maintain behavior in existing applications, this boolean should default to false
when anchor
is undefined and true
otherwise.
Your unit test is a great start! I'd like to see more thorough coverage of different possible states (combinations of options and positions on the map to ensure that the anchor is correctly dynamically anchoring).
Thanks again for your contribution! 🙏
Closes #6965
@SnailBones I'm picking up on this, and I'm going to follow the However, I noticed you stated the following:
If
Would you agree? |
@diebarral Agreed! To clarify, what's important is that the new feature maintains consistent behavior in existing apps (which is to have an adaptive anchor that defaults to "bottom" behavior when |
Sorry I forgot about this! Thank you for offering to finish it. |
@anthony-hull were you able to make some progress? If not, I have it done, I'm only missing some tests. Let me know if I can help you out with something. |
I'm just getting to it now :) my day job got busy! |
I have implemented the functionality. I will finish writing the tests tomorrow. Mapbox.GL.JS.debug.page.mp4 |
const fallbackPosition = 'bottom'; | ||
if ( | ||
this.options.fixedAnchor || | ||
(typeof (this.options.fixedAnchor) === 'undefined' && this.options.anchor) |
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:
(typeof (this.options.fixedAnchor) === 'undefined' && this.options.anchor) | |
this.options.fixedAnchor === undefined && this.options.anchor) |
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.
Thanks for following this up @anthony-hull!
I tested this out and found one issue: popups with fixedAnchor: false
and a non-bottom anchor don't correct expected when near the bottom of the screen, instead remaining in their default position.
I also added a few small nitpicks about code style.
Your added tests for default placement look great! Increasing test coverage for cases with fixedAnchor: false
would be helpful for catching issues like this.
if ( | ||
this.options.fixedAnchor || | ||
(typeof (this.options.fixedAnchor) === 'undefined' && this.options.anchor) | ||
) { |
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.
Could this be more readable if broken into two if
statements?
|
||
_getAnchor(bottomY: number): Anchor { | ||
if (this.options.anchor) { return this.options.anchor; } | ||
const fallbackPosition = 'bottom'; |
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.
const fallbackPosition = 'bottom'; | |
const fallbackPosition = this.options.anchor || 'bottom'; |
I think this could help clean up the later return statements
I'll get to this on Wednesday! thanks for the review. |
@anthony-hull Apologies for the short notice, but we're planning a beta release tomorrow. I'd love to include this if you'd have the time to clean it up before then! If not, we can include it in the next release. |
I'll do it first thing tomorrow. |
sorry tested positive for covid 🤕 I'll have to get to this later. |
I'm sorry to hear that @anthony-hull! I hope you feel better soon. |
@anthony-hull Hope you're feeling better by today, is there any progress on this one? |
A preference option for where the anchor is set when left to dynamically chose the best position.
Launch Checklist
@mapbox/map-design-team
@mapbox/static-apis
if this PR includes style spec API or visual changes@mapbox/gl-native
if this PR includes shader changes or needs a native portmapbox-gl-js
changelog:<changelog> Add anchorPreference option to PopupOptions which specifies the preferred anchor position when it is left to dynamically choose. </changelog>