Hi all,
I’ve a problem with a very simple app for changing the visibility of some tools of Dash Leaflet EditControl.
The callback is able to change the property “position” of the tool, but has no effect on the property ‘draw’, used for enable/disable draw controls.
For sure I made a mistake.
I’d appreciate your kindly help and thanks in advance.
Here is the code:
import dash_leaflet as dl
from dash import Dash, html, Output, Input
from dash.exceptions import PreventUpdate
from dash_extensions.javascript import assign
app = Dash(prevent_initial_callbacks=True)
# ------------------------------------------
# Layout
# ------------------------------------------
app.layout = html.Div([
dl.Map(center=[56, 10], zoom=4, children=[
dl.TileLayer(),
dl.FeatureGroup([
dl.EditControl(id="id-edit_control",
draw={
"circlemarker":False,
"circle": False,
"polygon": True,
"polyline": True,
"rectangle": False,
"marker": False,
},
),
dl.Marker(position=[56, 10])
]),
],
style={'width': '50%', 'height': '50vh', "display": "inline-block"}, id="map"),
html.Button("Change tools visibility", id="id-btn-change-tools"),
])
# ------------------------------------------
# Callback for changing the tools visibility
# ------------------------------------------
@app.callback(Output("id-edit_control", "draw"),
Output("id-edit_control", "position"),
Input("id-btn-change-tools", "n_clicks"))
def trigger_mode(n_clicks):
print ('change visibility')
draw={
"circlemarker":False,
"circle": False,
"polygon": False,
"polyline": False,
"rectangle": False,
"marker": False,
}
position = 'topleft'
return draw, position
# ------------------------------------------
# Main program
# ------------------------------------------
if __name__ == '__main__':
app.run(debug=False)