Skip to content

fix: correct coordinate rendering offset at maximum zoom via fp64 viewport center#2817

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-drawpolygon-offset-issue
Open

fix: correct coordinate rendering offset at maximum zoom via fp64 viewport center#2817
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-drawpolygon-offset-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 25, 2026

At maximum zoom levels on AMap (zoom 21+), drawn points render 20–40px away from the actual click position. The LNGLAT_OFFSET coordinate system (active when zoom > 12) uses fp64 split encoding for vertex positions, but the viewport center passed as u_ViewportCenter is a float32 uniform — silently dropping fp64LowPart(center) ≈ 6e-6°, which maps to ~18–36px error at zoom 21–22.

Changes

  • scene_uniforms.glsl: Add vec2 u_ViewportCenterLow to the UBO struct (fits in existing 96-float buffer)
  • projection.glsl: In the LNGLAT_OFFSET path, subtract u_ViewportCenterLow from the computed offset to achieve full double-precision center subtraction:
// Before: error = fp64LowPart(center) ≈ 6e-6° → ~20–36px at max zoom
return project_offset(vec4(X + absolutePosition64xyLow.x, Y + absolutePosition64xyLow.y, ...));

// After: vertex.x - center.x with full float64 accuracy
return project_offset(vec4(
  X + absolutePosition64xyLow.x - u_ViewportCenterLow.x,
  Y + absolutePosition64xyLow.y - u_ViewportCenterLow.y, ...
));
  • CoordinateSystemService: Compute viewportCenterLow = [center[0] - Math.fround(center[0]), center[1] - Math.fround(center[1])] on every refresh()
  • ICoordinateSystemService: Add ViewportCenterLow to CoordinateUniform enum and getViewportCenterLow() to the interface
  • ShaderUniformPlugin: Retrieve and pack u_ViewportCenterLow into the UBO data array and WebGL1 uniforms fallback
Original prompt

This section details on the original issue you should resolve

<issue_title>drawPolygon绘制,光标位置和渲染的点位置偏移严重,</issue_title>
<issue_description>### 问题描述

问题描述
把高德地图放到最大时候, drawPolygon绘制,光标位置和渲染的点位置偏移严重
似乎是地图放到最大,l7坐标渲染的位置和底图坐标渲染的位置有一定误差导致的

重现链接

https://l7draw.antv.vision/example/polygon/start

重现步骤

在上面重新链接里,把地图放到最大,然后启用绘制,会发现,光标点击的位置和绘制的点位置偏移严重

预期行为

No response

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]

屏幕截图或视频(可选)

Image

补充说明(可选)

No response</issue_description>

<agent_instructions>看看这个 issue,尝试解决一下</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@lzxue 应该是高精度的问题

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 25, 2026

⚠️ No Changeset found

Latest commit: 338a416

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

…ax zoom

At high zoom levels (>12) in LNGLAT_OFFSET mode, the shader subtracts the
viewport center from vertex positions. Since uniforms are float32, the viewport
center loses its fp64 low part (fp64LowPart(center) ≈ 6e-6 degrees), causing
an 18-36 pixel rendering offset at zoom 21-22.

The fix adds a u_ViewportCenterLow uniform containing fp64LowPart(center),
which is subtracted from the computed offset in the shader. This achieves full
double-precision accuracy for the center subtraction.

Changes:
- scene_uniforms.glsl: Add vec2 u_ViewportCenterLow
- projection.glsl: Subtract u_ViewportCenterLow in LNGLAT_OFFSET path
- ICoordinateSystemService.ts: Add ViewportCenterLow to enum and interface
- CoordinateSystemService.ts: Compute viewportCenterLow = fp64LowPart(center)
- ShaderUniformPlugin.ts: Pass u_ViewportCenterLow in UBO data and uniforms

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
@hustcc hustcc marked this pull request as ready for review February 25, 2026 04:33
Copilot AI changed the title [WIP] Fix severe offset in drawPolygon cursor and rendering points fix: correct coordinate rendering offset at maximum zoom via fp64 viewport center Feb 25, 2026
Copilot AI requested a review from hustcc February 25, 2026 04:34
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.

drawPolygon绘制,光标位置和渲染的点位置偏移严重,

2 participants