From 87c1e440b000ba58fbc098437b9e9641f99e1bb8 Mon Sep 17 00:00:00 2001 From: lzxue <120635640@qq.com> Date: Tue, 14 Jul 2026 11:42:19 +0800 Subject: [PATCH 1/4] refactor(maps): migrate gmap & tdtmap adapters to BaseMap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将两个使用 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 交集借用 mapbase Map 的方法签名, 迁移到 BaseMap 后会暴露 on/off/getMinZoom/getContainer 等 TS2333, 需配合 @types 补全或类型放宽决策后再单独处理。 构建验证: @antv/l7-maps esm/cjs (52 文件) + umd 全部通过; tsc 无 TS2654/TS2416; eslint 通过。 --- packages/maps/src/gmap/map.ts | 59 ++++++++++++++++++++++++--------- packages/maps/src/tdtmap/map.ts | 54 +++++++++++++++++++++++++----- 2 files changed, 90 insertions(+), 23 deletions(-) diff --git a/packages/maps/src/gmap/map.ts b/packages/maps/src/gmap/map.ts index 88da9d9b68..c3ad6c0f7d 100644 --- a/packages/maps/src/gmap/map.ts +++ b/packages/maps/src/gmap/map.ts @@ -5,14 +5,16 @@ import type { IPoint, IStatusOptions, IViewport, + MapStyleConfig, Point, } from '@antv/l7-core'; import { MapServiceEvent } from '@antv/l7-core'; import { MercatorCoordinate } from '@antv/l7-map'; import { DOM } from '@antv/l7-utils'; import { mat4, vec3 } from 'gl-matrix'; +import BaseMap from '../lib/base-map'; import Viewport from '../lib/web-mercator-viewport'; -import BaseMapService from '../utils/BaseMapService'; +import { MapTheme } from '../utils/theme'; import './logo.css'; import GMapLoader from './maploader'; @@ -25,7 +27,7 @@ const EventMap: { dragging: 'drag', }; -export default class GMapService extends BaseMapService { +export default class GMapService extends BaseMap { // @ts-ignore protected viewport: IViewport = null; @@ -120,7 +122,7 @@ export default class GMapService extends BaseMapService { if (this.viewport) { this.viewport.syncWithMapCamera(option as any); this.updateCoordinateSystemService(); - this.cameraChangedCallback(this.viewport); + this.cameraChangedCallback?.(this.viewport); } } @@ -166,7 +168,7 @@ export default class GMapService extends BaseMapService { if (mapInstance) { this.map = mapInstance as any; - this.$mapContainer = this.map.getDiv(); + this.mapContainer = this.map.getDiv(); if (logoVisible === false) { this.hideLogo(); } @@ -187,7 +189,7 @@ export default class GMapService extends BaseMapService { }); this.map = map; - this.$mapContainer = map.getDiv(); + this.mapContainer = map.getDiv(); if (logoVisible === false) { this.hideLogo(); } @@ -238,7 +240,7 @@ export default class GMapService extends BaseMapService { private styleObserver: MutationObserver | null = null; public addMarkerContainer(): void { - const container = this.$mapContainer!; + const container = this.mapContainer!; this.markerContainer = DOM.create('div', 'l7-marker-container', container); this.markerContainer.setAttribute('tabindex', '-1'); this.markerContainer.style.zIndex = '2'; @@ -250,31 +252,31 @@ export default class GMapService extends BaseMapService { } public getCanvasOverlays(): HTMLElement { - return this.$mapContainer as HTMLElement; + return this.mapContainer as HTMLElement; } public getMapContainer(): HTMLElement { // 首次调用时设置 MutationObserver, // 防止 Hammer.js 在此元素上设置 touch-action: none 阻止 Google Map 原生手势 - if (!this.styleObserver && this.$mapContainer) { + if (!this.styleObserver && this.mapContainer) { this.styleObserver = new MutationObserver(() => { - if (this.$mapContainer!.style.touchAction === 'none') { - this.$mapContainer!.style.touchAction = 'auto'; + if (this.mapContainer!.style.touchAction === 'none') { + this.mapContainer!.style.touchAction = 'auto'; } - if (this.$mapContainer!.style.userSelect === 'none') { - this.$mapContainer!.style.userSelect = ''; + if (this.mapContainer!.style.userSelect === 'none') { + this.mapContainer!.style.userSelect = ''; } }); - this.styleObserver.observe(this.$mapContainer, { + this.styleObserver.observe(this.mapContainer, { attributes: true, attributeFilter: ['style'], }); } - return this.$mapContainer as HTMLElement; + return this.mapContainer as HTMLElement; } public getMapCanvasContainer(): HTMLElement { - return this.$mapContainer as HTMLElement; + return this.mapContainer as HTMLElement; } // MapEvent — Google Maps 使用 google.maps.event.addListener/removeListener @@ -360,6 +362,33 @@ export default class GMapService extends BaseMapService { } // get dom + // 以下方法原先继承自 BaseMapService(mapbox 通用实现),迁移到 BaseMap 后显式补全, + // 方法体与原继承实现保持一致,行为不变。 + 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 ''; + } + } + + public getMapStyleConfig(): MapStyleConfig { + return MapTheme; + } + + public setMaxZoom(max: number): void { + this.map.setMaxZoom(max); + } + + public setMinZoom(min: number): void { + this.map.setMinZoom(min); + } + public getContainer(): HTMLElement | null { return this.map.getDiv(); } diff --git a/packages/maps/src/tdtmap/map.ts b/packages/maps/src/tdtmap/map.ts index c9eeb8d93d..6aad1a4edb 100644 --- a/packages/maps/src/tdtmap/map.ts +++ b/packages/maps/src/tdtmap/map.ts @@ -1,4 +1,5 @@ -import BaseMapService from '../utils/BaseMapService'; +import BaseMap from '../lib/base-map'; +import { MapTheme } from '../utils/theme'; import type { Bounds, @@ -7,6 +8,8 @@ import type { IPoint, IStatusOptions, IViewport, + MapStyleConfig, + MapStyleName, Point, } from '@antv/l7-core'; import { MapServiceEvent } from '@antv/l7-core'; @@ -22,9 +25,8 @@ const EventMap: { zoomchange: ['Ge'], }; -// TODO: 基于抽象类 BaseMap 实现,补全缺失方法,解决类型问题 -export default class TdtMapService extends BaseMapService { - protected viewport: IViewport | null = null; +export default class TdtMapService extends BaseMap { + protected viewport: IViewport = new Viewport(); protected evtCbProxyMap: Map any, (...args: any) => any>> = new Map(); // @ts-ignore @@ -146,7 +148,7 @@ export default class TdtMapService extends BaseMapService { if (this.viewport) { this.viewport.syncWithMapCamera(option as any); this.updateCoordinateSystemService(); - this.cameraChangedCallback(this.viewport); + this.cameraChangedCallback?.(this.viewport); } }; @@ -172,7 +174,7 @@ export default class TdtMapService extends BaseMapService { this.map = mapInstance; // @ts-ignore this.map.centerAndZoom(new window.T.LngLat(center[0], center[1]), zoom); - this.$mapContainer = this.map.getContainer(); + this.mapContainer = this.map.getContainer(); // @ts-ignore const point = new window.T.LngLat(center[0], center[1]); @@ -184,9 +186,9 @@ export default class TdtMapService extends BaseMapService { throw Error('No container id specified'); } - this.$mapContainer = this.creatMapContainer(id as string | HTMLDivElement); + this.mapContainer = this.creatMapContainer(id as string | HTMLDivElement); // @ts-ignore - const map = new T.Map(this.$mapContainer, { + const map = new T.Map(this.mapContainer, { // @ts-ignore center: window.T.LngLat(center[0], center[1]), minZoom, @@ -503,6 +505,42 @@ export default class TdtMapService extends BaseMapService { throw new Error('Method not implemented.'); } + // 以下方法原先继承自 BaseMapService(mapbox 通用实现),迁移到 BaseMap 后显式补全, + // 方法体与原继承实现保持一致,行为不变。 + public getContainer(): HTMLElement | null { + return this.map.getContainer(); + } + + public getMinZoom(): number { + return this.map.getMinZoom(); + } + + public getMaxZoom(): number { + return this.map.getMaxZoom(); + } + + 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 ''; + } + } + + public getMapStyleConfig(): MapStyleConfig { + return MapTheme; + } + + public setMapStyle(style: MapStyleName): void { + // @ts-ignore + this.map?.setStyle(this.getMapStyleValue(style)); + } + protected creatMapContainer(id: string | HTMLDivElement) { let $wrapper = id as HTMLDivElement; if (typeof id === 'string') { From a27cc252e6476c15380b3282e29203e42a928d4a Mon Sep 17 00:00:00 2001 From: lzxue <120635640@qq.com> Date: Tue, 14 Jul 2026 14:55:45 +0800 Subject: [PATCH 2/4] fix(ci): pin pnpm to 11.12.0 to avoid 11.13.0 install regression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 更稳妥。 --- .github/actions/prepare-install/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/prepare-install/action.yml b/.github/actions/prepare-install/action.yml index 255c9ea118..bc3594b0a2 100644 --- a/.github/actions/prepare-install/action.yml +++ b/.github/actions/prepare-install/action.yml @@ -11,7 +11,7 @@ runs: steps: - uses: pnpm/action-setup@v3 with: - version: 11 + version: 11.12.0 - name: Use Node.js ${{ inputs.node-version }} uses: actions/setup-node@v4 From 9fccf7bfc51d9001607fc9e04005d45128d3416b Mon Sep 17 00:00:00 2001 From: "@thinkinggis" Date: Thu, 16 Jul 2026 12:11:27 +0800 Subject: [PATCH 3/4] Update packages/maps/src/tdtmap/map.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/maps/src/tdtmap/map.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/maps/src/tdtmap/map.ts b/packages/maps/src/tdtmap/map.ts index 6aad1a4edb..24162768ff 100644 --- a/packages/maps/src/tdtmap/map.ts +++ b/packages/maps/src/tdtmap/map.ts @@ -520,16 +520,7 @@ export default class TdtMapService extends BaseMap { } 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 ''; - } + return this.config.style ?? ''; } public getMapStyleConfig(): MapStyleConfig { @@ -537,8 +528,9 @@ export default class TdtMapService extends BaseMap { } public setMapStyle(style: MapStyleName): void { - // @ts-ignore - this.map?.setStyle(this.getMapStyleValue(style)); + if (this.map && typeof this.map.setStyle === 'function') { + this.map.setStyle(this.getMapStyleValue(style)); + } } protected creatMapContainer(id: string | HTMLDivElement) { From d16a900663612a18231e97d8d58308512233aeac Mon Sep 17 00:00:00 2001 From: "@thinkinggis" Date: Thu, 16 Jul 2026 14:29:59 +0800 Subject: [PATCH 4/4] Update packages/maps/src/gmap/map.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/maps/src/gmap/map.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/maps/src/gmap/map.ts b/packages/maps/src/gmap/map.ts index c3ad6c0f7d..f2bb287f07 100644 --- a/packages/maps/src/gmap/map.ts +++ b/packages/maps/src/gmap/map.ts @@ -28,8 +28,7 @@ const EventMap: { }; export default class GMapService extends BaseMap { - // @ts-ignore - protected viewport: IViewport = null; + protected viewport: IViewport = new Viewport(); // Google Map 和 L7 内置 Map 均使用 Web Mercator,zoom level 定义一致,无需偏移 protected zoomOffset: number = 0;