-
-
Notifications
You must be signed in to change notification settings - Fork 643
/
anchor.ts
27 lines (25 loc) · 939 Bytes
/
anchor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Where to position the anchor.
* Used by a popup and a marker.
*/
export type PositionAnchor = 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
export const anchorTranslate: {
[_ in PositionAnchor]: string;
} = {
'center': 'translate(-50%,-50%)',
'top': 'translate(-50%,0)',
'top-left': 'translate(0,0)',
'top-right': 'translate(-100%,0)',
'bottom': 'translate(-50%,-100%)',
'bottom-left': 'translate(0,-100%)',
'bottom-right': 'translate(-100%,-100%)',
'left': 'translate(0,-50%)',
'right': 'translate(-100%,-50%)'
};
export function applyAnchorClass(element: HTMLElement, anchor: PositionAnchor, prefix: string) {
const classList = element.classList;
for (const key in anchorTranslate) {
classList.remove(`maplibregl-${prefix}-anchor-${key}`);
}
classList.add(`maplibregl-${prefix}-anchor-${anchor}`);
}