dash-leaflet icon indicating copy to clipboard operation
dash-leaflet copied to clipboard

No cluster when applying a filter

Open KeurKeur opened this issue 11 months ago • 1 comments

Hi,

It seems that when we add a filter to the GeoJSON with cluster set to True, there is neither the cluster or markers on the map... I think the cluster are there but just not visible....

Thanks !!

KeurKeur avatar Mar 06 '25 21:03 KeurKeur

I just happened to come across the same problem. Filter works, also the clustering but you are right the cluster markers are not drawn. Here is a small example:

import dash
import dash_leaflet as dl
import random
from dash import html
from dash_extensions.javascript import assign

def generate_geojson():
    features = []
    for i in range(100):
        lat = random.uniform(49.5, 49.8)
        lon = random.uniform(9.5, 10.5)
        et = random.uniform(0, 20)
        features.append({
            "type": "Feature",
            "geometry": {"type": "Point", "coordinates": [lon, lat]},
            "properties": {"id": i, "et": et}
        })
    return {"type": "FeatureCollection", "features": features}

GEOJSON_DATA = generate_geojson()

geojson_filter = assign("function(feature) { return feature.properties.et < 10; }")

app = dash.Dash(__name__)

app.layout = html.Div([
    dl.Map([
        dl.TileLayer(),
        dl.GeoJSON(
            id="geojson",
            data=GEOJSON_DATA,
            cluster=True, # Deactive cluster and the filter works
            superClusterOptions=dict(radius=100, maxZoom=12),
            filter=geojson_filter  # Clustering fails when this is active
        )
    ], style={"height": "500px"}, center=(48.5, 9), zoom=7)
])

if __name__ == "__main__":
    app.run_server(debug=True)

klingklangmatze avatar Mar 07 '25 09:03 klingklangmatze