@@ -471,6 +471,44 @@ def test_geo_json_str(self):
471471 assert bounds == [[18.948267 , - 171.742517 ],
472472 [71.285909 , - 66.979601 ]], bounds
473473
474+ def test_geo_json_highlight (self ):
475+ # Highlight data binding
476+ self .map = folium .Map ([43 , - 100 ], zoom_start = 4 )
477+ path = os .path .join (rootpath , 'us-counties.json' )
478+
479+ data = json .load (open (path ))
480+
481+ for feature in data ['features' ]:
482+ feature .setdefault ('properties' , {}).setdefault ('style' , {}).update ({ # noqa
483+ 'color' : 'black' ,
484+ 'opacity' : 1 ,
485+ 'fillOpacity' : 0.6 ,
486+ 'weight' : 1 ,
487+ 'fillColor' : 'blue' ,
488+ })
489+
490+ self .map .geo_json (geo_str = json .dumps (data ), highlight = True )
491+
492+ geo_json = [x for x in self .map ._children .values () if
493+ isinstance (x , GeoJson )][0 ]
494+
495+ out = '' .join (self .map ._parent .render ().split ())
496+
497+ # Verify the geo_json object
498+ obj_temp = jinja2 .Template ("""
499+ var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
500+ .addTo({{ this._parent.get_name() }});
501+ {{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
502+ """ )
503+ obj = obj_temp .render (this = geo_json , json = json )
504+ rendered_obj = '' .join (obj .split ())[:- 1 ]
505+
506+ assert '' .join (obj .split ())[:- 1 ] in out
507+
508+ bounds = self .map .get_bounds ()
509+ assert bounds == [[18.948267 , - 171.742517 ],
510+ [71.285909 , - 66.979601 ]], bounds
511+
474512 def test_geo_json_highlight (self ):
475513 # Highlight data binding
476514 self .map = folium .Map ([43 , - 100 ], zoom_start = 4 )
0 commit comments