Update result of cameraForBounds (#35891)

This commit is contained in:
Dan Vanderkam
2019-06-28 13:53:32 -04:00
committed by Ben Lichtman
parent 653fbb1999
commit ea62d7c444
2 changed files with 10 additions and 3 deletions

View File

@@ -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<Pick<CameraOptions, 'zoom' | 'bearing'>> & {
/** Map center */
center: {lng: number; lat: number};
};
/**
* FlyToOptions
*/

View File

@@ -510,8 +510,8 @@ let cameraForBoundsOpts: mapboxgl.CameraForBoundsOptions = {
...cameraOpts,
}
expectType<mapboxgl.CameraOptions | undefined>(map.cameraForBounds(lnglatboundslike));
expectType<mapboxgl.CameraOptions | undefined>(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts));
expectType<mapboxgl.CameraForBoundsResult | undefined>(map.cameraForBounds(lnglatboundslike));
expectType<mapboxgl.CameraForBoundsResult | undefined>(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts));
expectType<mapboxgl.Map>(map.fitScreenCoordinates([0, 0], pointlike, 1));
expectType<mapboxgl.Map>(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts));