fix: map style ts Type

This commit is contained in:
thinkinggis 2020-01-11 20:22:46 +08:00
parent d17b0326fe
commit b71ddb5a72
3 changed files with 10 additions and 4 deletions

View File

@ -11,6 +11,7 @@ export interface IPoint {
y: number; y: number;
} }
export type MapStyle = string | { [key: string]: any };
export interface IMapWrapper { export interface IMapWrapper {
setContainer(container: Container, id: string): void; setContainer(container: Container, id: string): void;
} }
@ -108,7 +109,7 @@ export interface IMapConfig<RawMap = {}> {
/** /**
* *
*/ */
style?: string | { [key: string]: any }; style?: MapStyle;
/** /**
* *
*/ */

View File

@ -13,6 +13,7 @@ import {
IPoint, IPoint,
IViewport, IViewport,
MapServiceEvent, MapServiceEvent,
MapStyle,
TYPES, TYPES,
} from '@antv/l7-core'; } from '@antv/l7-core';
import { DOM } from '@antv/l7-utils'; import { DOM } from '@antv/l7-utils';
@ -249,7 +250,7 @@ export default class AMapService
); );
// @ts-ignore // @ts-ignore
this.map = new AMap.Map(this.$mapContainer, { this.map = new AMap.Map(this.$mapContainer, {
mapStyle: this.getMapStyle(style), mapStyle: this.getMapStyle(style as string),
zooms: [minZoom, maxZoom], zooms: [minZoom, maxZoom],
viewMode: '3D', viewMode: '3D',
...rest, ...rest,
@ -361,7 +362,7 @@ export default class AMapService
} }
}; };
private getMapStyle(name: string) { private getMapStyle(name: string): string {
return MapTheme[name] ? MapTheme[name] : name; return MapTheme[name] ? MapTheme[name] : name;
} }
private creatAmapContainer(id: string | HTMLDivElement) { private creatAmapContainer(id: string | HTMLDivElement) {

View File

@ -13,6 +13,7 @@ import {
IPoint, IPoint,
IViewport, IViewport,
MapServiceEvent, MapServiceEvent,
MapStyle,
TYPES, TYPES,
} from '@antv/l7-core'; } from '@antv/l7-core';
import { DOM } from '@antv/l7-utils'; 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; return MapTheme[name] ? MapTheme[name] : name;
} }
} }