Skip to content

fix: enable animate option for GaodeMap fitBounds (fix #2704)#2853

Open
lzxue wants to merge 1 commit intomasterfrom
fix/gaode-fitbounds-animate
Open

fix: enable animate option for GaodeMap fitBounds (fix #2704)#2853
lzxue wants to merge 1 commit intomasterfrom
fix/gaode-fitbounds-animate

Conversation

@lzxue
Copy link
Copy Markdown
Contributor

@lzxue lzxue commented May 5, 2026

修复 Issue #2704: 当使用GaodeMap时,scene.fitBounds(bounds, {animate: true})无动画效果

修改内容

  • 为高德地图的 fitBounds 方法添加 fitBoundsOptions 参数支持
  • 从 fitBoundsOptions 中提取 animate 参数并传递给高德地图的 setBounds 方法
  • 默认 animate 为 false,保持原有行为

影响范围

只影响高德地图 (amap-next),其他地图保持不变。

测试方法

scene.fitBounds(bounds, { animate: true });

使用高德地图时,现在应该有过渡动画效果。

修复 Issue #2704: 当使用GaodeMap时,scene.fitBounds(bounds, {animate: true})无动画效果

修改内容:
- 为高德地图的 fitBounds 方法添加 fitBoundsOptions 参数支持
- 从 fitBoundsOptions 中提取 animate 参数并传递给高德地图的 setBounds 方法
- 默认 animate 为 false,保持原有行为
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

⚠️ No Changeset found

Latest commit: 1d88057

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the fitBounds method in the AMap service to support animation options via a new fitBoundsOptions parameter. Feedback identifies a logic error where the immediately parameter is hardcoded to true, which prevents animations from occurring regardless of the animate flag. Additionally, the animate argument is being passed to the wrong parameter index in the setBounds call. The reviewer also recommends replacing the any type for the options parameter with a more specific type definition to improve type safety.

Comment on lines 314 to +316
true,
// @ts-expect-error animate 参数,控制动画效果
animate,
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,

}

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 {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant