Skip to content

Plugin to handle overlapping markers #901

@psychemedia

Description

@psychemedia
import folium

loc=[50.65795773762609, -1.2263860950441539]

m=folium.Map(location=loc, zoom_start=12)
for i in range(5):
    folium.Marker(loc, popup='{}'.format( i )).add_to(m)
m

When plotting markers geocoded from things like UK postcodes, it's quite common to get collisions when placing markers (multiple markers at the same location).

The markercluster approach will separate out markers that are colocated, but the overall effect can be quite unsatisfactory because the clustering algorithm tries to cluster things all over the place.

One solution is to perturb markers randomly. For example:

import numpy as np

m=folium.Map(location=loc, zoom_start=12)
for i in range(5):
    loc[0]=loc[0]+np.random.uniform(0.001, 10**(-20))-0.00005
    loc[1]=loc[1]+np.random.uniform(0.001, 10**(-20))-0.00005
    folium.Marker(loc, popup='{}'.format( i )).add_to(m)
m

What would be really useful would be a plugin to separate out colocated markers. jawj/OverlappingMarkerSpiderfier-Leaflet looks like it might be a useful candidate?

Expected Output

Separate out colocated markers but not cluster markers AND separate out colocated ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature request or idea about how to make folium bettergood first issueNew contributors are welcome to pick up this issuepluginThis issue/PR is about an existing or new plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions