Skip to content

fix: normalize longitude for popup coordinates (#2692)#2842

Open
lzxue wants to merge 1 commit intomasterfrom
fix/issue-2692-popup-coordinates
Open

fix: normalize longitude for popup coordinates (#2692)#2842
lzxue wants to merge 1 commit intomasterfrom
fix/issue-2692-popup-coordinates

Conversation

@lzxue
Copy link
Copy Markdown
Contributor

@lzxue lzxue commented Mar 30, 2026

描述

修复 Issue #2692: Popup 如果坐标点的经度大于180度,弹出框不会在实际经度弹出

问题

当 Popup 坐标的经度大于 180 度时,Popup 会在错误的位置显示。

解决方案

在将经纬度转换为容器坐标之前,先将经度标准化到 -180 ~ 180 范围内。

修改内容

  • packages/component/src/popup/popup.ts: 在 updateLngLatPosition 方法中添加经度标准化逻辑

测试

  • 手动验证经度 > 180 度时 Popup 位置正确
  • 手动验证经度 < -180 度时 Popup 位置正确
  • 手动验证正常经度范围 (-180 ~ 180) 不受影响

Closes #2692

🤖 Generated with Claude Code

Fixes #2692

When popup longitude is greater than 180 degrees, the popup
displays at the wrong position. This fix normalizes the longitude
to -180 ~ 180 range before converting to container coordinates.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 30, 2026

⚠️ No Changeset found

Latest commit: 29a2df4

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

Copy link
Copy Markdown
Contributor

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

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 adds longitude normalization to the Popup component to ensure coordinates remain within the -180 to 180 degree range before being converted to container coordinates. The reviewer recommends replacing the manual normalization logic with the existing 'longitude' utility function from the @antv/l7-utils package to improve code reuse and maintainability.

Comment on lines +401 to +406
let normalizedLng = lng;
if (lng > 180) {
normalizedLng = lng - 360 * Math.floor((lng + 180) / 360);
} else if (lng < -180) {
normalizedLng = lng + 360 * Math.floor((-lng + 180) / 360);
}
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.

medium

为了避免代码重复并提高可维护性,建议使用 @antv/l7-utils 包中已有的 longitude 工具函数来标准化经度。使用现有工具函数可以确保一致性并减少维护成本。

您需要从 @antv/l7-utils 导入 longitude 函数,如下所示:

import { DOM, anchorTranslate, anchorType, applyAnchorClass, longitude } from '@antv/l7-utils';
Suggested change
let normalizedLng = lng;
if (lng > 180) {
normalizedLng = lng - 360 * Math.floor((lng + 180) / 360);
} else if (lng < -180) {
normalizedLng = lng + 360 * Math.floor((-lng + 180) / 360);
}
const normalizedLng = longitude(lng);

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.

Popup 如果坐标点的经度大于180度,弹出框不会在实际经度弹出,最多只能在180的经度显示

2 participants