fix: normalize longitude for Popup coordinates (fix #2692)#2848
fix: normalize longitude for Popup coordinates (fix #2692)#2848
Conversation
- Add longitude normalization to valid range [-180, 180] in updateLngLatPosition - Fixes Popup not displaying correctly when longitude exceeds 180 degrees
|
There was a problem hiding this comment.
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; |
| 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; |
修复内容
修复 Popup 组件在经度超过180度时无法正确显示的问题。
问题描述
解决方案
updateLngLatPosition方法中添加经度归一化处理修改文件
packages/component/src/popup/popup.ts测试