@@ -79,6 +79,8 @@ def _parse_path(**kw):
79
79
80
80
"""
81
81
color = kw .pop ('color' , '#3388ff' )
82
+ fill_color = kw .pop ('fill_color' , color )
83
+ fill = False if not fill_color else True
82
84
return {
83
85
'stroke' : kw .pop ('stroke' , True ),
84
86
'color' : color ,
@@ -88,8 +90,8 @@ def _parse_path(**kw):
88
90
'lineJoin' : kw .pop ('line_join' , 'round' ),
89
91
'dashArray' : kw .pop ('dash_array' , None ),
90
92
'dashOffset' : kw .pop ('dash_offset' , None ),
91
- 'fill' : kw . pop ( ' fill' , False ) ,
92
- 'fillColor' : kw . pop ( ' fill_color' , color ) ,
93
+ 'fill' : fill ,
94
+ 'fillColor' : fill_color ,
93
95
'fillOpacity' : kw .pop ('fill_opacity' , 0.2 ),
94
96
'fillRule' : kw .pop ('fill_rule' , 'evenodd' ),
95
97
'bubblingMouseEvents' : kw .pop ('bubbling_mouse_events' , True ),
@@ -309,3 +311,61 @@ def mercator(x):
309
311
if origin == 'upper' :
310
312
out = out [::- 1 , :, :]
311
313
return out
314
+
315
+
316
+ def none_min (x , y ):
317
+ if x is None :
318
+ return y
319
+ elif y is None :
320
+ return x
321
+ else :
322
+ return min (x , y )
323
+
324
+
325
+ def none_max (x , y ):
326
+ if x is None :
327
+ return y
328
+ elif y is None :
329
+ return x
330
+ else :
331
+ return max (x , y )
332
+
333
+
334
+ def iter_points (x ):
335
+ """Iterates over a list representing a feature, and returns a list of points,
336
+ whatever the shape of the array (Point, MultiPolyline, etc).
337
+ """
338
+ if isinstance (x , (list , tuple )):
339
+ if len (x ):
340
+ if isinstance (x [0 ], (list , tuple )):
341
+ out = []
342
+ for y in x :
343
+ out += iter_points (y )
344
+ return out
345
+ else :
346
+ return [x ]
347
+ else :
348
+ return []
349
+ else :
350
+ raise ValueError ('List/tuple type expected. Got {!r}.' .format (x ))
351
+
352
+
353
+ def get_bounds (locations ):
354
+ """
355
+ Computes the bounds of the object in the form
356
+ [[lat_min, lon_min], [lat_max, lon_max]]
357
+
358
+ """
359
+ bounds = [[None , None ], [None , None ]]
360
+ for point in iter_points (locations ):
361
+ bounds = [
362
+ [
363
+ none_min (bounds [0 ][0 ], point [0 ]),
364
+ none_min (bounds [0 ][1 ], point [1 ]),
365
+ ],
366
+ [
367
+ none_max (bounds [1 ][0 ], point [0 ]),
368
+ none_max (bounds [1 ][1 ], point [1 ]),
369
+ ],
370
+ ]
371
+ return bounds
0 commit comments