Skip to content

fix: normalize longitude for Popup coordinates (fix #2692)#2848

Open
lzxue wants to merge 1 commit intomasterfrom
fix/popup-longitude-normalize
Open

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

Conversation

@lzxue
Copy link
Copy Markdown
Contributor

@lzxue lzxue commented Apr 12, 2026

修复内容

修复 Popup 组件在经度超过180度时无法正确显示的问题。

问题描述

解决方案

  • updateLngLatPosition 方法中添加经度归一化处理
  • 将超出 [-180, 180] 范围的经度值规范化到有效范围内

修改文件

  • packages/component/src/popup/popup.ts

测试

  • 经度 190度 应正确显示在 10度位置
  • 经度 -190度 应正确显示在 -10度位置
  • 正常的经度值不受影响

- Add longitude normalization to valid range [-180, 180] in updateLngLatPosition
- Fixes Popup not displaying correctly when longitude exceeds 180 degrees
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 12, 2026

⚠️ No Changeset found

Latest commit: 862b810

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 introduces longitude normalization to the Popup component to ensure coordinates remain within the [-180, 180] range. While the logic is correctly applied in the coordinate update method, the panToPopup method calculates the normalized value but fails to use it in the map service call. Additionally, it is recommended to extract this normalization logic into a reusable utility function to avoid code duplication and improve maintainability.

public panToPopup() {
const { lng, lat } = this.lngLat;
// Normalize longitude to valid range [-180, 180]
const normalizedLng = ((lng + 180) % 360 + 360) % 360 - 180;
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.

high

变量 normalizedLng 虽然已经计算,但在第 325 行的 this.mapsService.panTo([lng, lat]) 调用中并未使用。这会导致地图平移时使用的是原始经度而非归一化后的经度,在经度超过 180 度时可能导致平移位置不正确。

const { lng, lat } = this.lngLat;
const { x, y } = this.mapsService.lngLatToContainer([lng, lat]);
// Normalize longitude to valid range [-180, 180]
const normalizedLng = ((lng + 180) % 360 + 360) % 360 - 180;
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

经度归一化的逻辑 ((lng + 180) % 360 + 360) % 360 - 180panToPopupupdateLngLatPosition 中重复出现。建议将其提取为公共的工具函数或类内部的私有方法,以提高代码的可维护性和一致性。

References
  1. 遵循 DRY (Don't Repeat Yourself) 原则,避免重复的逻辑计算。

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.

1 participant