mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #32530 from macobo/improve-mapgl-types
[@types/mapbox-gl] Improve Expression, Source types
This commit is contained in:
Vendored
+56
-14
@@ -1,8 +1,10 @@
|
||||
// Type definitions for Mapbox GL JS v0.51.0
|
||||
// Project: https://github.com/mapbox/mapbox-gl-js
|
||||
// Definitions by: Dominik Bruderer <https://github.com/dobrud>, Patrick Reames <https://github.com/patrickr>
|
||||
// Definitions by: Dominik Bruderer <https://github.com/dobrud>
|
||||
// Patrick Reames <https://github.com/patrickr>
|
||||
// Karl-Aksel Puulmann <https://github.com/macobo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
/// <reference types="geojson" />
|
||||
|
||||
@@ -20,7 +22,33 @@ declare namespace mapboxgl {
|
||||
type LngLatLike = LngLat | { lng: number; lat: number; } | { lon: number; lat: number; } | [number, number];
|
||||
type LngLatBoundsLike = LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number];
|
||||
type PointLike = Point | [number, number];
|
||||
type Expression = any[];
|
||||
|
||||
type ExpressionName =
|
||||
// Types
|
||||
| 'array' | 'boolean' | 'collator' | 'format' | 'literal' | 'number' | 'object' | 'string'
|
||||
| 'to-boolean' | 'to-color' | 'to-number' | 'to-string' | 'typeof'
|
||||
// Feature data
|
||||
| 'feature-state' | 'geometry-type' | 'id' | 'line-progress' | 'properties'
|
||||
// Lookup
|
||||
| 'at' | 'get' | 'has' | 'length'
|
||||
// Decision
|
||||
| '!=' | '<' | '<=' | '==' | '>' | '>=' | 'all' | 'any' | 'case' | 'match'
|
||||
// Ramps, scales, curves
|
||||
| 'interpolate' | 'interpolate-hcl' | 'interpolate-lab' | 'step'
|
||||
// Variable binding
|
||||
| 'let' | 'var'
|
||||
// String
|
||||
| 'concat' | 'downcase' | 'is-supported-script' | 'resolved-locale' | 'upcase'
|
||||
// Color
|
||||
| 'rgb' | 'rgba'
|
||||
// Math
|
||||
| '-' | '*' | '/' | '%' | '^' | '+' | 'abs' | 'acos' | 'asin' | 'atan' | 'ceil' | 'cos' | 'e'
|
||||
| 'floor' | 'ln' | 'ln2' | 'log10' | 'log2' | 'max' | 'min' | 'pi' | 'round' | 'sin' | 'sqrt' | 'tan'
|
||||
// Zoom, Heatmap
|
||||
| 'zoom' | 'heatmap-density';
|
||||
|
||||
type Expression = [ExpressionName, ...any[]]
|
||||
|
||||
type Anchor = 'center' | 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
||||
|
||||
/**
|
||||
@@ -73,7 +101,7 @@ declare namespace mapboxgl {
|
||||
|
||||
isStyleLoaded(): boolean;
|
||||
|
||||
addSource(id: string, source: VectorSource | RasterSource | RasterDemSource | GeoJSONSource | ImageSource | VideoSource | GeoJSONSourceRaw): this;
|
||||
addSource(id: string, source: AnySourceData): this;
|
||||
|
||||
isSourceLoaded(id: string): boolean;
|
||||
|
||||
@@ -81,7 +109,7 @@ declare namespace mapboxgl {
|
||||
|
||||
removeSource(id: string): this;
|
||||
|
||||
getSource(id: string): VectorSource | RasterSource | RasterDemSource | GeoJSONSource | ImageSource | VideoSource;
|
||||
getSource(id: string): AnySourceImpl;
|
||||
|
||||
addImage(name: string, image: HTMLImageElement | ArrayBufferView | { width: number, height: number, data: Uint8Array | Uint8ClampedArray } | ImageData, options?: { pixelRatio?: number, sdf?: boolean }): this;
|
||||
|
||||
@@ -626,7 +654,7 @@ declare namespace mapboxgl {
|
||||
name?: string;
|
||||
pitch?: number;
|
||||
light?: Light;
|
||||
sources?: any;
|
||||
sources?: Sources;
|
||||
sprite?: string;
|
||||
transition?: Transition;
|
||||
version: number;
|
||||
@@ -648,6 +676,14 @@ declare namespace mapboxgl {
|
||||
'intensity-transition'?: Transition;
|
||||
}
|
||||
|
||||
export interface Sources {
|
||||
[sourceName: string]: AnySourceData;
|
||||
}
|
||||
|
||||
export type AnySourceData = GeoJSONSourceRaw | VideoSourceRaw | ImageSourceRaw | CanvasSourceRaw | VectorSource | RasterSource | RasterDemSource
|
||||
|
||||
export type AnySourceImpl = GeoJSONSource | VideoSource | ImageSource | CanvasSource | VectorSource | RasterSource | RasterDemSource
|
||||
|
||||
export interface Source {
|
||||
type: 'vector' | 'raster' | 'raster-dem' | 'geojson' | 'image' | 'video' | 'canvas';
|
||||
}
|
||||
@@ -699,10 +735,11 @@ declare namespace mapboxgl {
|
||||
/**
|
||||
* VideoSource
|
||||
*/
|
||||
export interface VideoSource extends VideoSourceOptions {
|
||||
export interface VideoSourceRaw extends Source, VideoSourceOptions {
|
||||
type: 'video';
|
||||
}
|
||||
|
||||
export class VideoSource implements Source {
|
||||
export class VideoSource implements VideoSourceRaw {
|
||||
type: 'video';
|
||||
|
||||
constructor(options?: mapboxgl.VideoSourceOptions);
|
||||
@@ -721,10 +758,11 @@ declare namespace mapboxgl {
|
||||
/**
|
||||
* ImageSource
|
||||
*/
|
||||
export interface ImageSource extends ImageSourceOptions {
|
||||
export interface ImageSourceRaw extends Source, ImageSourceOptions {
|
||||
type: 'image';
|
||||
}
|
||||
|
||||
export class ImageSource implements Source {
|
||||
export class ImageSource implements ImageSourceRaw {
|
||||
type: 'image';
|
||||
|
||||
constructor(options?: mapboxgl.ImageSourceOptions);
|
||||
@@ -741,7 +779,11 @@ declare namespace mapboxgl {
|
||||
/**
|
||||
* CanvasSource
|
||||
*/
|
||||
export class CanvasSource implements Source, CanvasSourceOptions {
|
||||
export interface CanvasSourceRaw extends Source, CanvasSourceOptions {
|
||||
type: 'canvas';
|
||||
}
|
||||
|
||||
export class CanvasSource implements CanvasSourceRaw {
|
||||
type: 'canvas';
|
||||
|
||||
coordinates: number[][];
|
||||
@@ -1246,7 +1288,7 @@ declare namespace mapboxgl {
|
||||
metadata?: any;
|
||||
ref?: string;
|
||||
|
||||
source?: string | VectorSource | RasterSource | RasterDemSource | GeoJSONSource | ImageSource | VideoSource | GeoJSONSourceRaw;
|
||||
source?: string | AnySourceData;
|
||||
|
||||
'source-layer'?: string;
|
||||
|
||||
@@ -1361,7 +1403,7 @@ declare namespace mapboxgl {
|
||||
'symbol-spacing'?: number | Expression;
|
||||
'symbol-avoid-edges'?: boolean;
|
||||
'symbol-z-order'?: 'viewport-y' | 'source';
|
||||
'icon-allow-overlap'?: boolean | StyleFunction;
|
||||
'icon-allow-overlap'?: boolean | StyleFunction | Expression;
|
||||
'icon-ignore-placement'?: boolean;
|
||||
'icon-optional'?: boolean;
|
||||
'icon-rotation-alignment'?: 'map' | 'viewport' | 'auto';
|
||||
@@ -1377,7 +1419,7 @@ declare namespace mapboxgl {
|
||||
'icon-pitch-alignment'?: 'map' | 'viewport' | 'auto';
|
||||
'text-pitch-alignment'?: 'map' | 'viewport' | 'auto';
|
||||
'text-rotation-alignment'?: 'map' | 'viewport' | 'auto';
|
||||
'text-field'?: string | StyleFunction;
|
||||
'text-field'?: string | StyleFunction | Expression;
|
||||
'text-font'?: string | string[];
|
||||
'text-size'?: number | StyleFunction | Expression;
|
||||
'text-max-width'?: number | Expression;
|
||||
|
||||
@@ -50,7 +50,8 @@ map.on('load', function(){
|
||||
"type": "symbol",
|
||||
"source": "data",
|
||||
"layout": {
|
||||
"icon-image": "marker-15"
|
||||
"icon-image": "marker-15",
|
||||
"text-field": ['get', 'property']
|
||||
}
|
||||
});
|
||||
|
||||
@@ -788,3 +789,14 @@ expectType<mapboxgl.Map>(map.on('touchcancel', 'text', (ev) => {
|
||||
expectType<mapboxgl.MapLayerTouchEvent>(ev);
|
||||
expectType<mapboxgl.MapboxGeoJSONFeature[] | undefined>(ev.features);
|
||||
}));
|
||||
|
||||
/*
|
||||
* Expression
|
||||
*/
|
||||
expectType<mapboxgl.Expression>(['id']);
|
||||
expectType<mapboxgl.Expression>(['get', 'property']);
|
||||
expectType<mapboxgl.Expression>([
|
||||
'format',
|
||||
['concat', ['get', 'name'], '\n'], {},
|
||||
['concat', ['get', 'area'], 'foobar', { 'font-scale': 0.8 }]
|
||||
]);
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@
|
||||
// Definitions by: Robert Imig <https://github.com/rimig>
|
||||
// Fabio Berta <https://github.com/fnberta>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
import * as React from 'react';
|
||||
import * as MapboxGL from 'mapbox-gl';
|
||||
|
||||
Reference in New Issue
Block a user