First of all, thank you so much Emil for your dedication regarding Dash-Leaflet and your responsiveness here in the Forum!
I have two issues that might be related somehow to rendering, though I do not think they are directly linked.
- One is the exact same one as user inisamuel posted some time ago (Link). Shapes drawn via EditControl get lost when switching Tabs back and forth. Is there a way to maintain the shapes? (I repost the MWE here.)
import dash
from dash import Dash, dcc, html
import dash_leaflet as dl
app = Dash(__name__)
app.layout = html.Div([
dcc.Tabs(id="tabs", children=[
dcc.Tab(value="a", label="a", children=[]),
dcc.Tab(value="b", label="b", children=[
dl.Map(center=[56, 10], children=[
dl.TileLayer(), dl.FeatureGroup([
dl.EditControl(id="edit_control")]),
], style={'width': '50%', 'height': '50vh'}, id="map"),
])
])
])
if __name__ == '__main__':
app.run_server(debug=True)
- The other one is related to GeoJSON filtering via hideout property PLUS clustering. The MWE is the Interactivity example from the website with two small modifications. The property
cluster=True
ist added to dl.GeoJSON()
, and the javascript function is altered, so that also clusters are shown. One can see that the clusters do not update when removing markers via the Dropdown menu. Is there a way to re-render the cluster markers after filtering the desired properties?
import dash_leaflet as dl
import dash_leaflet.express as dlx
from dash import Dash, html, dcc, Output, Input
from dash_extensions.javascript import assign
# A few cities in Denmark.
cities = [dict(name="Aalborg", lat=57.0268172, lon=9.837735),
dict(name="Aarhus", lat=56.1780842, lon=10.1119354),
dict(name="Copenhagen", lat=55.6712474, lon=12.5237848)]
# Create drop down options.
dd_options = [dict(value=c["name"], label=c["name"]) for c in cities]
dd_defaults = [o["value"] for o in dd_options]
# Generate geojson with a marker for each city and name as tooltip.
geojson = dlx.dicts_to_geojson([{**c, **dict(tooltip=c['name'])} for c in cities])
# Create javascript function that filters on feature name.
geojson_filter = assign("function(feature, context){return context.props.hideout.includes(feature.properties.name) || feature.properties.cluster;}")
# Create example app.
app = Dash()
app.layout = html.Div([
dl.Map(children=[
dl.TileLayer(),
dl.GeoJSON(data=geojson, options=dict(filter=geojson_filter), hideout=dd_defaults, id="geojson", zoomToBounds=True, cluster=True)
], style={'width': '100%', 'height': '50vh', 'margin': "auto", "display": "block"}, id="map"),
dcc.Dropdown(id="dd", value=dd_defaults, options=dd_options, clearable=False, multi=True)
])
# Link drop down to geojson hideout prop (could be done with a normal callback, but clientside is more performant).
app.clientside_callback("function(x){return x;}", Output("geojson", "hideout"), Input("dd", "value"))
if __name__ == '__main__':
app.run_server()
Again, many thanks!