This is how I have filter working and cluster.
I have a dmc.Select within along with a dmc.TextInput for type to search.
I’m using a custom geojson script for the pointToLayer which can allow you to change the markers on zoom to whatever you’d like and the clusterToLayer prop allows you to change the cluster bubble design but basically within my dl.Map I have:
dl.GeoJSON(
data=geojson_dict,
id="locations_layer",
cluster=True,
zoomToBoundsOnClick=True,
superClusterOptions=dict(radius=40),
hideout=dict(
m_type_colors=m_type_colors,
circleOptions=dict(fillOpacity=0.5, stroke=False, radius=3),
min=0,
),
pointToLayer=point_to_layer_js,
clusterToLayer=cluster_to_layer,
)
Most of the magic happens within the callback for filtering a package that I use that would be helpful would be geopandas
which can help you translate a dataframe into a geopandas that will work in the filter process for example my callback looks like:
@callback(
Output("quick-filter-simple", "dashGridOptions"),
Output("locations_layer", "data", allow_duplicate=True),
Output("quick-filter-simple", "rowData", allow_duplicate=True),
Input("quick-filter-input", "value"),
Input("location_type", "value"),
Input('autocomplete_r_map', 'value'),
prevent_initial_call=True,
)
def update_filter_and_locations_layer(filter_value, location_type, city):
# Filter by city
if city == "Everything":
rowData = everything_df
else:
rowData = everything_df[everything_df['city'] == city]
# Filter by location type
if location_type != "everything":
rowData = rowData[rowData['type'] == location_type]
# Filter by name
if filter_value:
rowData = rowData[rowData['name'].str.contains(f'{filter_value}', case=False, na=False)]
# Convert the filtered DataFrame to GeoJSON
gdf = gpd.GeoDataFrame(
rowData, geometry=gpd.points_from_xy(rowData.lon, rowData.lat))
geojson = gdf.to_json()
geojson_dict = json.loads(geojson)
# Update the quick filter
newFilter = Patch()
newFilter["quickFilterText"] = filter_value
return newFilter, geojson_dict, rowData.to_dict("records")
Hope this gives some clues to help you figure out a working example for your data and use case.