fix: normalize longitude for popup coordinates (#2692)#2842
fix: normalize longitude for popup coordinates (#2692)#2842
Conversation
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.
|
There was a problem hiding this comment.
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.
| 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); | ||
| } |
There was a problem hiding this comment.
为了避免代码重复并提高可维护性,建议使用 @antv/l7-utils 包中已有的 longitude 工具函数来标准化经度。使用现有工具函数可以确保一致性并减少维护成本。
您需要从 @antv/l7-utils 导入 longitude 函数,如下所示:
import { DOM, anchorTranslate, anchorType, applyAnchorClass, longitude } from '@antv/l7-utils';| 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); |
描述
修复 Issue #2692: Popup 如果坐标点的经度大于180度,弹出框不会在实际经度弹出
问题
当 Popup 坐标的经度大于 180 度时,Popup 会在错误的位置显示。
解决方案
在将经纬度转换为容器坐标之前,先将经度标准化到 -180 ~ 180 范围内。
修改内容
packages/component/src/popup/popup.ts: 在updateLngLatPosition方法中添加经度标准化逻辑测试
Closes #2692
🤖 Generated with Claude Code