22
33import { extend , bindAll } from '../util/util.js' ;
44import { Event , Evented } from '../util/evented.js' ;
5- import { MapMouseEvent } from '../ui /events.js' ;
5+ import { MapMouseEvent } from './events.js' ;
66import DOM from '../util/dom.js' ;
77import LngLat from '../geo/lng_lat.js' ;
88import Point from '@mapbox/point-geometry' ;
@@ -19,7 +19,8 @@ const defaultOptions = {
1919 closeOnClick : true ,
2020 focusAfterOpen : true ,
2121 className : '' ,
22- maxWidth : "240px"
22+ maxWidth : "240px" ,
23+ stickyAnchor : 'bottom'
2324} ;
2425
2526export type Offset = number | PointLike | { [ _ : Anchor ] : PointLike } ;
@@ -32,7 +33,8 @@ export type PopupOptions = {
3233 anchor ?: Anchor ,
3334 offset ?: Offset ,
3435 className ?: string ,
35- maxWidth ?: string
36+ maxWidth ?: string ,
37+ stickyAnchor : Anchor
3638} ;
3739
3840const focusQuerySelector = [
@@ -57,6 +59,9 @@ const focusQuerySelector = [
5759 * map moves.
5860 * @param {boolean } [options.focusAfterOpen=true] If `true`, the popup will try to focus the
5961 * first focusable element inside the popup.
62+ * @param {string } [options.stickyAnchor='bottom'] - A string to set the preference for where the anchor will be
63+ * dynamically set. Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`,
64+ * `'bottom-left'`, and `'bottom-right'`.
6065 * @param {string } [options.anchor] - A string indicating the part of the popup that should
6166 * be positioned closest to the coordinate, set via {@link Popup#setLngLat}.
6267 * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
@@ -67,7 +72,7 @@ const focusQuerySelector = [
6772 * A pixel offset applied to the popup's location specified as:
6873 * - a single number specifying a distance from the popup's location
6974 * - a {@link PointLike} specifying a constant offset
70- * - an object of {@link Point}s specifing an offset for each anchor position.
75+ * - an object of {@link Point}s specifying an offset for each anchor position.
7176 *
7277 * Negative offsets indicate left and up.
7378 * @param {string } [options.className] Space-separated CSS class names to add to popup container.
@@ -575,7 +580,7 @@ export default class Popup extends Evented {
575580 }
576581
577582 if ( anchorComponents . length === 0 ) {
578- return ' bottom ' ;
583+ return this . options . stickyAnchor ;
579584 }
580585 return ( ( anchorComponents . join ( '-' ) : any ) : Anchor ) ;
581586
0 commit comments