From 71b643e240d0de8aa7bababf917a5d7cd105b9e9 Mon Sep 17 00:00:00 2001 From: Liam Clarke Date: Mon, 29 Jul 2019 16:58:40 -0400 Subject: [PATCH] Update mapbox-gl to v0.53.0 (#37145) * Update mapbox-gl to v0.53.0 * Added tests * Fixed removeFeatureState argument type * Added missing semicolons * Added extra test case, clean up * Removed import added by editor which broke tests --- types/mapbox-gl/index.d.ts | 22 ++++++++-- types/mapbox-gl/mapbox-gl-tests.ts | 65 +++++++++++++++++++++++++----- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index 8473b5a263..26b37616f7 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -1,9 +1,10 @@ -// Type definitions for Mapbox GL JS v0.51.0 +// Type definitions for Mapbox GL JS v0.53.0 // Project: https://github.com/mapbox/mapbox-gl-js // Definitions by: Dominik Bruderer // Patrick Reames // Karl-Aksel Puulmann // Dmytro Gokun +// Liam Clarke // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -15,6 +16,7 @@ export as namespace mapboxgl; declare namespace mapboxgl { let accessToken: string; let version: string; + let baseApiUrl: string; export function supported(options?: { failIfMajorPerformanceCaveat?: boolean }): boolean; @@ -148,9 +150,11 @@ declare namespace mapboxgl { getLight(): mapboxgl.Light; - setFeatureState(feature: { source: string, sourceLayer?: string, id: string | number } | mapboxgl.MapboxGeoJSONFeature, state: { [key: string]: any }): void; + setFeatureState(feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, state: { [key: string]: any }): void; - getFeatureState(feature: { source: string, sourceLayer?: string, id: string | number } | mapboxgl.MapboxGeoJSONFeature): { [key: string]: any }; + getFeatureState(feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature): { [key: string]: any }; + + removeFeatureState(target: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, key?: string): void; getContainer(): HTMLElement; @@ -254,6 +258,9 @@ declare namespace mapboxgl { /** Snap to north threshold in degrees. */ bearingSnap?: number; + /** The initial bounds of the map. If bounds is specified, it overrides center and zoom constructor options. */ + bounds?: LngLatBoundsLike; + /** If true, enable the "box zoom" interaction (see BoxZoomHandler) */ boxZoom?: boolean; @@ -317,6 +324,9 @@ declare namespace mapboxgl { /** If true, map creation will fail if the implementation determines that the performance of the created WebGL context would be dramatically lower than expected. */ failIfMajorPerformanceCaveat?: boolean; + /** A fitBounds options object to use only when setting the bounds option. */ + fitBoundsOptions?: FitBoundsOptions; + /** If false, no mouse, touch, or keyboard listeners are attached to the map, so it will not respond to input */ interactive?: boolean; @@ -454,6 +464,12 @@ declare namespace mapboxgl { right: number; } + export interface FeatureIdentifier { + id?: string | number, + source: string + sourceLayer?: string + } + /** * BoxZoomHandler */ diff --git a/types/mapbox-gl/mapbox-gl-tests.ts b/types/mapbox-gl/mapbox-gl-tests.ts index a4de99236b..2db8e2855f 100644 --- a/types/mapbox-gl/mapbox-gl-tests.ts +++ b/types/mapbox-gl/mapbox-gl-tests.ts @@ -7,6 +7,10 @@ import mapboxgl = require('.'); */ mapboxgl.accessToken = 'foo'; +/** + * Set Base API URL + */ +mapboxgl.baseApiUrl = 'https://example.com'; /** * Display a Map @@ -29,11 +33,36 @@ let map = new mapboxgl.Map({ dragPan: true, }); +/** + * Initialize map with bounds + */ +expectType({ + container: 'map', + bounds: new mapboxgl.LngLatBounds([-100, -90, 100, 90]), + fitBoundsOptions: { + padding: 0, + offset: new mapboxgl.Point(0, 0), + linear: true, + maxZoom: 22, + easing: time => time + } +}); +expectType({ + container: 'map', + bounds: [[-100, -90], [100, 90]], + fitBoundsOptions: { + offset: [0, 0] + } +}); +expectType({ + container: 'map', + bounds: [-100, -90, 100, 90] +}); /** * Create and style marker clusters */ -map.on('load', function(){ +map.on('load', function() { // Add a new source from our GeoJSON data and set the // 'cluster' option to true. @@ -55,7 +84,7 @@ map.on('load', function(){ } }); - var layers: [number, string][] = [ + var layers: [number, string][] = [ [150, '#f28cb1'], [20, '#f1f075'], [0, '#51bbd6'] @@ -93,9 +122,9 @@ map.on('load', function(){ } }); -/** - * Add a GeoJSON line - */ + /** + * Add a GeoJSON line + */ map.addSource("route", { "type": "geojson", "data": { @@ -234,14 +263,28 @@ map.addSource('radar', { type: 'raster', tiles: ['https://nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WmsServer?bbox={bbox-epsg-3857}&service=WMS&request=GetMap&version=1.3.0&layers=1&styles=&format=image/png&transparent=true&height=256&width=256&crs=EPSG:3857'], tileSize: 256 -}) +}); map.addLayer({ id: 'radar', type: 'raster', source: 'radar', paint: {} -}) +}); + +/** + * Manipulate feature state + */ +let featureIdentifier = { + id: 1337, + source: 'source-id', + sourceLayer: 'liam-was-here' +}; +expectType(featureIdentifier); +map.setFeatureState(featureIdentifier, { someState: true, someOtherState: 123 }); +map.getFeatureState(featureIdentifier); +map.removeFeatureState(featureIdentifier, 'someState'); +map.removeFeatureState(featureIdentifier); /** * Popup @@ -412,9 +455,9 @@ marker.remove(); /* * LngLatBounds */ -let bool:boolean -let bounds = new mapboxgl.LngLatBounds() -bool = bounds.isEmpty() +let bool:boolean; +let bounds = new mapboxgl.LngLatBounds(); +bool = bounds.isEmpty(); /* * AttributionControl */ @@ -533,7 +576,7 @@ let cameraForBoundsOpts: mapboxgl.CameraForBoundsOptions = { maxZoom: 10, padding, ...cameraOpts, -} +}; expectType(map.cameraForBounds(lnglatboundslike)); expectType(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts));