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 diff --git a/packages/maps/src/gmap/map.ts b/packages/maps/src/gmap/map.ts index 88da9d9b68..f2bb287f07 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,9 +27,8 @@ const EventMap: { dragging: 'drag', }; -export default class GMapService extends BaseMapService { - // @ts-ignore - protected viewport: IViewport = null; +export default class GMapService extends BaseMap { + protected viewport: IViewport = new Viewport(); // Google Map 和 L7 内置 Map 均使用 Web Mercator,zoom level 定义一致,无需偏移 protected zoomOffset: number = 0; @@ -120,7 +121,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 +167,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 +188,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 +239,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 +251,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 +361,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..24162768ff 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,34 @@ 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 { + return this.config.style ?? ''; + } + + public getMapStyleConfig(): MapStyleConfig { + return MapTheme; + } + + public setMapStyle(style: MapStyleName): void { + if (this.map && typeof this.map.setStyle === 'function') { + this.map.setStyle(this.getMapStyleValue(style)); + } + } + protected creatMapContainer(id: string | HTMLDivElement) { let $wrapper = id as HTMLDivElement; if (typeof id === 'string') {