Folium: Transparent GeoJson

Created on 20 Nov 2018  路  5Comments  路  Source: python-visualization/folium

Trying to create a transparent GeoJson, i only want to see the tooltips over a choropleth.

Trying the below, but getting nowhere.

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)

Can you tell me how to make the GeoJson layer transparent?

Thanks.

Jack.

Most helpful comment

Thanks a lot for getting back to me, both options worked!

Just for anybody finding this in future: replace the dict from my code with:

{'fillColor': '#00000000', 'color': '#00000000'}

All 5 comments

Hey @jackemcpherson, the issue is that your style function is a dictionary instead of a function returning a dictionary.

Rewrite it like this:

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

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

or:

def style_function():
    return {'fillColor': '#00FFFFFF', 'lineColor': '#00FFFFFF'}

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

and that should be good. Hope this helps!

Thanks a lot for getting back to me, both options worked!

Just for anybody finding this in future: replace the dict from my code with:

{'fillColor': '#00000000', 'color': '#00000000'}

@jtbaker maybe assert style_function is callable, raise a meaningful error otherwise? What do you think, user-friendly or overkill?

@Conengmo good thinking! I like it. I've PR'd a fix in #1024.

I came across a similar problem like yours. Try to set the 'fillOpacity' property in your style function. Because according to the original Leaflet documentation, the default value is 0.2. I hope it helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alcampopiano picture Alcampopiano  路  14Comments

nathan3leaf picture nathan3leaf  路  32Comments

agravier picture agravier  路  26Comments

ElmWer picture ElmWer  路  24Comments

Demetrio92 picture Demetrio92  路  18Comments