吉安感知网项目-前端
shuishen
2026-01-31 50eae3d37dbc8e210b845c6b959c9b7dedb88d01
applications/drone-command/src/utils/cesium/shapeTools/Tooltip.js
@@ -5,6 +5,7 @@
      this.container = viewer?.container || null
      this.tooltipEl = null
      this.isVisible = false
      this.handleMouseLeave = this.handleMouseLeave.bind(this)
      this.init()
   }
@@ -23,6 +24,8 @@
      el.style.display = 'none'
      this.container.appendChild(el)
      this.tooltipEl = el
      this.container.addEventListener('mouseleave', this.handleMouseLeave)
      this.container.addEventListener('pointerleave', this.handleMouseLeave)
   }
   show(text, position) {
@@ -35,6 +38,19 @@
   move(position) {
      if (!this.tooltipEl || !position) return
      const width = this.container?.clientWidth ?? 0
      const height = this.container?.clientHeight ?? 0
      if (
         !width ||
         !height ||
         position.x < 0 ||
         position.y < 0 ||
         position.x > width ||
         position.y > height
      ) {
         this.hide()
         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`
@@ -46,8 +62,16 @@
      this.isVisible = false
   }
   handleMouseLeave() {
      this.hide()
   }
   destroy() {
      this.hide()
      if (this.container) {
         this.container.removeEventListener('mouseleave', this.handleMouseLeave)
         this.container.removeEventListener('pointerleave', this.handleMouseLeave)
      }
      if (this.tooltipEl && this.container) {
         this.container.removeChild(this.tooltipEl)
      }