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

How to set bounding box to map? #30

Open
eruiz67 opened this issue Feb 2, 2023 · 1 comment
Open

How to set bounding box to map? #30

eruiz67 opened this issue Feb 2, 2023 · 1 comment

Comments

@eruiz67
Copy link

eruiz67 commented Feb 2, 2023

Im trayin to represent a polygon in the map. But when I do so, The size of the polygon in the map is so little. I need a way to define a bounding box in the map, or a zoom level, so I can the the polygon bigger.
polygon pillow
Here is the code:


import staticmaps

context = staticmaps.Context()
context.set_tile_provider(staticmaps.tile_provider_OSM)

polygon = [
    (11.946898955783189, -86.1092862482307 ),
    (11.947196373156675, -86.10915988584337 ),
    (11.947196373156675, -86.10896210123707),
    (11.946897164111272, -86.1088650402729),
    (11.946898955783189, -86.1092862482307)
]

context.add_object(
    staticmaps.Area(
        [staticmaps.create_latlng(lat, lng) for lat, lng in polygon],
        fill_color=staticmaps.parse_color("#00FF003F"),
        width=2,
        color=staticmaps.BLUE,
    )
)

# render non-anti-aliased png
image = context.render_pillow(800, 500)
image.save("polygon.pillow.png")

# render anti-aliased png (this only works if pycairo is installed)
image = context.render_cairo(800, 500)
image.write_to_png("polygon.cairo.png")

# render svg
svg_image = context.render_svg(800, 500)
with open("polygon.svg", "w", encoding="utf-8") as f:
    svg_image.write(f, pretty=True)
@lowtower
Copy link
Contributor

lowtower commented Feb 3, 2023

Hello @eruiz67

the zoom should be determined automatically - in Your case it is calculated to 15.
Instead, you can set the zoom "manually" with context.set_zoom(), e.g.

...
staticmaps.context.add_object(
    staticmaps.Area(
        [staticmaps.create_latlng(lat, lng) for lat, lng in polygon],
        fill_color=staticmaps.parse_color("#00FF003F"),
        width=2,
        color=staticmaps.BLUE,
    )
)
staticmaps.context.set_zoom(17)
...

Cheers,
LT

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