Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add map.getMaxBounds method #4890

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,23 @@ class Map extends Camera {
return bounds;
}

/**
* Gets the map's geographical bounds.
*
* Returns the LngLatBounds by which pan and zoom operations on the map are constrained.
*
* @returns {LngLatBounds | null} The maximum bounds the map is constrained to, or `null` if none set.
*/
getMaxBounds () {
if (this.transform.latRange && this.transform.latRange.length === 2 &&
this.transform.lngRange && this.transform.lngRange.length === 2) {
return new LngLatBounds([this.transform.lngRange[0], this.transform.latRange[0]],
[this.transform.lngRange[1], this.transform.latRange[1]]);
} else {
return null;
}
}

/**
* Sets or clears the map's geographical bounds.
*
Expand Down Expand Up @@ -434,6 +451,7 @@ class Map extends Camera {
return this;

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidental line? 🙃

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everywhere else had a whitespace between methods, so I added one here to be consistent.

/**
* Sets or clears the map's minimum zoom level.
* If the map's current zoom level is lower than the new minimum,
Expand Down
18 changes: 18 additions & 0 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,24 @@ test('Map', (t) => {
t.end();
});

t.test('#getMaxBounds', (t) => {
t.test('returns null when no bounds set', (t) => {
const map = createMap({zoom:0});
t.equal(map.getMaxBounds(), null);
t.end();
});

t.test('returns bounds', (t) => {
const map = createMap({zoom:0});
const bounds = [[-130.4297, 50.0642], [-61.52344, 24.20688]];
map.setMaxBounds(bounds);
t.deepEqual(map.getMaxBounds().toArray(), bounds);
t.end();
});

t.end();
});

t.test('#setMinZoom', (t) => {
const map = createMap({zoom:5});
map.setMinZoom(3.5);
Expand Down