Set map dimentions for folium_static

Hi,

I am running streamlit 1.7.0 and I have issues setting the dimensions of the folium map using the stramlit_folium library.

I have tried to set width= and height= in folium.Map but that seems to change the map proportions underneath while the actual frame in the app doesn’t change size.

I have also set st.set_page_config(layout=“wide”) but that didn’t change the size of the map.

#empty map
world_map= folium.Map(location=[mid_y, mid_x], width=1500, height=800, zoom_start=16, tiles="OpenStreetMap")
marker_cluster = MarkerCluster().add_to(world_map)
#for each coordinate
for i in range(len(filtered_data_street)):
    lat = filtered_data_street.iloc[i]['latitude']
    long = filtered_data_street.iloc[i]['longitude']
    popup_text = """Crime : {}<br>
                    Month : {}<br>"""
    popup_text = popup_text.format(filtered_data_street.iloc[i]['Crime type'],
                                   filtered_data_street.iloc[i]['Month']
                                   )
    if filtered_data_street.iloc[i]['Crime type'] == 'Violence and sexual offences':
        color = c_violence
        print(color)
        folium.CircleMarker(location=[lat, long], radius=10, popup=popup_text, fill=True, color='red').add_to(
            marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Anti-social behaviour':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='orange').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Criminal damage and arson':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='yellow').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Other theft':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='grey').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Vehicle crime':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='blue').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Burglary':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='violet').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Public order':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='pink').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Shoplifting':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='brown').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Other crime':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='turquoise').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Theft from the person':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='gold').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Drugs':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='white').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Robbery':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='black').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Bicycle theft':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='green').add_to(marker_cluster)
    elif filtered_data_street.iloc[i]['Crime type'] == 'Possession of weapons':
        color = c_violence
        print(color)
        folium.CircleMarker(location = [lat, long], radius=10, popup= popup_text, fill =True, color='indigo').add_to(marker_cluster)
#show the map
folium_static(world_map)

The size of the map will not deviate from the width of the narrow mode appearance.

Have you had any luck resolving this issue? I’m also have trouble getting the dimensions of the map to change.

Any luck?

In your last line, change:

folium_static(world_map, width=1500, height=800)

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.