import type { Bounds, ICoordinateSystemService, IGlobalConfigService, ILngLat, IMapCamera, IMapConfig, IMapService, IMercator, IPoint, IStatusOptions, IViewport, L7Container, MapStyleConfig, MapStyleName } from '@antv/l7-core'; import type { EventEmitterStatic } from 'eventemitter3'; import { SimpleMapCoord } from '../utils/simpleMapCoord'; export default abstract class BaseMap implements IMapService { /** * 地图实例 */ map: T; /** * @deprecated * TODO: 基类型不需要实现,只是自定义 Map 使用非地理坐标系才会用到 */ simpleMapCoord: SimpleMapCoord; /** * 背景色 */ bgColor: string; protected abstract viewport: IViewport; protected readonly config: Partial>; protected readonly configService: IGlobalConfigService; protected readonly coordinateSystemService: ICoordinateSystemService; protected eventEmitter: InstanceType; protected markerContainer: HTMLElement; protected mapContainer: HTMLElement | null; protected cameraChangedCallback?: (viewport: IViewport) => void; /** * 在地图实例初始化之前缓存的事件处理器,init 完成后自动重放绑定 */ protected pendingHandlers: Array<{ type: string; handler: (...args: any[]) => void; }>; constructor(container: L7Container); abstract init(): Promise; onCameraChanged(callback: (viewport: IViewport) => void): void; protected abstract handleCameraChanged: () => void; updateView(viewOption: Partial): void; protected updateCoordinateSystemService(): void; protected creatMapContainer(id: string | HTMLDivElement): HTMLDivElement; abstract getMapStyle(): string; abstract getMapStyleConfig(): MapStyleConfig; getMapStyleValue(name: MapStyleName): any; abstract getType(): string; setBgColor(color: string): void; abstract getContainer(): HTMLElement | null; getMapContainer(): HTMLElement | null; abstract getMapCanvasContainer(): HTMLElement; abstract addMarkerContainer(): void; getMarkerContainer(): HTMLElement; getOverlayContainer(): HTMLElement | undefined; getCanvasOverlays(): HTMLElement | null | undefined; abstract on(type: string, handle: (...args: any[]) => void): void; abstract off(type: string, handle: (...args: any[]) => void): void; /** * 地图实例初始化完成后,重放缓存的事件绑定 * 子类在 init() 末尾应调用此方法 */ protected bindPendingEvents(): void; emit(name: string, ...args: any[]): void; once(name: string, handler: (...args: any[]) => void): void; abstract getSize(): [number, number]; abstract getZoom(): number; abstract setZoom(zoom: number): void; abstract getCenter(): ILngLat; abstract setCenter(lnglat: [number, number]): void; abstract getPitch(): number; abstract getRotation(): number; abstract getBounds(): Bounds; abstract getMinZoom(): number; abstract getMaxZoom(): number; abstract setRotation(rotation: number): void; abstract zoomIn(option?: any, eventData?: any): void; abstract zoomOut(option?: any, eventData?: any): void; abstract setPitch(pitch: number): void; abstract panTo(p: [number, number]): void; abstract panBy(x: number, y: number): void; abstract fitBounds(bound: Bounds, fitBoundsOptions?: any): void; abstract setMaxZoom(max: number): void; abstract setMinZoom(min: number): void; abstract setMapStatus(option: Partial): void; abstract setZoomAndCenter(zoom: number, center: [number, number]): void; abstract setMapStyle(name: MapStyleName): void; meterToCoord(center: [number, number], outer: [number, number]): number; abstract pixelToLngLat(pixel: [number, number]): ILngLat; abstract lngLatToPixel(lnglat: [number, number]): IPoint; abstract containerToLngLat(pixel: [number, number]): ILngLat; abstract lngLatToContainer(lnglat: [number, number]): IPoint; abstract lngLatToMercator(lnglat: [number, number], altitude: number): IMercator; abstract getModelMatrix(lnglat: [number, number], altitude: number, rotate: [number, number, number], scale: [number, number, number], origin: IMercator): number[]; abstract exportMap(type: 'jpg' | 'png'): string; destroy(): void; }