Skip to content

refactor(maps): migrate gmap & tdtmap adapters to BaseMap#2875

Open
lzxue wants to merge 4 commits into
masterfrom
feat/basemap-migration-gmap-tdtmap
Open

refactor(maps): migrate gmap & tdtmap adapters to BaseMap#2875
lzxue wants to merge 4 commits into
masterfrom
feat/basemap-migration-gmap-tdtmap

Conversation

@lzxue

@lzxue lzxue commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

refactor(maps): gmap & tdtmap 迁移到 BaseMap

延续上一轮创建的 lib/base-map.tsBaseMap,取代已 @deprecatedutils/BaseMapService)。此前仅 amap-next 用了新基类,本轮把两个使用 any 类型参数的非 mapbox 适配器迁过去,行为保持不变。

改动(gmap, tdtmap)

  • extends BaseMapService<any>extends BaseMap<any>
  • $mapContainermapContainerBaseMap 字段名)
  • cameraChangedCallback(viewport)cameraChangedCallback?.(viewport)(与已迁移的 amap-next 一致,BaseMap 中该字段为可选)
  • tdtmapviewport 声明由 IViewport | null = null 改为 IViewport = new Viewport()BaseMap 抽象属性声明为非空 IViewport,原 BaseMapService 声明为 IViewport | unknown(= unknown)才掩盖了不兼容 —— 此处对齐 amap-next 范式
  • 显式补全原先继承自 BaseMapService 的抽象方法(getMapStyle/getMapStyleConfig/setMaxZoom/setMinZoom 等),方法体与原继承实现逐字一致

bmap / tmap 暂未迁移

其地图类型 BMapGL.Map / TMap.Map@types 不完整,原 BaseMapService 通过 implements IMapService<Map & T> 交集借用了 mapbase Map 的方法签名,迁移到 BaseMap 后会暴露 on/off/getMinZoom/getContainerTS2333,需配合 @types 补全或类型放宽决策后再单独处理(已在 commit message 标注)。

验证

  • @antv/l7-maps esm/cjs(52 文件)+ umd 全部构建通过
  • tscTS2654/TS2416
  • eslint 通过

后续(未在本 PR 范围)

  • mapbox 类适配器(map/mapbox/maplibre/earth):严重继承 BaseMapService 约 30 个 mapbox 通用实现,需先抽 MapboxBaseMap extends BaseMap 中间基类
  • bmap/tmap:待 @types 决策
  • 全部迁完后删除 utils/BaseMapService.ts 及其导出

改动

2 files changed, 90 insertions(+), 23 deletions(-)

将两个使用 any 类型参数的非 mapbox 适配器从已废弃的 BaseMapService
迁移到新基类 BaseMap (lib/base-map.ts),行为保持不变:

- gmap, tdtmap: extends BaseMapService -> extends BaseMap
- $mapContainer -> mapContainer (BaseMap 字段名)
- cameraChangedCallback(viewport) -> cameraChangedCallback?.(viewport)
  (与已迁移的 amap-next 一致,BaseMap 中该字段为可选)
- tdtmap: viewport 声明由 IViewport | null = null 改为 IViewport = new Viewport()
  (BaseMap 抽象属性声明为非空 IViewport;原 BaseMapService 声明为
  IViewport | unknown 才掩盖了不兼容。与 amap-next 范式一致)
- 显式补全原先继承自 BaseMapService 的抽象方法
  (getMapStyle/getMapStyleConfig/setMaxZoom/setMinZoom 等),方法体与原继承实现逐字一致

bmap/tmap 暂未迁移: 其地图类型 (BMapGL.Map/TMap.Map) 的 @types 不完整,
原 BaseMapService 通过 IMapService<Map & T> 交集借用 mapbase Map 的方法签名,
迁移到 BaseMap 后会暴露 on/off/getMinZoom/getContainer 等 TS2333,
需配合 @types 补全或类型放宽决策后再单独处理。

构建验证: @antv/l7-maps esm/cjs (52 文件) + umd 全部通过; tsc 无 TS2654/TS2416;
eslint 通过。
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d16a900

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

@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 refactors GMapService and TdtMapService to extend BaseMap instead of BaseMapService, renaming $mapContainer to mapContainer and explicitly implementing several map-related methods. The review feedback highlights that the newly added getMapStyle and setMapStyle methods in both services contain Mapbox-specific logic that is incompatible with Google Maps and TianDiTu, resulting in dead code and potential runtime errors. Additionally, it is recommended to initialize the viewport property directly in GMapService to align with TdtMapService and improve type safety.

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.

Comment thread packages/maps/src/tdtmap/map.ts
Comment thread packages/maps/src/gmap/map.ts Outdated
Comment on lines +367 to +378
public getMapStyle(): string {
try {
// @ts-ignore
const styleUrl = this.map.getStyle().sprite ?? '';
if (/^mapbox:\/\/sprites\/zcxduo\/\w+\/\w+$/.test(styleUrl)) {
return styleUrl?.replace(/\/\w+$/, '').replace(/sprites/, 'styles');
}
return styleUrl;
} catch {
return '';
}
}

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

The getMapStyle method was copied verbatim from the Mapbox-centric BaseMapService. However, Google Maps (google.maps.Map) does not have a getStyle() method. This Mapbox-specific code is dead code and will always throw an error, falling back to returning ''.

We should simplify this to return the configured style from this.config.style or an empty string.

  public getMapStyle(): string {
    return this.config.style ?? '';
  }

@lzxue

lzxue commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

CI 失败说明(非代码问题)

本 PR 的 lint / unit-test / size-test 三个 job 都在 install 阶段 ~10s 内失败

[ERROR] Cannot use 'in' operator to search for 'integrity' in undefined

根因.github/actions/prepare-install/action.yml 用浮动 version: 11,近期解析到新发布的 pnpm 11.13.0,它读当前 lockfile(由 pnpm@11.12.0 生成)时崩溃。与本 PR 的代码改动无关——本 PR 只动了 (见文件清单),不碰 lockfile/package.json/workflow。

对照证据:较早的 PR(#2863 / #2856 / #2853 等)跑 lint (20.x) 全 pass 且耗时 2 分钟+;近期 11.13.0 发布后所有新 PR 才开始 10s 内崩在 install。

修复:已开 #2876 固定 pnpm 到 11.12.0

注:#2876 因 ci.yml 的 paths: [packages/**, __tests__/**] filter 不触发 lint workflow,无法自验证;为让本 PR 的 CI 真正跑起来验证代码,已在本分支附带该 1 行 pin(见相关 commit)。

lzxue and others added 3 commits July 15, 2026 22:24
prepare-install 复合 action 原用浮动 version: 11,最近解析到新发布的
pnpm 11.13.0,导致 pnpm install 在解析 lockfile 时崩溃:

  [ERROR] Cannot use 'in' operator to search for 'integrity' in undefined

影响所有基于当前 master 的新 PR(lint/unit-test/size-test 在 install
阶段即失败,~10s),与各 PR 的代码改动无关。

固定为 11.12.0(与 package.json 的 packageManager 字段一致)。
action-setup@v3 本身可读 packageManager,但显式 pin 更稳妥。
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant