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

fitBounds with padding zooms the map really far out #4528

Closed
theashyster opened this issue May 3, 2016 · 27 comments
Closed

fitBounds with padding zooms the map really far out #4528

theashyster opened this issue May 3, 2016 · 27 comments
Labels
Milestone

Comments

@theashyster
Copy link
Contributor

theashyster commented May 3, 2016

I am not sure if this is a regression or not, but I have experienced that since the RC1 release the map fitBounds function with padding option does not work the same way as it worked before.

Some examples:
Leaflet 0.7.5 http://playground-leaflet.rhcloud.com/niv/edit?html,output
Leaflet 1.0.0-beta.2 http://playground-leaflet.rhcloud.com/jasi/edit?html,output
Leaflet 1.0.0-rc.1 http://playground-leaflet.rhcloud.com/cipe/edit?html,output

The padding is just really big and the map is zoomed far out. We have used this function with the padding on layer containing SVG polygon also and since RC1 that also started to act strange by zooming the map really far out.

I can get the same result on RC1 by setting the padding option on a point that is really small L.point(0.001, 0.001).

@IvanSanchez IvanSanchez added the bug label May 3, 2016
@IvanSanchez IvanSanchez added this to the 1.0 milestone May 3, 2016
@jieter
Copy link
Contributor

jieter commented May 3, 2016

Sounds like a perfect chance for a simple unit test and some git bisecting...

@IvanSanchez
Copy link
Member

IvanSanchez commented May 3, 2016

The culprit seems to be this line:

boundsSize = this.project(se, zoom).subtract(this.project(nw, zoom)).add(padding),

That's getting the size (in pixels) of the bounds to fit, at the current zoom level, then adding the padding.

What we really want is to have the padding at the destination zoom level, not at the original zoom level.

@IvanSanchez
Copy link
Member

IvanSanchez commented May 3, 2016

A possible solution would be to subtract padding from size - but that needs testing.

I think this is a rather self-contained, explained bug, so I think any newbie can try fixing this. (Hello, @yourfirstpr!).

Things to be done:

  • Let people know you're interested
  • Fork the leaflet repo and clone it locally
  • Modify src/map/Map.js around line 509 so that padding is subtracted from size (instead of being added to boundsSize)
  • Add some unit tests to spec/map/MapSpec.js, next to the tests for getBounds() - ensure that calls to getBoundsZoom() with small areas and big padding returns high levels of zoom (currently it returns low levels like 0 and 1)
  • Run npm install, npm test
  • git commit, git push
  • Create merge request

@varjmes
Copy link

varjmes commented May 3, 2016

👋 Thanks so much for another wonderful guide, @IvanSanchez! Will post this out to @yourfirstpr shortly :)

@theashyster
Copy link
Contributor Author

theashyster commented May 3, 2016

@IvanSanchez Looks like this is related then #4172

@theashyster
Copy link
Contributor Author

theashyster commented May 3, 2016

Tried subtract padding from size and not adding padding to boundsSize and it seems to have helped with this case.

@dianjin
Copy link
Contributor

dianjin commented May 3, 2016

I would love to do this! Thanks for the guide, I'll follow it and let you know my results. 😄

@hyperknot
Copy link
Collaborator

hyperknot commented May 3, 2016

I'd just like to add to the list:

  • test it with the default zoomSnap: 1 option
  • test it with a fractional zoomSnap, like 0.25
  • test it with zoomSnap: false or 0

For development of fitBounds I believe the best is to use zoomSnap: 0, as snapping to an integer zoom level will usually add a big padding on it's own.

@dianjin
Copy link
Contributor

dianjin commented May 3, 2016

Here's what I have so far: #4532

Please let me know if I did everything correctly!

@hyperknot
Copy link
Collaborator

hyperknot commented May 3, 2016

@dianjin code looks good for me, wrote a comment about the test.

Feel free to tick the completed checkboxes on this page.

@IvanSanchez
Copy link
Member

IvanSanchez commented May 9, 2016

Closed via #4532

@theashyster
Copy link
Contributor Author

theashyster commented May 9, 2016

Thanks again for fixing the issue 👍

@eldamsheety
Copy link

eldamsheety commented Nov 15, 2017

