Skip to content

refactor(maps): migrate mapbox family (map/mapbox/maplibre/earth) to MapboxBaseMap - #2877

Merged
lzxue merged 7 commits into
masterfrom
refactor/mapbox-basemap-migration
Jul 18, 2026
Merged

refactor(maps): migrate mapbox family (map/mapbox/maplibre/earth) to MapboxBaseMap#2877
lzxue merged 7 commits into
masterfrom
refactor/mapbox-basemap-migration

Conversation

@lzxue

@lzxue lzxue commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

背景

前期将非 Mapbox 适配器(amap-next / gmap / tdtmap,见 #2875)从废弃的 BaseMapService 迁移到 BaseMap。本 PR 推进 Mapbox 家族四个适配器(map / mapbox / maplibre / earth)的同类迁移,作为后续删除 BaseMapService 的中间铺路步骤。

改动

新增

  • `packages/maps/src/lib/mapbox-base-map.ts`(~350 行):抽出的 `MapboxBaseMap extends BaseMap<Map & T> implements IMapService<Map & T>` 中间基类,承载原先分散在 `BaseMapService` 中的 ~30 个 Mapbox 专用具体实现:
    • 事件代理:`on` / `off`(保留 handler→proxy 映射用于精确解绑)
    • 相机 getters/setters:`getZoom`/`setZoom`/`getCenter` 等
    • `setMapStatus`、坐标转换、容器 getters、`getMapStyle`、默认 `handleCameraChanged`(earth 自行覆盖)

四个适配器迁移

适配器 改动
`map/map.ts` `extends BaseMapService` → `extends MapboxBaseMap`
`mapbox/map.ts` `extends BaseMapService<Map & IMapboxInstance>` → `extends MapboxBaseMap<Map & IMapboxInstance>`
`maplibre/map.ts` 同上
`earth/map.ts` `extends BaseMapService` → `extends MapboxBaseMap`(保留 `implements IEarthService`)

机械清理

  • 适配器内 `$mapContainer` → `mapContainer`(统一基类命名)
  • 删除三个适配器内冗余重写 `emit`/`once`/`getMapContainer`(基类已提供正确实现;子类的 `once(name, ...args)` 签名是 bug,正确应是 `once(name, handler)`,顺手清掉)
  • 删除 `earth/map.ts` 冗余 `onCameraChanged`
  • `earth/map.ts` 的 `cameraChangedCallback(this.viewport)` 改 optional chaining(基类该属性是可选的)

类型契约诚实化

不再依赖 `BaseMapService implements IMapService<Map & T>` 的 \"`Map & T` 万能交集\"——该交集本是为了掩盖 `bmap`/`tmap` 适配不完整。Mapbox 家族类型完整(`@types/mapbox-gl`/`@types/maplibre-gl` 齐全),迁移零类型风险。

铺路性质

本次完成后 `BaseMapService` 仍保留——`bmap`/`tmap` 仍依赖它(`@types` 不完整,迁移会暴露 TS2333,待后续决策)。这是后续完全删除 `BaseMapService` 的中间一步。

验证

  • ✅ `tsc --noEmit -p packages/maps/tsconfig.json`:`packages/maps/src` 路径 0 错误(与 master 基线一致;master 基线 199 错误均为 pre-existing 的 `.glsl` 类型声明缺失与 `packages/map/` 单数目录问题)
  • 🔄 CI 远端:lint / unit / size(pre-commit lint-staged 在本机因 pnpm install 注册中心供应链策略 451 错误未跑完)

不在本 PR 范围

  • `bmap`/`tmap` 迁移(等 `@types`/类型放宽决策)
  • 删除 `BaseMapService.ts`(前置条件全部满足后另起一个 PR)

@changeset-bot

changeset-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1d6a87b

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 introduces a new shared base class, MapboxBaseMap, to consolidate common Mapbox API implementations and reduce duplication across several map services, which now inherit from this new base class. The review feedback identifies a copy-paste bug in setMapStatus where dragEnable is checked instead of rotateEnable, redundant type assertions and casts, potential type unsafety in exportMap when renderCanvas is undefined, and opportunities to further reduce code duplication by delegating cleanup logic to super.destroy().

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/lib/mapbox-base-map.ts Outdated
Comment thread packages/maps/src/lib/mapbox-base-map.ts Outdated
Comment thread packages/maps/src/lib/mapbox-base-map.ts
Comment thread packages/maps/src/lib/mapbox-base-map.ts
Comment thread packages/maps/src/lib/mapbox-base-map.ts
Comment thread packages/maps/src/earth/map.ts
Comment thread packages/maps/src/mapbox/map.ts
Comment thread packages/maps/src/maplibre/map.ts
…MapboxBaseMap

抽取 MapboxBaseMap 中间基类 (lib/mapbox-base-map.ts, ~350 行),
承载原先分散在 BaseMapService 里的 ~30 个 mapbox 专用具体实现
(on/off 事件代理、getZoom/setZoom/getCenter/fitBounds/setMapStatus/
getMapStyle 等), 让四个 mapbox 家族适配器统一走:
    BaseMap -> MapboxBaseMap -> 具体适配器

四个适配器迁移:
- map/map.ts:     extends BaseMapService<Map> -> extends MapboxBaseMap<Map>
- mapbox/map.ts:  extends BaseMapService<Map & IMapboxInstance> -> extends MapboxBaseMap<Map & IMapboxInstance>
- maplibre/map.ts:extends BaseMapService<Map & IMapboxInstance> -> extends MapboxBaseMap<Map & IMapboxInstance>
- earth/map.ts:   extends BaseMapService<Map> (implements IEarthService) -> extends MapboxBaseMap<Map>

机械清理:
- 适配器内 $mapContainer -> mapContainer (统一基类命名)
- 删除适配器内冗余重写 emit/once/getMapContainer/onCameraChanged
  (基类已提供正确实现, 且子类 once 签名是错的 spread bug, 顺手清掉)
- earth/map.ts 的 cameraChangedCallback 调用改为 optional chaining
  (基类 BaseMap.cameraChangedCallback 是可选属性)

类型契约诚实化:
- 不再依赖 BaseMapService<T> implements IMapService<Map & T> 的
  'Map & T 万能交集' 掩盖 bmap/tmap 的适配不完整
- mapbox 家族类型完整 (@types/mapbox-gl/@types/maplibre-gl 齐全), 迁移零风险

铺路: 本次完成后 BaseMapService 仍保留 (bmap/tmap 仍依赖),
作为后续删除 BaseMapService 的中间一步。

验证:
- tsc --noEmit -p packages/maps/tsconfig.json: packages/maps/src 路径 0 错误 (与 master 基线一致)
- pre-commit lint-staged 与 CI 远端跑 lint / unit / size (本地 pnpm install 被 registry 阻塞)
@lzxue
lzxue force-pushed the refactor/mapbox-basemap-migration branch from 739f52a to 963e937 Compare July 18, 2026 09:05
lzxue and others added 6 commits July 18, 2026 20:07
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>
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>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- 移除未使用的 IViewport import (organize-imports, 网页编辑去掉
  (this.viewport as IViewport) cast 后 IViewport 已无引用)
- 合并 exportImage 三元表达式为单行 (去掉 'as string' cast 后
  行宽 < 100, prettier 要求单行)

tsc 复核 packages/maps: 仅 4 个本地 @types 缺失的全局错误,
mapbox-base-map 相关零错误。
@lzxue
lzxue merged commit 8f2d6d7 into master Jul 18, 2026
5 checks passed
@lzxue
lzxue deleted the refactor/mapbox-basemap-migration branch July 18, 2026 15:23
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