refactor(maps): migrate mapbox family (map/mapbox/maplibre/earth) to MapboxBaseMap - #2877
Conversation
|
There was a problem hiding this comment.
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.
…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 阻塞)
739f52a to
963e937
Compare
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 相关零错误。
背景
前期将非 Mapbox 适配器(
amap-next/gmap/tdtmap,见 #2875)从废弃的BaseMapService迁移到BaseMap。本 PR 推进 Mapbox 家族四个适配器(map/mapbox/maplibre/earth)的同类迁移,作为后续删除BaseMapService的中间铺路步骤。改动
新增
四个适配器迁移
机械清理
类型契约诚实化
不再依赖 `BaseMapService implements IMapService<Map & T>` 的 \"`Map & T` 万能交集\"——该交集本是为了掩盖 `bmap`/`tmap` 适配不完整。Mapbox 家族类型完整(`@types/mapbox-gl`/`@types/maplibre-gl` 齐全),迁移零类型风险。
铺路性质
本次完成后 `BaseMapService` 仍保留——`bmap`/`tmap` 仍依赖它(`@types` 不完整,迁移会暴露 TS2333,待后续决策)。这是后续完全删除 `BaseMapService` 的中间一步。
验证
不在本 PR 范围