Skip to content

Commit 020273f

Browse files
committed
fix(DrawControl): 修复tooltip偏移问题 — extractClientXY正确处理L7图层事件坐标
L7图层mousemove事件中originalEvent可能缺少clientX/clientY, fallback到e.x/e.y时需要加上canvas的viewport偏移量才能得到正确的client坐标
1 parent c419886 commit 020273f

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

packages/core/src/components/Control/DrawControl/DrawLayerManager.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,30 @@ export class DrawLayerManager {
652652
/** 从 L7 事件中提取 clientX/clientY */
653653
private extractClientXY(e: Record<string, unknown>): [number, number] {
654654
const orig = (e.originalEvent ?? e.originEvent ?? e.e) as MouseEvent | undefined;
655-
return [orig?.clientX ?? (e.x as number) ?? 0, orig?.clientY ?? (e.y as number) ?? 0];
655+
// 优先使用 DOM MouseEvent 的 clientX/clientY(相对于视口)
656+
if (orig && typeof orig.clientX === 'number' && typeof orig.clientY === 'number') {
657+
return [orig.clientX, orig.clientY];
658+
}
659+
// fallback: L7 内部像素坐标 e.x/e.y 是相对于 canvas 的,需要加上 canvas 偏移
660+
const px = e.x as number | undefined;
661+
const py = e.y as number | undefined;
662+
if (px !== undefined && py !== undefined) {
663+
const container = this.mapsService?.getContainer?.() as HTMLElement | undefined;
664+
if (container) {
665+
const rect = container.getBoundingClientRect();
666+
return [px + rect.left, py + rect.top];
667+
}
668+
}
669+
// pixel 对象
670+
const pixel = e.pixel as Record<string, number> | undefined;
671+
if (pixel) {
672+
const container = this.mapsService?.getContainer?.() as HTMLElement | undefined;
673+
if (container) {
674+
const rect = container.getBoundingClientRect();
675+
return [(pixel.x ?? 0) + rect.left, (pixel.y ?? 0) + rect.top];
676+
}
677+
}
678+
return [0, 0];
656679
}
657680

658681
/** 从 L7 事件 feature 中提取指定属性(兼容 GeoJSON properties 和 JSON parser 直出) */

0 commit comments

Comments
 (0)