-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Description
Currently, if you generate a SVG based on bounds, it will contain more than just the bounds you gave, because we have to specify output width and height, and also because zoom level are integers.
It would be awesome be able to let the program choose the output size based on the given bounds (or have a minWidth, minHeight instead).
Current behavior:
The code:
import staticmaps
import s2sphere
import sys
context = staticmaps.Context()
# add bounds on east Canada
context.add_bounds(s2sphere.LatLngRect(
s2sphere.LatLng.from_degrees(43.26120612479979, -79.859619140625),
s2sphere.LatLng.from_degrees(49.475263243037986, -63.017578125)
))
context.set_tile_provider(staticmaps.tile_provider_OSM)
svg_image = context.render_svg(2000, 2000)
with open("output.svg", "w", encoding="utf-8") as f:
svg_image.write(f, pretty=True)
Output file looks like this:
SVG file available here:
https://mega.nz/file/wtdARJwJ#4bXTgySf9vcmBBCnliu3blbkRoLW2hTIEcipWPbs4tg
When given bounds are:
Expected behavior
I think that we should be able to call the render_svg method with minWidth and minHeight arguments which would let the program choose a better zoom level, to perfectly fit the bounds.
Here is how it could work:
- User defines bounds
- User defines minWidth and minHeight
- The program would determine on it's own which size the output file should be to fit the bounds
- It renders the SVG with the viewbox matching the size
I would be ok to work on it, I already tried to do a first version but the mathematics used in the context._determine_zoom function are complicated, I don't know the formulas and I'm not sure to understand the variables.
I know that I can return return self._clamp_zoom(zoom) instead of return self._clamp_zoom(zoom - 1) but I don't know how to determine the output size.

