diff --git a/packages/core/src/services/map/IMapService.ts b/packages/core/src/services/map/IMapService.ts index c4af094802..0fed5893e8 100644 --- a/packages/core/src/services/map/IMapService.ts +++ b/packages/core/src/services/map/IMapService.ts @@ -11,6 +11,7 @@ export interface IPoint { y: number; } +export type MapStyle = string | { [key: string]: any }; export interface IMapWrapper { setContainer(container: Container, id: string): void; } @@ -108,7 +109,7 @@ export interface IMapConfig { /** * 底图样式 */ - style?: string | { [key: string]: any }; + style?: MapStyle; /** * 最小缩放等级 */ diff --git a/packages/maps/src/amap/index.ts b/packages/maps/src/amap/index.ts index cf9f00e974..3143322762 100644 --- a/packages/maps/src/amap/index.ts +++ b/packages/maps/src/amap/index.ts @@ -13,6 +13,7 @@ import { IPoint, IViewport, MapServiceEvent, + MapStyle, TYPES, } from '@antv/l7-core'; import { DOM } from '@antv/l7-utils'; @@ -249,7 +250,7 @@ export default class AMapService ); // @ts-ignore this.map = new AMap.Map(this.$mapContainer, { - mapStyle: this.getMapStyle(style), + mapStyle: this.getMapStyle(style as string), zooms: [minZoom, maxZoom], viewMode: '3D', ...rest, @@ -361,7 +362,7 @@ export default class AMapService } }; - private getMapStyle(name: string) { + private getMapStyle(name: string): string { return MapTheme[name] ? MapTheme[name] : name; } private creatAmapContainer(id: string | HTMLDivElement) { diff --git a/packages/maps/src/mapbox/index.ts b/packages/maps/src/mapbox/index.ts index 95786ec2f7..b8659c1716 100644 --- a/packages/maps/src/mapbox/index.ts +++ b/packages/maps/src/mapbox/index.ts @@ -13,6 +13,7 @@ import { IPoint, IViewport, MapServiceEvent, + MapStyle, TYPES, } from '@antv/l7-core'; import { DOM } from '@antv/l7-utils'; @@ -318,7 +319,10 @@ export default class MapboxService } } - private getMapStyle(name: string) { + private getMapStyle(name: MapStyle) { + if (typeof name !== 'string') { + return name; + } return MapTheme[name] ? MapTheme[name] : name; } }