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

Conversation

elyobo
Copy link
Contributor

@elyobo elyobo commented Dec 6, 2018

Complements #5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page
  • tagged @mapbox/studio and/or @mapbox/maps-design if this PR includes style spec changes

I'm not sure how to manually test the debug page, but have implemented a simple unit test (that adding padding decreases the zoom vs not adding it).

fixes #7553

@elyobo
Copy link
Contributor Author

elyobo commented Dec 6, 2018

@mourner you were the reviewer for #5518, this is related, so possibly you would be appropriate to look at this?

@elyobo elyobo force-pushed the bounds-options-in-init branch 2 times, most recently from 6506698 to cd4af61 Compare December 6, 2018 23:19
Complements mapbox#5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.
@elyobo
Copy link
Contributor Author

elyobo commented Dec 7, 2018

Resolved initial lint/test issues, pushed amended commit.

@@ -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.

@asheemmamoowala asheemmamoowala merged commit 55f4c01 into mapbox:master Dec 18, 2018
@elyobo elyobo deleted the bounds-options-in-init branch December 18, 2018 23:45
@elyobo
Copy link
Contributor Author

elyobo commented Dec 18, 2018

Thanks @asheemmamoowala. I didn't see your thumbs up to my more detailed description of the option (GH notifications don't mention those!), so the merged version only had my original description. Would you like a new PR with the change?

@matyushen
Copy link

So how could I use it? This doesn't seem to work:

var map = new mapboxgl.Map({
  center: [-122.420679, 37.772537],
  zoom: 13,
  bounds: [[-73.9876, 40.7661], [-73.9397, 40.8002]],
  fitBoundsOptions: {
    padding: { top: 100, bottom: 407, left: 100, right: 100 }
  }
});

Padding is not applied. Am I doing something wrong here?
Thanks!

@asheemmamoowala
Copy link
Contributor

@matyushen this will be available in the next release.

@elyobo - a new PR would be great!

elyobo added a commit to elyobo/mapbox-gl-js that referenced this pull request Jan 3, 2019
@elyobo
Copy link
Contributor Author

elyobo commented Jan 3, 2019

NP @asheemmamoowala, see #7743

@mrmos
Copy link

mrmos commented Oct 28, 2019

the correct format for this is:

fitBoundsOptions: {
    padding: 100
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support fitBounds options when setting the initial map bounds
5 participants