-
-
Notifications
You must be signed in to change notification settings - Fork 860
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
Added MapController.fitCoordinates
method
#1549
Conversation
Hi @jjoelson! Yes, you are spot-on. I only found the bug in |
Great, thank you! While writing tests I realized that the calculations to handle padding are not quite correct, so I'm going to push an update at some point today or tomorrow to address that. |
Okay, I will have a look a bit later then! Oh, and if you have the fixed |
OK, I pushed an update with the fixed padding computation and tests. I have two questions:
I should be able to put up a separate PR for that some time next week. 👍 |
Hey @jjoelson, apologies for not popping in sooner! Thanks for the contributions so far! Fixes and improvements are always appriciated. Just to let you know, the checks appear to be failing atm due to an unnecessary import.
Don't worry about documentation or changelog, I do that before a release. If you can add an example, please do!
If they can share now, they should share now. However, the class does need some improvements in terms of documentation, clarity, and ensuring consistency. |
MapController.fitCoordinates
method
28eee4f
to
3b6035f
Compare
Hey @jjoelson, nice work on this PR and the fitBounds fix! I was looking at bounds related code in #1551 before I noticed these two PRs. We have three different ways of expressing map bounds right now (four with your coordinate bounds) and I was hoping we could clean that up by creating a MapBounds base class which the different bounds implementations can subclass. I mentioned it in this comment but disregard the suggestions for the specific methods as I'm starting to think they don't make sense. I think we have the following variations of map bounds (I've given them names for convenience, the names can change):
These would all subclass
If you think this is doable and a good idea, maybe you could help me determine what methods MapBounds would need to expose? EDIT: |
(I've converted this to a draft due to it's conflicting interaction with #1551. @rorystephenson Any commits that integrate this change, if this PR is no longer needed, please add @jjoelson as co-author and mention this PR ID in commit message to give appropriate credit.) |
3b6035f
to
4025e34
Compare
Hi all! With this PR I'm proposing to add a new map controller method called
fitCoordinates
.When we have a list of lat/lng coordinates and want to fit the map viewport to those coordinates, the current best practice is to first calculate a
LatLngBounds
, and then usefitBounds
:With this PR, we can instead write:
The origin of this PR is that I was trying to implement a fix for #1342 to make
fitBounds
work correctly when the map is rotated. I implemented this fix which was proposed by @JosefWN but the result was a bit surprising to me:I was puzzled by the additional padding to the left of the green marker, until I remembered
fitBounds
is fitting theLatLngBounds
, not the 4 coordinates themselves. GivenLatLngBounds
can only represent a rectangle bounds in a north-up orientation, then what is happening here is correct; that extra margin on the left is required to fit the northwestern most point of the bounds. If we draw a black rectangle polyline that represents theLatLngBounds
of the four points, then we can see it's working as it should:So I realized
fitBounds
, even if corrected to work with rotation, is not what I actually need, and is probably not what most users of this package need when trying to fit a list of coordinates in the viewport when the map is rotated. Rather, I needed a method likefitCoordinates
that fits specific coordinate points, regardless of rotation. WithfitCoordinates
, the result looks like this:Rather than fitting a north-up bounding box of the coordinates,
fitCoordinates
fits the coordinates themselves.I plan to add tests and make some minor tweaks to the code to avoid some duplicate computations, but I wanted to post this PR before putting in too much more work so I can get feedback from the experienced maintainers of this package about this idea. Am I correct that
fitCoordinates
does something useful and different thanfitBounds
when the map is rotated?