@@ -370,17 +370,60 @@ def test_geo_json_str(self):
370
370
371
371
# Verify the geo_json object
372
372
obj_temp = jinja2 .Template ("""
373
- var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
374
- .addTo({{ this._parent.get_name() }});
373
+ var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
374
+ .addTo({{ this._parent.get_name() }});
375
375
{{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
376
376
""" )
377
377
obj = obj_temp .render (this = geo_json , json = json )
378
+ rendered_obj = '' .join (obj .split ())[:- 1 ]
379
+
378
380
assert '' .join (obj .split ())[:- 1 ] in out
379
381
380
382
bounds = self .map .get_bounds ()
381
383
assert bounds == [[18.948267 , - 171.742517 ],
382
384
[71.285909 , - 66.979601 ]], bounds
383
385
386
+ def test_geo_json_highlight (self ):
387
+ # Highlight data binding
388
+ self .map = folium .Map ([43 , - 100 ], zoom_start = 4 )
389
+ path = os .path .join (rootpath , 'us-counties.json' )
390
+
391
+ data = json .load (open (path ))
392
+
393
+ for feature in data ['features' ]:
394
+ feature .setdefault ('properties' , {}).setdefault ('style' , {}).update ({ # noqa
395
+ 'color' : 'black' ,
396
+ 'opacity' : 1 ,
397
+ 'fillOpacity' : 0.6 ,
398
+ 'weight' : 1 ,
399
+ 'fillColor' : 'blue' ,
400
+ })
401
+
402
+ self .map .geo_json (geo_str = json .dumps (data ), highlight = True )
403
+
404
+ geo_json = [x for x in self .map ._children .values () if
405
+ isinstance (x , GeoJson )][0 ]
406
+
407
+ out = '' .join (self .map ._parent .render ().split ())
408
+
409
+ # Verify the geo_json object
410
+ obj_temp = jinja2 .Template ("""
411
+ var {{ this.get_name() }} = L.geoJson(
412
+ {{ this.style_data() }}
413
+ ,{onEachFeature: {{this.get_name()}}_onEachFeature }
414
+ ).addTo({{ this._parent.get_name() }});
415
+ {{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
416
+ """ )
417
+ obj = obj_temp .render (this = geo_json , json = json )
418
+ rendered_obj = '' .join (obj .split ())[:- 1 ]
419
+
420
+ assert '' .join (obj .split ())[:- 1 ] in out
421
+
422
+ bounds = self .map .get_bounds ()
423
+ assert bounds == [[18.948267 , - 171.742517 ],
424
+ [71.285909 , - 66.979601 ]], bounds
425
+
426
+
384
427
def test_geo_json_bad_color (self ):
385
428
"""Test geojson method."""
386
429
0 commit comments