-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathinfotip.mjs
41 lines (27 loc) · 1.09 KB
/
infotip.mjs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const infotip = {}
export default function(content) {
const mapview = this;
// Remove infotip node element
infotip.node?.remove()
// Remove infotip positioning event from mapview Map.
mapview.Map.un('pointermove', position)
// Just clears the infotip.
if (!content) return;
// Creates the infotip node.
infotip.node = mapp.utils.html.node`<div class="infotip box-shadow">`
// Assigns the infotip content.
infotip.node.innerHTML = content
// Appends the infotip to the mapview.Map.
mapview.Map.getTargetElement().appendChild(infotip.node)
// Assign infotip positioning event to mapview.Map.
mapview.Map.on('pointermove', position)
// Set the position of the infotip.
position()
function position() {
// The infotip class has a default opacity of 0, with transition effect.
infotip.node.style.opacity = 1;
// Set the infotip position from mapview pointerLocation.
infotip.node.style.left = mapview.pointerLocation.x - infotip.node.offsetWidth / 2 + 'px'
infotip.node.style.top = mapview.pointerLocation.y - infotip.node.offsetHeight - 15 + 'px'
}
}