Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 新版高德大于 21 级别抖动问题 #2433

Merged
merged 1 commit into from
Apr 28, 2024
Merged
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
20 changes: 18 additions & 2 deletions packages/maps/src/amap-next/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ export default class BMapService extends BaseMap<AMap.Map> {
};

private getViewState() {
const { center, zoom } = getMapHighPrecisionState(this.map);
const option = {
center: [this.map.getCenter().getLng(), this.map.getCenter().getLat()] as [number, number],
center: center,
viewportWidth: this.map.getContainer()!.clientWidth,
viewportHeight: this.map.getContainer()!.clientHeight,
bearing: -this.map.getRotation(),
pitch: this.map.getPitch(),
zoom: this.map.getZoom() - ZOOM_OFFSET,
zoom: zoom - ZOOM_OFFSET,
};

return option;
Expand Down Expand Up @@ -437,3 +438,18 @@ export default class BMapService extends BaseMap<AMap.Map> {
this.map.destroy();
}
}

/**
* 访问高精度的地图状态(临时解决方案)
* - 解决 map.getCenter() 方法只返回小数点五位有效数据
* - 解决 map.getZoom() 方法只返回小数点两位有效数据
*/
function getMapHighPrecisionState(map: AMap.Map) {
// @ts-expect-error 访问未暴露的内部属性
const viewStatus = map._view.getOptions();

const center: [number, number] = viewStatus.center;
const zoom: number = viewStatus.zoom;

return { center, zoom };
}
Loading