how could I start joining an open source here?

@aalsiuser
Copy link

aalsiuser commented Feb 10, 2018

As Iam new to open source community so how can i help you in contributing over here?

@qwertypool
Copy link

qwertypool commented Feb 11, 2018

hello, how may i join and start contributing to this open source ??

@ghybs
Copy link
Collaborator

ghybs commented Feb 12, 2018

Hi @eldamsheety, @aalsiuser and @qwertypool,

Thank you for your interest in Leaflet!
Sorry for not getting back to you earlier.

There are many ways of contributing to this project, and to Open Source projects in general.

This thread is already closed, since the bug it describes has already been fixed in PR #4532.
Avoid commenting on closed threads, as you may remain unnoticed, unless what you have to say is absolutely relevant to the thread (e.g. when the bug is actually not fixed). And even in that case, it is probably better opening a new issue and mentioning the closed thread.

As for contributing, you could have a look at threads with label "help wanted" and/or "good first issue".

Keep up the good work and feel free to ask! 😄

@Reshwanth
Copy link

Reshwanth commented Mar 4, 2020

Hi I am new to this open source community projects. So, how can i start contributing in the projects?

@angelhen2020
Copy link

angelhen2020 commented Mar 14, 2020

👾 I would like to contribute !

@SAG17hande
Copy link

SAG17hande commented Jul 14, 2020

Hi I am new to this open source community projects. So, how can i start contributing in the projects, how can i learn as well as contribute ?

@ugofine
Copy link

ugofine commented Sep 6, 2020

I am new here, will like to contribute.

@ixxiv
Copy link

ixxiv commented Sep 16, 2020

I guess I'm late to the party... I'm new to the open source community and how do i contribute

@akshat-max
Copy link

akshat-max commented Sep 21, 2020

I'm new to the open-source community and how can I contribute.

@yakim228
Copy link

yakim228 commented Oct 3, 2020

Hi, I would like to contribute to the open-source community, how can i get started ?

@ghybs
Copy link
Collaborator

ghybs commented Oct 8, 2020

Hi @johnd0e,

I am taking the liberty to draw your attention on this closed thread, which seems to be for some reason the landing page of potential new contributors.

Please what kind of entry point do you think could be more appropriate, so that newcomers can receive better information?

They may also be interested in the Hacktoberfest event, which you can leverage by tagging issues that you would like contributors to work on with a new "hacktoberfest" label, and tagging meaningful Pull Requests with a new "hacktoberfest-accepted" label (see https://hacktoberfest.digitalocean.com/details#rules).

I hope this can be helpful somehow!

@IvanSanchez
Copy link
Member

IvanSanchez commented Oct 9, 2020

The point of entry should be https://github.com/Leaflet/Leaflet/blob/master/CONTRIBUTING.md . Maybe there's a need to rewrite parts of that.

Regarding the hacktoberfest thing, I've read that it has spawned vandalism, so I'm kinda against that.

@johnd0e
Copy link
Collaborator

johnd0e commented Oct 9, 2020

Hi @ghybs.
I am not sure why are you addressing me personally, but anywhere I agree with @IvanSanchez.

this closed thread, which seems to be for some reason the landing page of potential new contributors.

And I really doubt that these strange people are really able to be useful for Leaflet.

P.S.
May be better remove good first issue tag from closed issues.

@johnd0e johnd0e removed good first issue Good for newcomers help wanted labels Oct 9, 2020
@IvanSanchez
Copy link
Member

IvanSanchez commented Oct 9, 2020

The reason people are coming to this issue is probably the link from https://opensource.guide/how-to-contribute/ . This (at least the first few comments) is a good example of how a (good-ish) bug report looks like.

So, to any lost souls coming here: if you want to do something with Leaflet specifically, read https://github.com/Leaflet/Leaflet/blob/master/CONTRIBUTING.md , see the list of open bugs, go fix something. For general stuff about FLOSS, go read https://www.gnu.org/philosophy/floss-and-foss.en.html and https://opensource.org/resources and the parts of the https://opensource.guide/ thing that you skipped. Read.

I'm locking the issue to prevent any further comments from newbies.

@Leaflet Leaflet locked as resolved and limited conversation to collaborators Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests