Skip to content

Combining GeoJson markers in a MarkerCluster shows unclustered markers #1209

Closed

Description

@diegoquintanav

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'

Activity

  1. changed the title [-]Combining `GeoJson` with `MarkerCluster`[/-] [+]Combining `GeoJson` markers in a `MarkerCluster` shows unclustered markers[/+] on Sep 27, 2019
  2. fullonic commented on Oct 22, 2019

    @fullonic
    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.

  3. fullonic commented on Oct 24, 2019

    @fullonic
    Contributor

    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

  4. vjsequi commented on Jun 12, 2020

    @vjsequi

    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!

  5. Conengmo commented on Jun 13, 2020

    @Conengmo
    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.
  6. added
    bug
    on Jun 13, 2020
  7. vjsequi commented on Jun 13, 2020

    @vjsequi

    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))
  8. Conengmo commented on Jun 13, 2020

    @Conengmo
    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.

  9. added
    work in progress
    on Jun 13, 2020
  10. removed
    work in progress
    on Jun 18, 2020
  11. Conengmo commented on Jun 18, 2020

    @Conengmo
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions