Skip to content

add initial bounds as map constructor option #1970 - #5518

Merged
mourner merged 5 commits into
mapbox:masterfrom
stepankuzmin:1970
Oct 8, 2018
Merged

mourner merged 5 commits into
mapbox:masterfrom
stepankuzmin:1970

Conversation

@stepankuzmin

@stepankuzmin stepankuzmin commented Oct 25, 2017 •

Copy link
Copy Markdown
Contributor

This PR will add initial bounds as map constructor option according to #1970.

I have a problem implementing the test for this case. Then I manually test new functionality using the debug page, I'm getting the expected result. But the same steps reproduced in test somehow outcomes with different zoom level in the result (1.113 instead of 2.469). What can cause this?

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • manually test the debug page

Comment thread src/ui/map.js Outdated
options.center = tr.unproject(nw.add(se).div(2));
options.zoom = Math.min(tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we reuse the code from fitBounds somehow and avoid copying it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, we can try to use fitBounds(bounds, { duration: 0 }) instead of manually reproducing fitBounds logic, but we have to resize the map before.

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

Unfortunately, the problem with the test is still there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have updated the PR using fitBounds

Comment thread test/unit/ui/map.test.js

t.end();
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But the same steps reproduced in test somehow outcomes with different zoom level

The zoom level depends on the size of the map container.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jfirebaugh
jfirebaugh force-pushed the 1970 branch 2 times, most recently from 5f83282 to fed794d Compare May 1, 2018 15:43
@mourner

mourner commented Jul 25, 2018

Copy link
Copy Markdown
Member

@stepankuzmin let's get this shipped. Can you rebase on master and fix the build?

@stepankuzmin

Copy link
Copy Markdown
Contributor Author

Oh, well, It seems that I mixed up rebasing. Should I create separate PR on top of the current master branch?

@mourner

mourner commented Jul 25, 2018 •

Copy link
Copy Markdown
Member

@stepankuzmin I think you can reset the PR branch to the master (git reset --hard origin/master), apply your commit on top and force-push — no need to create a new PR.

@stepankuzmin

Copy link
Copy Markdown
Contributor Author

Thanks for help, @mourner! It seems that tests are passing now.

Comment thread src/ui/map.js
pitch: options.pitch
});
if (options.bounds) {
this.resize();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need the resize here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without resize, Transform's pixelMatrixInverse is undefined here:

vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);

Maybe we can move following resize call before condition?

this.resize();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@stepankuzmin yes, let's do that — seems to be more logical.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

@mourner

mourner commented Jul 25, 2018

Copy link
Copy Markdown
Member

Hmm, now the query tests fail for some reason :(

@stepankuzmin

stepankuzmin commented Jul 25, 2018 •

Copy link
Copy Markdown
Contributor Author

That's strange, because test-query now fails on upstream/master too. Same with test-render.

@mourner

mourner commented Aug 9, 2018

Copy link
Copy Markdown
Member

@stepankuzmin maybe let's rebase on top of the current master and revisit this?

@stepankuzmin

Copy link
Copy Markdown
Contributor Author

I've rebased on top of the current master branch, but the tests are still failing. And the problem is that I can't reproduce it locally — all 14 376 tests are passing.

@mourner

mourner commented Aug 9, 2018

Copy link
Copy Markdown
Member

@stepankuzmin the unit tests are passing; it's the query and render tests that fail. I can reproduce failures locally, e.g. by running ./build/run-node test/render.test.js 5911. I guess moving resize before the jumpTo somehow messes up map initialization in certain circumstances.

@ryanhamley

Copy link
Copy Markdown
Contributor

Can we pick this back up? I'd love to close out as many PRs as possible. I was just testing it out and rebasing it against master is still straightforward. The only change necessary to get all the tests passing is moving this.resize() into the conditionals. It's a bit messy to call it twice, but since it needs to be called in a specific order depending on what options are passed, I think that's ok.

            if (options.bounds) {
                this.resize();
                this.fitBounds(options.bounds, { duration: 0 });
            } else {
                this.jumpTo({
                    center: options.center,
                    zoom: options.zoom,
                    bearing: options.bearing,
                    pitch: options.pitch
                });
                this.resize();
            }

I did notice after rebasing that I had to change the expected zoom value in the test from 2.469 to 2.113 to get that test to pass. I'm not totally sure why that would be the case, but changing that value produces a passing test.

@stepankuzmin

Copy link
Copy Markdown
Contributor Author

Hey @mourner and @ryanhamley! Sorry for the late reply, I've updated the PR according to the last comment — moved resize back to conditional and set expected zoom value in the test to 2.113.

@mourner
mourner merged commit 83aebca into mapbox:master Oct 8, 2018
@GeospatialMax

Copy link
Copy Markdown

@mourner Just stumbled upon this new feature which would be quite useful to us. When is the next release planned for this to be included as it's not in the current latest 0.50.0?

Thank you!

@ryanhamley

Copy link
Copy Markdown
Contributor

@GeovationMax This will be included in v0.51.0. The beta will be released next week and the final version will be released the following week, around November 7th.

@SoLoGHoST

Copy link
Copy Markdown

I am using the latest version js and css v0.51.0. Can someone please help me understand how to initialize the map with bounds? Doesn't work for me and I get no errors. It just doesn't seem to work.

@andrewharvey

andrewharvey commented Nov 16, 2018 •

Copy link
Copy Markdown
Collaborator

I am using the latest version js and css v0.51.0. Can someone please help me understand how to initialize the map with bounds? Doesn't work for me and I get no errors. It just doesn't seem to work.

See https://www.mapbox.com/mapbox-gl-js/api/#map there is a map option called bounds which accepts a LngLatBoundsLike

var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v9',
    bounds: [left, bottom, right, top]
});

@SoLoGHoST

SoLoGHoST commented Nov 16, 2018 •

Copy link
Copy Markdown

So, I'm misunderstood. How can I set a bunch of LngLat markers than have the map show with them centered in there by default? Instead of setting center property to a Lng,Lat.

@andrewharvey

Copy link
Copy Markdown
Collaborator

@SoLoGHoST

Copy link
Copy Markdown

@elyobo

elyobo commented Dec 6, 2018 •

Copy link
Copy Markdown
Contributor

This is great, but is missing a way to provide the padding that fitBounds supports; this is quite important if you're fitting bounds to some markers, as without padding greater than the market dimensions they'll always sit partially off the map.

@mourner would you be open to accepting a PR that adds a boundsOptions parameter which would be passed to the fitBounds call here, except that it would always apply a duration of 0 as per the PR?

Added #7681

elyobo added a commit to elyobo/mapbox-gl-js that referenced this pull request Dec 6, 2018
Complements mapbox#5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.
elyobo added a commit to elyobo/mapbox-gl-js that referenced this pull request Dec 6, 2018
Complements mapbox#5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.
elyobo added a commit to elyobo/mapbox-gl-js that referenced this pull request Dec 6, 2018
Complements mapbox#5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.
elyobo added a commit to elyobo/mapbox-gl-js that referenced this pull request Dec 6, 2018
Complements mapbox#5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.
elyobo added a commit to elyobo/mapbox-gl-js that referenced this pull request Dec 6, 2018
Complements mapbox#5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.
asheemmamoowala pushed a commit that referenced this pull request Dec 18, 2018
Complements #5518 by allowing additional options (notably padding) to be
provided for the initial bounds for a map.
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.

7 participants