diff --git a/src/ui/camera.js b/src/ui/camera.js index 87a6e692f2d..ae850423ce5 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -369,11 +369,11 @@ class Camera extends Evented { * `options` provided in arguments. If map is unable to fit, method will warn and return undefined. * @example * var bbox = [[-79, 43], [-73, 45]]; - * var newCameraTransform = map.getFitBoundsTransform(bbox, { + * var newCameraTransform = map.cameraForBounds(bbox, { * padding: {top: 10, bottom:25, left: 15, right: 5} * }); */ - getFitBoundsTransform(bounds: LngLatBoundsLike, options?: CameraOptions): void | CameraOptions & AnimationOptions { + cameraForBounds(bounds: LngLatBoundsLike, options?: CameraOptions): void | CameraOptions & AnimationOptions { options = extend({ padding: { top: 0, @@ -465,9 +465,9 @@ class Camera extends Evented { * @see [Fit a map to a bounding box](https://www.mapbox.com/mapbox-gl-js/example/fitbounds/) */ fitBounds(bounds: LngLatBoundsLike, options?: AnimationOptions & CameraOptions, eventData?: Object) { - const calculatedBounds = this.getFitBoundsTransform(bounds, options); + const calculatedBounds = this.cameraForBounds(bounds, options); - // getFitBoundsTransform warns + returns undefined if unable to fit: + // cameraForBounds warns + returns undefined if unable to fit: if (!calculatedBounds) return this; options = extend(calculatedBounds, options); diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index cf45c89269d..5efba5f8aa1 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -1664,12 +1664,12 @@ test('camera', (t) => { t.end(); }); - t.test('#getFitBoundsTransform', (t) => { + t.test('#cameraForBounds', (t) => { t.test('no padding passed', (t) => { const camera = createCamera(); const bb = [[-133, 16], [-68, 50]]; - const transform = camera.getFitBoundsTransform(bb); + const transform = camera.cameraForBounds(bb); t.deepEqual(fixedLngLat(transform.center, 4), { lng: -100.5, lat: 34.7171 }, 'correctly calculates coordinates for new bounds'); t.equal(fixedNum(transform.zoom, 3), 2.469); t.end(); @@ -1679,7 +1679,7 @@ test('camera', (t) => { const camera = createCamera(); const bb = [[-133, 16], [-68, 50]]; - const transform = camera.getFitBoundsTransform(bb, { padding: 15 }); + const transform = camera.cameraForBounds(bb, { padding: 15 }); t.deepEqual(fixedLngLat(transform.center, 4), { lng: -100.5, lat: 34.7171 }, 'correctly calculates coordinates for bounds with padding option as number applied'); t.equal(fixedNum(transform.zoom, 3), 2.382); t.end(); @@ -1689,7 +1689,7 @@ test('camera', (t) => { const camera = createCamera(); const bb = [[-133, 16], [-68, 50]]; - const transform = camera.getFitBoundsTransform(bb, { padding: {top: 10, right: 75, bottom: 50, left: 25}, duration: 0 }); + const transform = camera.cameraForBounds(bb, { padding: {top: 10, right: 75, bottom: 50, left: 25}, duration: 0 }); t.deepEqual(fixedLngLat(transform.center, 4), { lng: -100.5, lat: 34.7171 }, 'correctly calculates coordinates for bounds with padding option as object applied'); t.end(); });