Hey,
I’m new to Dash/Plotly and webcoding but I know coding in Python.
I’m trying to write to write an app that shows a map that you are able to draw in. This is the website I’ve come up with:
This is the code for it:
Blockquote import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import pandas as pd
import plotly
import chart_studio.plotly as py
import plotly.offline as py
import plotly.graph_objs as go
mapstyle = “mapbox://styles/anjulia/ck6212zuo0n7k1irz2cvd377i”
#set the geo=spatial data
data = [go.Scattermapbox(
lat= [‘57.72849’] ,
lon= [‘11.9745’],
#customdata = train[‘key’],
mode=‘markers’,
marker=dict(
size= 4,
color = ‘gold’,
opacity = .8,
),
)]
#set the layout to plot
layout = go.Layout(autosize=True,
mapbox= dict(accesstoken=“xxx”,
bearing=10,
pitch=60,
zoom=13,
center= dict(lat=57.671667,
lon=11.980833),
style=mapstyle),
#width=1800,
#height=1200,
title = “Karta över Göteborg”
)
fig = go.Figure(data=data, layout=layout)
navbar = dbc.NavbarSimple(
children=[
dbc.NavItem(dbc.NavLink(“Link”, href=“#”)),
dbc.DropdownMenu(
nav=True,
in_navbar=True,
label=“Menu”,
children=[
dbc.DropdownMenuItem(“Entry 1”),
dbc.DropdownMenuItem(“Entry 2”),
dbc.DropdownMenuItem(divider=True),
dbc.DropdownMenuItem(“Entry 3”),
],
),
],
brand=“Demo”,
brand_href=“#”,
sticky=“top”,
)
body = dbc.Container(
[
dbc.Row(
[
dbc.Col(
[
html.H2(“Heading”),
html.P(
“”"
Det här är en app för att se Göteborg inbäddat i en fin liten karta.“”"
),
dbc.Button(“View details”, color=“secondary”),
],
md=4,
),
dbc.Col(
[
html.H2(“Graph”),
dcc.Graph(
figure=fig
),
]
),
]
)
],
className=“mt-4”,
)
app = dash.Dash(name, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = html.Div([navbar, body])
if name == “main”:
app.run_server()
However, I want to be able to include a tool to make it able to draw a polygon and from there get the dimensions from it. I have found this Draw a polygon and calculate its area | Mapbox GL JS | Mapbox and I want it to work similar to that but it is in html. Can I implement this in my dash/python code somehow?