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
9 changes: 8 additions & 1 deletion packages/component/src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,14 @@ 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 -180 ~ 180 range
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);
}
Comment on lines +401 to +406

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);

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

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