Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/component/src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ export default class Popup<O extends IPopupOption = IPopupOption>
*/
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 度时可能导致平移位置不正确。

if (this.popupOption.autoPan) {
this.mapsService.panTo([lng, lat]);
}
Expand Down Expand Up @@ -397,7 +399,9 @@ export default class Popup<O extends IPopupOption = IPopupOption>
return;
}
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) 原则,避免重复的逻辑计算。

const { x, y } = this.mapsService.lngLatToContainer([normalizedLng, lat]);

this.setPopupPosition(x, y);
};
Expand Down
Loading