@@ -84,9 +84,9 @@ def __init__(self, location=None, width=960, height=500,
84
84
----------
85
85
location: tuple or list, default None
86
86
Latitude and Longitude of Map (Northing, Easting).
87
- width: int, default 960
87
+ width: pixel int or percentage string ( default 960)
88
88
Width of the map.
89
- height: int, default 500
89
+ height: pixel int or percentage string ( default 500)
90
90
Height of the map.
91
91
tiles: str, default 'OpenStreetMap'
92
92
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,
135
135
self .location = location
136
136
137
137
# 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 ))
138
149
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 ))
139
162
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 ))
143
163
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 ))
144
167
# Templates.
145
168
self .env = ENV
146
169
self .template_vars = dict (lat = location [0 ],
0 commit comments