Folium marker dimension

Viewed 201

I would like to resize the marker of folium on a map

Here the snipped I'm using

for i in range(0,len(destinations)):
   folium.Marker(
      location=[destinations.iloc[i][' Lat dest'], destinations.iloc[i][' Lon dest']],
#        radius=1, weight=1, border_width=10
#       icon = folium.Icon(color='blue', icon_size=(10,10),
   ).add_to(m)

m

the picture I refere is: enter image description here

Is there a way to rescale the marker size so that all becomes more visible? thank you

1 Answers

Since you can set your own icons, we used the official example as a basis and extracted only some of the lines to be graphed. The official example is a marker using folium.Geojson(). Tooltips and popups are set up. See this for details.

UPDATE:

Updated the code and graphs, as the first example in the official reference is what we are looking for. In this case, the style references a column in the data frame to set the color and size of the marker.

import os
import folium
import geopandas as gpd

rootpath = os.path.abspath(os.getcwd())
gdf = gpd.read_file(os.path.join(rootpath, "data", "subway_stations.geojson"))
gdf = gdf[gdf['line'].str.contains('Express')]
gdfs = gdf.copy()
gdfs['objectid'] = gdfs['objectid'].astype(int) 
gdfs.sort_values(['line', 'objectid'], ascending=[True, False], inplace=True)

gdfs['href'] = '<a href="' + gdfs.url + '">' + gdfs.url + "</a>"
gdfs['service_level'] = gdfs.notes.str.split(', ').apply(lambda x: len([v for v in x if "all" in v]))
gdfs['lines_served'] = gdfs.line.str.split('-').apply(lambda x: len(x))

colors = ["orange", "yellow", "green", "blue"]
service_levels = gdfs.service_level.unique().tolist()

m = folium.Map(location=[40.75, -73.95], zoom_start=12)

folium.GeoJson(
    gdfs,
    name="Subway Stations",
    marker=folium.Circle(radius=4, fill_color="orange", fill_opacity=0.4, color="black", weight=1),
    tooltip=folium.GeoJsonTooltip(fields=["name", "line", "notes"]),
    popup=folium.GeoJsonPopup(fields=["name", "line", "url", "notes"]),
    style_function=lambda x: {
        "fillColor": colors[x['properties']['service_level']],
        "radius": (x['properties']['lines_served'])*30,
    },
    highlight_function=lambda x: {"fillOpacity": 0.8},
    zoom_on_click=True,
).add_to(m)

enter image description here

Related