-
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
Open
anthony-hull
wants to merge
8
commits into
mapbox:main
Choose a base branch
from
anthony-hull:choose-a-sticky-anchor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b555794
anchor point can be set stickily
anthony-hull d397c8d
rename option to anchorPreference
anthony-hull dd61c6b
Merge branch 'mapbox:main' into choose-a-sticky-anchor
anthony-hull 96342b6
fixedAnchor bool and backwards compat with api
anthony-hull 434ae7d
documentation adjustment
anthony-hull 52c5d04
fixed anchor set but anchor undefined
anthony-hull 754922e
added unit tests
anthony-hull 8b27b9a
merge main
anthony-hull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |||||
|
|
||||||
| import {extend, bindAll} from '../util/util.js'; | ||||||
| import {Event, Evented} from '../util/evented.js'; | ||||||
| import {MapMouseEvent} from '../ui/events.js'; | ||||||
| import {MapMouseEvent} from './events.js'; | ||||||
| import * as DOM from '../util/dom.js'; | ||||||
| import LngLat from '../geo/lng_lat.js'; | ||||||
| import Point from '@mapbox/point-geometry'; | ||||||
|
|
@@ -19,7 +19,7 @@ const defaultOptions = { | |||||
| closeOnClick: true, | ||||||
| focusAfterOpen: true, | ||||||
| className: '', | ||||||
| maxWidth: "240px" | ||||||
| maxWidth: "240px", | ||||||
| }; | ||||||
|
|
||||||
| export type Offset = number | PointLike | {[_: Anchor]: PointLike}; | ||||||
|
|
@@ -32,7 +32,8 @@ export type PopupOptions = { | |||||
| anchor?: Anchor, | ||||||
| offset?: Offset, | ||||||
| className?: string, | ||||||
| maxWidth?: string | ||||||
| maxWidth?: string, | ||||||
| fixedAnchor: boolean | ||||||
| }; | ||||||
|
|
||||||
| const focusQuerySelector = [ | ||||||
|
|
@@ -57,6 +58,9 @@ const focusQuerySelector = [ | |||||
| * map moves. | ||||||
| * @param {boolean} [options.focusAfterOpen=true] If `true`, the popup will try to focus the | ||||||
| * first focusable element inside the popup. | ||||||
| * @param {boolean} [options.fixedAnchor] - If 'true', the popup will fix to the value set by | ||||||
| * `options.anchor`. If 'false' the anchor will be dynamically set to ensure the popup falls within | ||||||
| * the map container with a preference for the value set by `options.anchor`. | ||||||
| * @param {string} [options.anchor] - A string indicating the part of the popup that should | ||||||
| * be positioned closest to the coordinate, set via {@link Popup#setLngLat}. | ||||||
| * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, | ||||||
|
|
@@ -67,7 +71,7 @@ const focusQuerySelector = [ | |||||
| * A pixel offset applied to the popup's location specified as: | ||||||
| * - a single number specifying a distance from the popup's location | ||||||
| * - a {@link PointLike} specifying a constant offset | ||||||
| * - an object of {@link Point}s specifing an offset for each anchor position. | ||||||
| * - an object of {@link Point}s specifying an offset for each anchor position. | ||||||
| * | ||||||
| * Negative offsets indicate left and up. | ||||||
| * @param {string} [options.className] Space-separated CSS class names to add to popup container. | ||||||
|
|
@@ -540,13 +544,19 @@ export default class Popup extends Evented { | |||||
| } | ||||||
|
|
||||||
| _getAnchor(bottomY: number): Anchor { | ||||||
| if (this.options.anchor) { return this.options.anchor; } | ||||||
| const fallbackPosition = 'bottom'; | ||||||
| if ( | ||||||
| this.options.fixedAnchor || | ||||||
| (typeof (this.options.fixedAnchor) === 'undefined' && this.options.anchor) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
|
||||||
| ) { | ||||||
anthony-hull marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be more readable if broken into two |
||||||
| return this.options.anchor || fallbackPosition; | ||||||
| } | ||||||
|
|
||||||
| const map = this._map; | ||||||
| const container = this._container; | ||||||
| const pos = this._pos; | ||||||
|
|
||||||
| if (!map || !container || !pos) return 'bottom'; | ||||||
| if (!map || !container || !pos) return fallbackPosition; | ||||||
|
|
||||||
| const width = container.offsetWidth; | ||||||
| const height = container.offsetHeight; | ||||||
|
|
@@ -568,7 +578,7 @@ export default class Popup extends Evented { | |||||
| if (isLeft) return 'left'; | ||||||
| if (isRight) return 'right'; | ||||||
|
|
||||||
| return 'bottom'; | ||||||
| return this.options.anchor || fallbackPosition; | ||||||
| } | ||||||
|
|
||||||
| _updateClassList() { | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
I think this could help clean up the later return statements