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

Allow bounds fitting options to be provided for initial bounds. #7681

Merged
merged 1 commit into from
Dec 18, 2018
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
3 changes: 2 additions & 1 deletion src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const defaultOptions = {
* @param {number} [options.bearing=0] The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
* @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-60). If `pitch` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
* @param {LngLatBoundsLike} [options.bounds] The initial bounds of the map. If `bounds` is specified, it overrides `center` and `zoom` constructor options.
* @param {Object} [options.fitBoundsOptions] A [`fitBounds`](#Map#fitBounds) options object to use when fitting the initial bounds provided above.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about emphasizing that this is only used for the initial bounds. Maybe something like:

A fitBounds options object to fit the initial bounds of the map when the bounds option is specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A fitBounds options object to use when fitting the initial bounds provided above.

The version already in there does say that it's for the initial bounds, but perhaps adding only and providing the right syntax note for the bounds would clarify further?

A fitBounds options object to use only when fitting the initial bounds provided above.

Copy link

Choose a reason for hiding this comment

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

The anchors in the link to the fitBounds API should be all lower-case: #map#fitbounds. It's currently broken on https://docs.mapbox.com/mapbox-gl-js/api/ :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, sorry, I'll open another PR for that. TIL that it's legit to have an id with a hash in it!

I did just copy that link from other documentation, so I'll check around - likely that it's broken elsewhere too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one I copied it from has already been fixed in #7791, so just this one to fix :)

Copy link
Contributor Author

@elyobo elyobo Feb 18, 2019

Choose a reason for hiding this comment

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

Fix in #7917 - thanks @j5kay.

* @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered, when zoomed out.
* @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
* @param {string} [options.localIdeographFontFamily=null] If specified, defines a CSS font-family
Expand Down Expand Up @@ -381,7 +382,7 @@ class Map extends Camera {

if (options.bounds) {
this.resize();
this.fitBounds(options.bounds, { duration: 0 });
this.fitBounds(options.bounds, extend({}, options.fitBoundsOptions, { duration: 0 }));
}
}

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 @@ -67,6 +67,24 @@ test('Map', (t) => {
t.end();
});

t.test('initial bounds options in constructor options', (t) => {
const bounds = [[-133, 16], [-68, 50]];

const map = (fitBoundsOptions, skipCSSStub) => {
const container = window.document.createElement('div');
Object.defineProperty(container, 'offsetWidth', {value: 512});
Object.defineProperty(container, 'offsetHeight', {value: 512});
return createMap(t, { skipCSSStub, container, bounds, fitBoundsOptions });
};

const unpadded = map(undefined, false);
const padded = map({ padding: 100 }, true);

t.ok(unpadded.getZoom() > padded.getZoom());

t.end();
});

t.test('disables handlers', (t) => {
t.test('disables all handlers', (t) => {
const map = createMap(t, {interactive: false});
Expand Down