folium icon indicating copy to clipboard operation
folium copied to clipboard

Plugin to handle overlapping markers

Open psychemedia opened this issue 7 years ago • 3 comments

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.

psychemedia avatar Jun 30 '18 00:06 psychemedia

Something like that can be added as a plugin to folium. I didn't check what Leaflet plugins exist for this, but your candidate seems fine. It would be nice if it integrates nicely with the existing Marker implementation.

Addition to folium are made by volunteers, so if you want to work on this you're welcome to do so. Just make a PR. You can look at the other plugins to see how stuff works in folium.

Conengmo avatar Jun 30 '18 11:06 Conengmo

Is this issue resolved? Would like to help contribute to the same if possible.

2Shabby avatar Aug 18 '21 12:08 2Shabby

Is this issue resolved?

eraduz avatar Dec 10 '22 13:12 eraduz