Skip to content

Commit

Permalink
rename getFitBoundsTransform -> cameraForBounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Jun 6, 2018
1 parent 1cc31d9 commit 80ae1d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/ui/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
});
Expand Down

0 comments on commit 80ae1d7

Please sign in to comment.