[mapbox-gl] add Visibility, Layout & AnyLayout types to facilitate further type-safety (#39264)

This commit is contained in:
Dmytro Gokun 2019-10-22 23:15:13 +03:00 committed by Wesley Wigham
parent c8463c47e0
commit 4ebcc8fea9
2 changed files with 33 additions and 23 deletions

View File

@ -251,11 +251,11 @@ declare namespace mapboxgl {
export interface MapboxOptions {
/**
* If true, the gl context will be created with MSA antialiasing, which can be useful for antialiasing custom layers.
* If true, the gl context will be created with MSA antialiasing, which can be useful for antialiasing custom layers.
* This is false by default as a performance optimization.
*/
antialias?: boolean;
/** If true, an attribution control will be added to the map. */
attributionControl?: boolean;
@ -1369,6 +1369,8 @@ declare namespace mapboxgl {
touchcancel: MapLayerTouchEvent;
}
export type AnyLayout = BackgroundLayout | FillLayout | FillExtrusionLayout | LineLayout | SymbolLayout | RasterLayout | CircleLayout | HeatmapLayout | HillshadeLayout;
export interface Layer {
id: string;
type?: 'fill' | 'line' | 'symbol' | 'circle' | 'fill-extrusion' | 'raster' | 'background' | 'heatmap' | 'hillshade';
@ -1386,7 +1388,7 @@ declare namespace mapboxgl {
interactive?: boolean;
filter?: any[];
layout?: BackgroundLayout | FillLayout | FillExtrusionLayout | LineLayout | SymbolLayout | RasterLayout | CircleLayout | HeatmapLayout | HillshadeLayout;
layout?: AnyLayout;
paint?: BackgroundPaint | FillPaint | FillExtrusionPaint | LinePaint | SymbolPaint | RasterPaint | CirclePaint | HeatmapPaint | HillshadePaint;
}
@ -1470,8 +1472,13 @@ declare namespace mapboxgl {
'colorSpace'?: 'rgb' | 'lab' | 'hcl';
}
export interface BackgroundLayout {
visibility?: 'visible' | 'none';
type Visibility = 'visible' | 'none';
export interface Layout {
visibility?: Visibility;
}
export interface BackgroundLayout extends Layout {
}
export interface BackgroundPaint {
@ -1483,8 +1490,7 @@ declare namespace mapboxgl {
'background-opacity-transition'?: Transition;
}
export interface FillLayout {
visibility?: 'visible' | 'none';
export interface FillLayout extends Layout {
}
export interface FillPaint {
@ -1502,8 +1508,7 @@ declare namespace mapboxgl {
'fill-pattern-transition'?: Transition;
}
export interface FillExtrusionLayout {
visibility?: 'visible' | 'none';
export interface FillExtrusionLayout extends Layout {
}
export interface FillExtrusionPaint {
@ -1523,9 +1528,7 @@ declare namespace mapboxgl {
'fill-extrusion-vertical-gradient'?: boolean;
}
export interface LineLayout {
visibility?: 'visible' | 'none';
export interface LineLayout extends Layout {
'line-cap'?: 'butt' | 'round' | 'square';
'line-join'?: 'bevel' | 'round' | 'miter' | Expression;
'line-miter-limit'?: number | Expression;
@ -1555,9 +1558,7 @@ declare namespace mapboxgl {
'line-gradient'?: Expression;
}
export interface SymbolLayout {
visibility?: 'visible' | 'none';
export interface SymbolLayout extends Layout {
'symbol-placement'?: 'point' | 'line' | 'line-center';
'symbol-spacing'?: number | Expression;
'symbol-avoid-edges'?: boolean;
@ -1626,8 +1627,7 @@ declare namespace mapboxgl {
'text-translate-anchor'?: 'map' | 'viewport';
}
export interface RasterLayout {
visibility?: 'visible' | 'none';
export interface RasterLayout extends Layout {
}
export interface RasterPaint {
@ -1647,8 +1647,7 @@ declare namespace mapboxgl {
'raster-resample'?: 'linear' | 'nearest';
}
export interface CircleLayout {
visibility?: 'visible' | 'none';
export interface CircleLayout extends Layout {
}
export interface CirclePaint {
@ -1673,8 +1672,7 @@ declare namespace mapboxgl {
'circle-stroke-opacity-transition'?: Transition;
}
export interface HeatmapLayout {
visibility?: 'visible' | 'none';
export interface HeatmapLayout extends Layout {
}
export interface HeatmapPaint {
@ -1688,8 +1686,7 @@ declare namespace mapboxgl {
'heatmap-opacity-transition'?: Transition;
}
export interface HillshadeLayout {
visibility?: 'visible' | 'none';
export interface HillshadeLayout extends Layout {
}
export interface HillshadePaint {

View File

@ -1008,3 +1008,16 @@ expectType<mapboxgl.Expression>(['coalesce', ['get', 'property'], ['get', 'prope
*/
expectType<void>(new mapboxgl.Map().scrollZoom.setZoomRate(1));
expectType<void>(new mapboxgl.Map().scrollZoom.setWheelZoomRate(1));
/*
* Visibility
*/
expectType<mapboxgl.Visibility>('visible');
expectType<mapboxgl.Visibility>('none');
/*
* AnyLayout
*/
expectType<mapboxgl.AnyLayout>({visibility: 'none'});
expectType<mapboxgl.AnyLayout>({visibility: 'none', 'line-cap': 'round' });
expectType<mapboxgl.AnyLayout>({visibility: 'visible', 'icon-allow-overlap': true });