@@ -84,9 +84,9 @@ def __init__(self, location=None, width=960, height=500,
8484 ----------
8585 location: tuple or list, default None
8686 Latitude and Longitude of Map (Northing, Easting).
87- width: int, default 960
87+ width: pixel int or percentage string ( default 960)
8888 Width of the map.
89- height: int, default 500
89+ height: pixel int or percentage string ( default 500)
9090 Height of the map.
9191 tiles: str, default 'OpenStreetMap'
9292 Map tileset to use. Can use defaults or pass a custom URL.
@@ -135,12 +135,35 @@ def __init__(self, location=None, width=960, height=500,
135135 self .location = location
136136
137137 # Map Size Parameters.
138+ try :
139+ if isinstance (width , int ):
140+ width_type = 'px'
141+ assert width > 0
142+ else :
143+ width_type = '%'
144+ width = int (width .strip ('%' ))
145+ assert 0 <= width <= 100
146+ except :
147+ msg = "Cannot parse width {!r} as {!r}" .format
148+ raise ValueError (msg (width , width_type ))
138149 self .width = width
150+
151+ try :
152+ if isinstance (height , int ):
153+ height_type = 'px'
154+ assert height > 0
155+ else :
156+ height_type = '%'
157+ height = int (height .strip ('%' ))
158+ assert 0 <= height <= 100
159+ except :
160+ msg = "Cannot parse height {!r} as {!r}" .format
161+ raise ValueError (msg (height , height_type ))
139162 self .height = height
140- self .map_size = {'width' : width , 'height' : height }
141- self ._size = ('style="width: {0}px; height: {1}px"'
142- .format (width , height ))
143163
164+ self .map_size = {'width' : width , 'height' : height }
165+ self ._size = ('style="width: {0}{1}; height: {2}{3}"'
166+ .format (width , width_type , height , height_type ))
144167 # Templates.
145168 self .env = ENV
146169 self .template_vars = dict (lat = location [0 ],
0 commit comments