Skip to content

Instantly share code, notes, and snippets.

@prl900
Created May 26, 2022 04:33
Show Gist options
  • Save prl900/c7fbcb375a1c3170325ea27b17262ff1 to your computer and use it in GitHub Desktop.
Save prl900/c7fbcb375a1c3170325ea27b17262ff1 to your computer and use it in GitHub Desktop.
import dash
import dash_leaflet as dl
from dash import Dash, html, Output, Input
import dash_bootstrap_components as dbc
from dash.exceptions import PreventUpdate
purple_dot = {"iconUrl": 'https://storage.googleapis.com/terrakio_webapps/purple_dot.png', "iconSize": [40, 40]}
red_triangle = {"iconUrl": 'https://storage.googleapis.com/terrakio_webapps/red_triangle.png', "iconSize": [40, 40]}
hires_url = "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = dbc.Container(
[
dbc.Row([
dbc.Col([
dl.Map(center=[-28.34, 148.42], zoom=13, children=[
dl.TileLayer(url=hires_url),
dl.FeatureGroup([
dl.EditControl(id="edit_control", draw=dict(circle=False, circlemarker=False, rectangle=False, polyline=False, polygon=False)),
dl.Marker(position=[-28.34, 148.42], icon=purple_dot),
dl.Marker(position=[-28.33, 148.411], icon=red_triangle),
]),
], style={'width': '1000px', 'height': '500px'}),
] , md=8),
dbc.Col([
dbc.RadioItems(
id="radios",
className="btn-group",
inputClassName="btn-check",
labelClassName="btn btn-outline-primary",
labelCheckedClassName="active",
options=[
{"label": "Dot", "value": 1},
{"label": "Triangle", "value": 2},
],
value=1),
] , md=4),
]),
dbc.Row([
dbc.Col(html.Div(id="json"), md=4),
], align="center",),
],
fluid=True,
)
@app.callback(
Output("json", "children"),
Input("edit_control", "geojson"))
def mirror(x):
if not x:
raise PreventUpdate
return str(x)
if __name__ == "__main__":
app.run_server(port=8081, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment