2222 ClickForMarker , TopoJson , PolyLine , MultiPolyLine ,
2323 )
2424
25-
2625def initialize_notebook ():
2726 """Initialize the IPython notebook display elements."""
2827 warnings .warn ("%s is deprecated and no longer required." %
2928 ("initialize_notebook" ,),
3029 FutureWarning , stacklevel = 2 )
3130 pass
3231
33-
3432class Map (LegacyMap ):
3533 """Create a Map with Folium and Leaflet.js
3634
@@ -510,7 +508,8 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json',
510508 data = None , columns = None , key_on = None , threshold_scale = None ,
511509 fill_color = 'blue' , fill_opacity = 0.6 , line_color = 'black' ,
512510 line_weight = 1 , line_opacity = 1 , legend_name = "" ,
513- topojson = None , reset = False , smooth_factor = None ):
511+ topojson = None , reset = False , smooth_factor = None ,
512+ highlight = None ):
514513 """
515514 Apply a GeoJSON overlay to the map.
516515
@@ -582,6 +581,8 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json',
582581 How much to simplify the polyline on each zoom level. More means
583582 better performance and smoother look, and less means more accurate
584583 representation. Leaflet defaults to 1.0.
584+ highlight: boolean, default False
585+ Enable highlight functionality when hovering over a GeoJSON area.
585586
586587 Returns
587588 -------
@@ -598,6 +599,12 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json',
598599 ... threshold_scale=[0, 20, 30, 40, 50, 60])
599600 >>> m.choropleth(geo_path='countries.json',
600601 ... topojson='objects.countries')
602+ >>> m.choropleth(geo_path='geo.json', data=df,
603+ ... columns=['Data 1', 'Data 2'],
604+ ... key_on='feature.properties.myvalue',
605+ ... fill_color='PuBu',
606+ ... threshold_scale=[0, 20, 30, 40, 50, 60],
607+ ... highlight=True)
601608
602609 """
603610 if threshold_scale and len (threshold_scale ) > 6 :
@@ -679,6 +686,13 @@ def style_function(x):
679686 "fillColor" : color_scale_fun (x )
680687 }
681688
689+
690+ def highlight_function (x ):
691+ return {
692+ "weight" : line_weight + 2 ,
693+ "fillOpacity" : fill_opacity + .2
694+ }
695+
682696 if topojson :
683697 geo_json = TopoJson (
684698 geo_data ,
@@ -689,7 +703,8 @@ def style_function(x):
689703 geo_json = GeoJson (
690704 geo_data ,
691705 style_function = style_function ,
692- smooth_factor = smooth_factor )
706+ smooth_factor = smooth_factor ,
707+ highlight_function = highlight_function if highlight else None )
693708
694709 self .add_child (geo_json )
695710
0 commit comments