1

I'm trying to create a Folium map where the top layer is a boundary plot (fill_opacity: 0) of coarser structure to the Choropleth on the bottom level. I'd like the coarser level with no highlight functionally to show on top while the finer lower level to be shown on the bottom but it's highlight functionality to still permeate through and still work with the top layer not switched off with layer control. Is this posible?

My map:

m1 = folium.Map([54.5,-3],zoom_start=6.8,min_zoom=6,tiles='cartodbpositron',control_scale=True)

My top layer:

#makes boundaries plot
Boundaries = folium.GeoJson(
    cluster_stab_df,
    style_function = lambda x: {
        'color': 'black',
        'weight': 4,
        "opacity":1,
        'fillOpacity': 0,
    }).add_to(m1)

My bottom layer:

#sets style of Choropleth
style_function = lambda x: {"weight":0.4,
                            "color":'black',
                            "opacity":1,
                            "fillColor":colormap(x['properties']['gi']), 
                            'fillOpacity':0.65}

#sets style of highlight                            
highlight_function = lambda x: {'fillColor': '#000000', 
                                'color':'#000000', 
                                'fillOpacity': 0.50}



#makes Choropleth map
Choropleth = folium.features.GeoJson(
    MSOA_stab_df,
    style_function=style_function,
    highlight_function=highlight_function, 
    tooltip=folium.features.GeoJsonTooltip(
        fields=['msoa11nm','label','numneigh','gi'],
        aliases=['MSOA Name','Cluster Label','Number of Neighbors','Common Neighbors Proportion'],
        localize = True,
        style=("background-color: white; color: #333333; font-family: arial; font-size: 12px; padding: 10px;") 
    )).add_to(m1)
1

To do this you need to make the top layer non-interactive as follows:

#makes boundaries plot
Boundaries = folium.GeoJson(
    cluster_stab_df,
    style_function = lambda x: {
        'color': 'black',
        'weight': 4,
        "opacity":1,
        'fillOpacity': 0,
        'interactive':False
    }).add_to(m1)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.