Skip to content

Unable to cluster a geojson layer #1129

Closed

Description

@fullonic

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

Your code here

import folium
from folium.plugins import MarkerCluster

map = folium.Map()
geo_data = folium.GeoJson("filename.geojson")

# Create cluster layer
cluster = MarkerCluster()
cluster.add_child(geo_data)

# Add cluster to map
map.add_child(cluster)

map.save("cluster.html")

Problem description

The problem only happen when using folium installed from the master branch. Folium version 8.3 works as expected, all points are clustered. However, with the master version any point is displayed.

Expected Output

Map with clustered markers.

Output of folium.__version__

'0.8.3+41.g0e527a3.dirty'

Possible solution

After reading and comparing the GeoJson class from version 8.3 and master I saw that the possible problem is the new way of adding the data to the geojson layer.

Adding a couple of extra lines to the GeoJson template fixes the problem:

(...)
{% if this._parent.get_name()|truncate(14, True, "") == "marker_cluster" %}
    {{ this.get_name() }}.addTo({{ this._parent.get_name() }})
{% endif %}
{%-endmacro %}

I can't figure out other workaround, but this one works.

Activity

  1. Conengmo commented on Jul 29, 2019

    @Conengmo
    Member

    This has been fixed in #1190. Thanks for looking into this and collaborating on it @fullonic!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions