| | |
| | | if (!this.mapView) return; |
| | | |
| | | const pixel = this.mapView.lngLatToContainer(item.position); |
| | | this.tooltipPos = { left: pixel.x, top: pixel.y }; |
| | | |
| | | // 获取当前缩放比例 |
| | | let scaleX = 1; |
| | | let scaleY = 1; |
| | | const app = document.querySelector('#app'); |
| | | if (app) { |
| | | const rect = app.getBoundingClientRect(); |
| | | // offsetWidth 是元素的布局宽度(不包含 transform) |
| | | // rect.width 是元素的渲染宽度(包含 transform) |
| | | if (app.offsetWidth > 0) { |
| | | scaleX = rect.width / app.offsetWidth; |
| | | } |
| | | if (app.offsetHeight > 0) { |
| | | scaleY = rect.height / app.offsetHeight; |
| | | } |
| | | } |
| | | |
| | | this.tooltipPos = { left: pixel.x / scaleX, top: pixel.y / scaleY - 60 }; |
| | | this.tooltipVisible = true; |
| | | this.tooltipLoading = true; |
| | | this.tooltipError = false; |