fix: map style ts Type

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

View File

@ -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<RawMap = {}> {
/**
*
*/
style?: string | { [key: string]: any };
style?: MapStyle;
/**
*
*/

View File

@ -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) {

View File

@ -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;
}
}