Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions staticmap/staticmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def extent(self):


class CircleMarker:
def __init__(self, coord, color, width):
def __init__(self, coord, color, width, outline_color=None):
"""
:param coord: a lon-lat pair, eg (175.0, 0.0)
:type coord: tuple
Expand All @@ -55,6 +55,7 @@ def __init__(self, coord, color, width):
self.coord = coord
self.color = color
self.width = width
self.outline_color = outline_color

@property
def extent_px(self):
Expand Down Expand Up @@ -179,7 +180,9 @@ def _simplify(points, tolerance=11):


class StaticMap:
def __init__(self, width, height, padding_x=0, padding_y=0, url_template="http://a.tile.komoot.de/komoot-2/{z}/{x}/{y}.png", tile_size=256, tile_request_timeout=None, headers=None, reverse_y=False, background_color="#fff",
def __init__(self, width, height, padding_x=0, padding_y=0,
url_template="http://a.tile.komoot.de/komoot-2/{z}/{x}/{y}.png", tile_size=256,
tile_request_timeout=None, headers=None, reverse_y=False, background_color="#fff",
delay_between_retries=0):
"""
:param width: map width in pixel
Expand Down Expand Up @@ -412,7 +415,8 @@ def _draw_base_layer(self, image):
raise RuntimeError("could not download {} tiles: {}".format(len(tiles), tiles))

failed_tiles = []
futures = [thread_pool.submit(requests.get, tile[2], timeout=self.request_timeout, headers=self.headers) for tile in tiles]
futures = [thread_pool.submit(requests.get, tile[2], timeout=self.request_timeout, headers=self.headers) for
tile in tiles]

for tile, future in zip(tiles, futures):
x, y, url = tile
Expand Down Expand Up @@ -451,9 +455,9 @@ def _draw_features(self, image):

for line in self.lines:
points = [(
self._x_to_px(_lon_to_x(coord[0], self.zoom)) * 2,
self._y_to_px(_lat_to_y(coord[1], self.zoom)) * 2,
) for coord in line.coords]
self._x_to_px(_lon_to_x(coord[0], self.zoom)) * 2,
self._y_to_px(_lat_to_y(coord[1], self.zoom)) * 2,
) for coord in line.coords]

if line.simplify:
points = _simplify(points)
Expand All @@ -479,14 +483,14 @@ def _draw_features(self, image):
point[1] - circle.width,
point[0] + circle.width,
point[1] + circle.width
), fill=circle.color)
), fill=circle.color, outline=circle.outline_color)

for polygon in self.polygons:
points = [(
self._x_to_px(_lon_to_x(coord[0], self.zoom)) * 2,
self._y_to_px(_lat_to_y(coord[1], self.zoom)) * 2,
self._x_to_px(_lon_to_x(coord[0], self.zoom)) * 2,
self._y_to_px(_lat_to_y(coord[1], self.zoom)) * 2,

) for coord in polygon.coords]
) for coord in polygon.coords]
if polygon.simplify:
points = _simplify(points)

Expand Down