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));