From 50eae3d37dbc8e210b845c6b959c9b7dedb88d01 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Sat, 31 Jan 2026 15:35:44 +0800
Subject: [PATCH] feat:tooltip提示优化
---
applications/drone-command/src/utils/cesium/shapeTools/Tooltip.js | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/applications/drone-command/src/utils/cesium/shapeTools/Tooltip.js b/applications/drone-command/src/utils/cesium/shapeTools/Tooltip.js
index 9fe2151..6ad6aef 100644
--- a/applications/drone-command/src/utils/cesium/shapeTools/Tooltip.js
+++ b/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)
}
--
Gitblit v1.9.3