吉安感知网项目-前端
罗广辉
2026-01-31 b2670c2a7f71fa80ebf1e5702bb23f33e4f2dcdc
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
export class MapTooltip {
    constructor(viewer, options = {}) {
        this.viewer = viewer
        this.options = options
        this.container = viewer?.container || null
        this.tooltipEl = null
        this.isVisible = false
        this.init()
    }
 
    init() {
        if (!this.container || this.tooltipEl) return
        const el = document.createElement('div')
        el.style.position = 'absolute'
        el.style.pointerEvents = 'none'
        el.style.padding = '6px 8px'
        el.style.background = 'rgba(0, 0, 0, 0.65)'
        el.style.color = '#fff'
        el.style.fontSize = '12px'
        el.style.borderRadius = '4px'
        el.style.whiteSpace = 'nowrap'
        el.style.zIndex = '1000'
        el.style.display = 'none'
        this.container.appendChild(el)
        this.tooltipEl = el
    }
 
    show(text, position) {
        if (!this.tooltipEl) return
        this.tooltipEl.textContent = text || ''
        this.tooltipEl.style.display = 'block'
        this.isVisible = true
        if (position) this.move(position)
    }
 
    move(position) {
        if (!this.tooltipEl || !position) return
        const offset = this.options.offset || { x: 12, y: 12 }
        this.tooltipEl.style.left = `${position.x + offset.x}px`
        this.tooltipEl.style.top = `${position.y + offset.y}px`
    }
 
    hide() {
        if (!this.tooltipEl) return
        this.tooltipEl.style.display = 'none'
        this.isVisible = false
    }
 
    destroy() {
        this.hide()
        if (this.tooltipEl && this.container) {
            this.container.removeChild(this.tooltipEl)
        }
        this.tooltipEl = null
        this.container = null
        this.viewer = null
    }
}