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

Finding center and zoom level in given a list of lat-long pairs #54

Open
Lyazz opened this issue Feb 1, 2023 · 4 comments
Open

Finding center and zoom level in given a list of lat-long pairs #54

Lyazz opened this issue Feb 1, 2023 · 4 comments

Comments

@Lyazz
Copy link

Lyazz commented Feb 1, 2023

How do I find what should I set as the center and as the zoom level so that all the points show up.

@xclud
Copy link
Owner

xclud commented Feb 1, 2023

Depends on your tile layers and the details they represent.

@Lyazz
Copy link
Author

Lyazz commented Feb 2, 2023

I used the RasterMap one, I got 5 points on the map, i find the center by calculating the average LatLng thought it is rightly centered but the zoom is not optimal. thanks.

@xclud
Copy link
Owner

xclud commented Feb 2, 2023

To get the zoom level, you'll need to know the pixel dimensions of your map. You'll also need to do your math in spherical mercator coordinates.

Convert latitude, longitude to spherical mercator x, y.
Get distance between your two points in spherical mercator.
The equator is about 40m meters long projected and tiles are 256 pixels wide, so the pixel length of that map at a given zoom level is about 256 * distance/40000000 * 2^zoom. Try zoom=0, zoom=1, zoom=2 until the distance is too long for the pixel dimensions of your map.

Source: https://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map

I hope soon i will add this feature to the package.

@Lyazz
Copy link
Author

Lyazz commented Feb 5, 2023

Thanks mate.

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

No branches or pull requests

2 participants