Search code examples
pythongisfolium

Passing Transparency Style to GeoJSON in Folium


Trying to make a transparent GeoJson (I only want the tooltips to appear over a choropleth) but I can't figure out how to pass transparent hex values to the GeoJson writer.

Trying the following:

style_function = {'fillColor': '#00FFFFFF',
                 'lineColor': '#00FFFFFF'}

folium.GeoJson(combined,
               tooltip=folium.GeoJsonTooltip(fields=['LGA','MBRS'],
                                             aliases=['Location','Members']),
               style_function=style_function).add_to(m)

folium.LayerControl().add_to(m)

Which returns:

TypeError: 'dict' object is not callable

The documentation example advises to pass a dict as part of a function but I want the transparency to apply to all of the GeoJson.

Please help!


Solution

  • Change code above to:

    style = {'fillColor': '#00000000', 'color': '#00000000'}
    
    folium.GeoJson(combined,
                   tooltip=folium.GeoJsonTooltip(fields=['LGA','MBRS'],
                                                 aliases=['Location','Members']),
                   style_function=lambda x: style).add_to(m)