From ea62d7c444fef4fb65d5579e8f078d76a7419e08 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 28 Jun 2019 13:53:32 -0400 Subject: [PATCH] Update result of cameraForBounds (#35891) --- types/mapbox-gl/index.d.ts | 9 ++++++++- types/mapbox-gl/mapbox-gl-tests.ts | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index cfe55d9ddb..6423f71818 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -199,7 +199,7 @@ declare namespace mapboxgl { setPitch(pitch: number, eventData?: EventData): this; - cameraForBounds(bounds: LngLatBoundsLike, options?: CameraForBoundsOptions): CameraOptions | undefined; + cameraForBounds(bounds: LngLatBoundsLike, options?: CameraForBoundsOptions): CameraForBoundsResult | undefined; fitBounds(bounds: LngLatBoundsLike, options?: mapboxgl.FitBoundsOptions, eventData?: mapboxgl.EventData): this; @@ -1211,6 +1211,13 @@ declare namespace mapboxgl { maxZoom?: number; } + // The Mapbox docs say that if the result is defined, it will have zoom, center and bearing set. + // In practice center is always a {lat, lng} object. + export type CameraForBoundsResult = Required> & { + /** Map center */ + center: {lng: number; lat: number}; + }; + /** * FlyToOptions */ diff --git a/types/mapbox-gl/mapbox-gl-tests.ts b/types/mapbox-gl/mapbox-gl-tests.ts index ac7e90e5a5..6e04375176 100644 --- a/types/mapbox-gl/mapbox-gl-tests.ts +++ b/types/mapbox-gl/mapbox-gl-tests.ts @@ -510,8 +510,8 @@ let cameraForBoundsOpts: mapboxgl.CameraForBoundsOptions = { ...cameraOpts, } -expectType(map.cameraForBounds(lnglatboundslike)); -expectType(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts)); +expectType(map.cameraForBounds(lnglatboundslike)); +expectType(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts)); expectType(map.fitScreenCoordinates([0, 0], pointlike, 1)); expectType(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts));