Skip to content

50 marker cluster

image image image

Creating a marker cluster with custom icons

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap
1
import leafmap

Create an interactive map.

1
m = leafmap.Map(center=[40, -100], zoom=4)

Use sample datasets.

1
2
cities = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/us_cities.csv"
regions = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/us_regions.geojson"

Add a GeoJSON to the map.

1
m.add_geojson(regions, layer_name="US Regions")

Add a marker cluster to the map. The input can either be a string (representing file path or HTTP URL to a csv file) or a Pandas DataFrame.

The list of available icon names can be found at https://fontawesome.com/v4/icons.

Please note that the spin parameter only supports the ipyleaflet backend. The folium backend does not support this.

1
2
3
4
5
6
7
8
9
m.add_points_from_xy(
    cities,
    x="longitude",
    y="latitude",
    color_column="region",
    icon_names=["gear", "map", "leaf", "globe"],
    spin=True,
    add_legend=True,
)

Display the map.

1
m