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
7 changes: 5 additions & 2 deletions packages/maps/src/amap-next/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,14 @@ export default class BMapService extends BaseMap<AMap.Map> {
this.map.panBy(x, y);
}

public fitBounds(extent: Bounds): void {
public fitBounds(extent: Bounds, fitBoundsOptions?: any): void {

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

建议将 fitBoundsOptions 的类型从 any 改为更具体的类型(如 { animate?: boolean })或 unknown,以符合 IMapService 接口的定义并提升类型安全性。

Suggested change
public fitBounds(extent: Bounds, fitBoundsOptions?: any): void {
public fitBounds(extent: Bounds, fitBoundsOptions?: { animate?: boolean }): void {

const animate = fitBoundsOptions?.animate ?? false;
this.map.setBounds(
new AMap.Bounds([extent[0][0], extent[0][1], extent[1][0], extent[1][1]]),
// @ts-expect-error 立即缩放到指定位置
// @ts-expect-error 第二个参数配置
true,
// @ts-expect-error animate 参数,控制动画效果
animate,
Comment on lines 314 to +316

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

这里的参数传递逻辑存在错误。在高德地图 2.0 API 中,setBounds 的第二个参数是 immediately(是否立即跳转)。如果将其硬编码为 true,则无论 animate 为何值,地图都会立即跳转而不会有动画效果。此外,animate 应该是第四个参数,而当前代码将其作为第三个参数(avoid,即边距)传入。

建议将第二个参数设为 !animate,并正确传递 animate 作为第四个参数。

      !animate,
      // @ts-expect-error avoid 参数
      undefined,
      // @ts-expect-error animate 参数
      animate,

);
}

Expand Down
Loading