Skip to content

feat(maps): 支持自定义高德地图 JS 版本#2863

Open
lzxue wants to merge 1 commit into
masterfrom
feature/support-amap-version
Open

feat(maps): 支持自定义高德地图 JS 版本#2863
lzxue wants to merge 1 commit into
masterfrom
feature/support-amap-version

Conversation

@lzxue

@lzxue lzxue commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

修复 Issue #2862

问题描述

用户希望能够自定义高德地图的 JS 版本,而不是使用硬编码的 2.0 版本。

解决方案

init 方法中添加 version 配置项,允许用户通过传入配置参数自定义版本,默认为 AMAP_VERSION (2.0)。

代码修改

  • 在配置解构中添加 version = AMAP_VERSION
  • AMapLoader.load 中的 version 参数改为使用配置值

使用示例

new GaodeMap({
  version: '1.4.15',  // 指定高德地图 JS 版本
  token: 'your-token',
  style: 'light'
});

相关 Issue

修复 issue #2862

允许用户通过 version 配置项自定义高德地图 JS 版本,默认为 2.0

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

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.

Code Review

This pull request introduces the ability to configure the AMap JSAPI version dynamically via the map configuration, defaulting to AMAP_VERSION. The review feedback highlights a variable shadowing issue where the destructured version variable conflicts with the existing class property this.version. It is recommended to rename the destructured variable to amapVersion to prevent confusion and improve code maintainability.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

token,
mapInstance,
plugin = [],
version = AMAP_VERSION,

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

init 方法中,解构出的局部变量 version 与类属性 this.version(定义在第 39 行 public version = MapType.GAODE;)同名。这会造成变量遮蔽(Shadowing),容易引起混淆并增加维护成本。建议在解构时将其重命名,例如 version: amapVersion

Suggested change
version = AMAP_VERSION,
version: amapVersion = AMAP_VERSION,

await AMapLoader.load({
key: amapKey, // 申请好的Web端开发者Key,首次调用 load 时必填
version: AMAP_VERSION, // 指定要加载的 JSAPI 的版本
version: version, // 指定要加载的 JSAPI 的版本

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

配合前面解构时的重命名,这里应将 version 替换为 amapVersion,以避免使用被遮蔽的变量名并保持上下文清晰。

Suggested change
version: version, // 指定要加载的 JSAPI 的版本
version: amapVersion, // 指定要加载 of JSAPI 的版本

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.

高德js版本可以指定吗?

1 participant