Giter Club home page Giter Club logo

Comments (3)

MoritzOff avatar MoritzOff commented on June 8, 2024

Did you already already find a solution for that?
I think I'm facing the same problem

from folium.

SCantergiani avatar SCantergiani commented on June 8, 2024

Did you already already find a solution for that? I think I'm facing the same problem

@MoritzOff

I found a workaround.

You must use folium.Choroplet and then access the underlying geojson and cmap. Here is the code I used, you can modify it with your own GeoJson dataframe:

mapita = folium.Map()

fg_lst = []

# Solamente nos interesan las columnas de data
for i, col in enumerate(regiones_data.columns):
    if col in ["CUT_REG", "REGION"]:
        continue
    choropleth = folium.Choropleth(
        geo_data=regiones,
        name=col,
        data=regiones_data,
        columns=["CUT_REG", col],  
        key_on="feature.properties.CUT_REG",
        fill_color="YlOrRd",
        fill_opacity=0.7,
        line_opacity=0.2,
        legend_name=col,
        highlight=True,
        line_color="white",
    )

    folium.GeoJsonTooltip(
        fields=["REGION_x", col],
        aliases=[field.title() for field in ["REGION_x", col]],
        style="background-color: white; color: #333333; font-family: arial; font-size: 12px; padding: 10px;",
        localize=True,
    ).add_to(choropleth.geojson)

    fg = folium.FeatureGroup(col)
    choropleth.geojson.add_to(fg)
    mapita.add_child(fg)
    mapita.add_child(choropleth.color_scale)
    mapita.add_child(BindColormap(fg, choropleth.color_scale))

    fg_lst.append(fg)

GroupedLayerControl(
    groups={"Groups": fg_lst},
    collapsed=False,
).add_to(mapita)

mapita

from folium.

Conengmo avatar Conengmo commented on June 8, 2024

I'm trying to replicate your issue, but not succeeding so far. Can you provide a minimal, standalone code snippet that reproduces your issue?

Here's what I tried what worked for me:

m = folium.Map()

for i in range(4):
    fg = folium.FeatureGroup(name=str(i)).add_to(m)
    folium.GeoJson(
        "https://raw.githubusercontent.com/python-visualization/folium-example-data/main/us_states.json",
        name=f"geojson {i}",
        highlight_function=lambda x: {
            "fillOpacity": i / 10,
        },
    ).add_to(fg)

folium.LayerControl(collapsed=False).add_to(m)

m.show_in_browser()

from folium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.