Skip to content

fix: 修复高 zoom 下经纬度投影精度偏移#2865

Merged
lzxue merged 3 commits into
antvis:masterfrom
MarkLei7:fix/issue-1578-coordinate-precision
Jul 6, 2026
Merged

fix: 修复高 zoom 下经纬度投影精度偏移#2865
lzxue merged 3 commits into
antvis:masterfrom
MarkLei7:fix/issue-1578-coordinate-precision

Conversation

@MarkLei7

@MarkLei7 MarkLei7 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 工作流程
  • 版本更新
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

Fixes #1578

💡 需求背景和解决方案

在高 zoom 层级下,使用经纬度数据绘制 L7 图层时,图层渲染位置会和鼠标位置 / 底图投影位置出现像素级偏移。这个问题在 L7 Draw 高层级绘制点、线、面时比较明显,表现为鼠标点击位置和最终绘制图形位置不重合。

原因主要有两处:

  1. LNGLAT_OFFSET 坐标链路里,shader 中 high / low 精度拆分后的 low part 过早参与大经纬度 float 计算,在高 zoom 下容易被 float32 舍入掉,导致低位精度没有真正补偿到最终屏幕投影。
  2. relative coordinates 场景下,setViewportCenter 会触发 viewport center 更新,但旧实现使用 Math.fround() 后的 center 计算 viewportCenterProjection,提前损失了中心点尾部精度。

本次修改:

  • projection.glsl 中新增 project_offset_with_low,让 fp64 low part 在 offset 转像素贡献时独立参与计算,避免被 GLSL 编译器提前折叠到大经纬度计算中。
  • CoordinateSystemService#setViewportCenter 场景下保留 exact center projection,避免 relative coordinates 路径提前丢失中心点精度。
  • 补充 issue1578CoordinatePrecision bugfix demo,用于验证高 zoom 下点、线、面以及 L7 Draw 绘制时的坐标一致性。
  • demo 中显示当前 zoom,并展示 draw 点击位置与 lngLatToContainer 反投影位置的像素差。

本地验证:

  • git diff --check
  • prettier --check
  • pnpm dev --host 127.0.0.1
  • demo: bugfix / issue1578CoordinatePrecision
  • 本地验证结果:
    • zoom: 22.000
    • DrawPoint 点击后:point last vertex delta: dx -0.00 px, dy 0.00 px

📝 更新日志

语言 更新描述
🇺🇸 英文 Fix high-zoom lnglat projection precision loss in LNGLAT_OFFSET, and add a bugfix demo for point, line, polygon, and L7 Draw alignment verification.
🇨🇳 中文 修复高 zoom 下 LNGLAT_OFFSET 经纬度投影精度损失导致的坐标偏移问题,并新增点、线、面及 L7 Draw 对齐验证 demo。

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1695ffd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@antv/l7-core Patch
@antv/l7-component Patch
@antv/l7 Patch
@antv/l7-layers Patch
@antv/l7-maps Patch
@antv/l7-renderer Patch
@antv/l7-scene Patch
@antv/l7-source Patch
@antv/l7-three Patch
@antv/l7-map Patch
@antv/l7-test-utils Patch
@antv/l7-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses high-zoom coordinate precision issues (Issue #1578). It introduces a new validation demo, updates CoordinateSystemService to support exact center projection without rounding, and modifies projection.glsl to keep fp64 low parts in explicit branches to prevent GLSL compilers from rounding away sub-ULP values. The review feedback highlights potential memory leaks in the demo code due to uncleaned global window resize listeners and undestroyed draw tools when the scene is destroyed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread examples/demos/bugfix/issue-1578-coordinate-precision.ts
Comment thread examples/demos/bugfix/issue-1578-coordinate-precision.ts
@lzxue lzxue merged commit 59a5216 into antvis:master Jul 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【BUG】L7在高缩放层级下经纬度和屏幕xy转换有偏差

2 participants