komoot / staticmap

A small, python-based library for creating map images with lines, markers and polygons.
https://www.komoot.com
Other
290 stars 65 forks source link

Do not draw transparent polygons #3

Closed lvonlanthen closed 8 years ago

lvonlanthen commented 8 years ago

Do not draw polygons on the map if fill_color and outline_color are None.

m = StaticMap(500, 400)
m.add_marker(CircleMarker((7.15, 46.80), '#0036FF', 12))
bbox_coords = [
    [5.96, 47.81],
    [5.96, 45.83],
    [10.49, 45.83],
    [10.49, 47.81],
    [5.96, 47.81]]
m.add_polygon(Polygon(bbox_coords, None, None))
image = m.render()
image.save('map.png')

Creates a thin polygon even though fill_color = None and outline_color = None. See https://imgur.com/yr3nQSX

christophlingg commented 8 years ago

What's the point of drawing a invisble polygon? But it's still a misbehaviour of the lib, great fix!

lvonlanthen commented 8 years ago

I have a use case where I always want to zoom to the entire country of a marker. So basically, I want to have a fixed extent of the map. As there is no function such as StaticMap.set_extent(bbox), I am adding an invisible polygon (the bounding box of the country) so the extent calculated in StaticMap.determine_extent() shows the entire country. It is probably not the most elegant way, but it works, especially now that the bbox is not showing anymore. Thanks for accepting my change!

christophlingg commented 8 years ago

That's a use case I haven't thought of yet, but it's relevant. I will create a corresponding ticket.