Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining GeoJson markers in a MarkerCluster shows unclustered markers #1209

Closed
diegoquintanav opened this issue Sep 27, 2019 · 7 comments · Fixed by #1353
Closed

Combining GeoJson markers in a MarkerCluster shows unclustered markers #1209

diegoquintanav opened this issue Sep 27, 2019 · 7 comments · Fixed by #1353
Labels
bug An issue describing unexpected or malicious behaviour

Comments

@diegoquintanav
Copy link

Please add a code sample or a nbviewer link, copy-pastable if possible

with open('examples/data/search_bars_rome.json') as f:
    data = json.load(f)
data_url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/search_bars_rome.json'

m = folium.Map((41.9, 12.5), tiles='cartodbpositron')
marker_cluster = folium.plugins.MarkerCluster(name='mc').add_to(m)
folium.GeoJson(data_url, embed=False).add_to(marker_cluster)
folium.GeoJson(data_url, embed=False, name='geojson').add_to(m)
folium.LayerControl(collapsed=False).add_to(m)
m.save('_map.html')
m

Problem description

I expected to see the markers in a clustered fashion

image

I can't tell from #1190, #1129 and #1188 if this is fixed in version 0.10.0, and if it is, what's the right syntax?

Expected Output

Clustered markers (This was taken from another example)

image

Output of folium.__version__

'0.10.0'

@diegoquintanav diegoquintanav changed the title Combining GeoJson with MarkerCluster Combining GeoJson markers in a MarkerCluster shows unclustered markers Sep 27, 2019
@fullonic
Copy link
Contributor

Hi @diegoquintanav, I think that #1190 fixed the problem you mention, and it was done after the release of version 10. Therefore, would be better install folium directly from github give it a try again.

@fullonic
Copy link
Contributor

fullonic commented Oct 24, 2019

Confirmed! It works with folium installed directly from github.
I had time to run your script and here is a screenshot of the html file.

Screenshot_2019-10-24 Screenshot

@vjsequi
Copy link

vjsequi commented Jun 12, 2020

I am having the same issues I'm afraid. It doesn't render the MarkerCluster at all.

image

image

image

image

Thanks for your help!

@Conengmo
Copy link
Member

It seems #1190 (merged July 2019) and #1289 (merged April 2020) are at odds with each other. We have to resolve the conflicting requirements. Some ideas:

  • make the ajax call synchronous and add to parent when it finished
  • move the embedded data to the GeoJson() call and accept that not al functionality will work when not embedding data.

@Conengmo Conengmo added the bug An issue describing unexpected or malicious behaviour label Jun 13, 2020
@vjsequi
Copy link

vjsequi commented Jun 13, 2020

I think I've found a way round it. If you make the GeoJson a subgroup of the MarkerCluster it seems to work. Although weirdly you need to untick and tick GeoJson layer (Housing) for it show anything.

with open('examples/data/search_bars_rome.json') as f:
    data = json.load(f)
data_url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/search_bars_rome.json'

m = folium.Map((41.9, 12.5), tiles='cartodbpositron')
marker_cluster = folium.plugins.MarkerCluster(name='Developments')
mc1= folium.plugins.FeatureGroupSubGroup(marker_cluster, 'Housing')
m.add_child(marker_cluster)
m.add_child(Housing)
mc1.add_child(folium.GeoJson(data_url, embed=False))
folium.LayerControl(collapsed=False).add_to(m)
m

image

My next query is, how can I show labels, either tooltips or popups? Substituting mc1 with the code below doesn't seem to work.

mc1.add_child(folium.GeoJson(data_url, tooltip=folium.GeoJsonTooltip(fields=['addr:street']), embed=False))

@Conengmo
Copy link
Member

It seems combining GeoJsonTooltip and MarkerCluster plugin is not supported behavior. Note that while everything in the base folium library should work well together we can't guarantee that for the plugins.

I don't think using the FeatureGroupSubGroup plugin is a real solution here. I'll make a PR where we do the ajax call asynchronously.

@Conengmo Conengmo added the work in progress Work is in progress on a PR, check the PR to see its status label Jun 13, 2020
@Conengmo Conengmo removed the work in progress Work is in progress on a PR, check the PR to see its status label Jun 18, 2020
@Conengmo
Copy link
Member

The fix has been merged. It will be in the next release, v0.12.0, release date yet unknown. If you want it earlier you can install folium from the main branch:

pip install git+https://github.com/python-visualization/folium.git@master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing unexpected or malicious behaviour
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants