File size: 939 Bytes
60ee11d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from typing import List, Tuple, Optional, Union


def plot_route(points, vehicle: Union[tuple[float, float], None] = None):
    import plotly.express as px
    
    lats = []
    lons = []

    for point in points:
        lats.append(point["latitude"])
        lons.append(point["longitude"])
    # fig = px.line_geo(lat=lats, lon=lons)
    # fig.update_geos(fitbounds="locations")

    fig = px.line_mapbox(
        lat=lats, lon=lons, zoom=12, height=600, color_discrete_sequence=["red"]
    )

    if vehicle:
        fig.add_trace(
            px.scatter_mapbox(
                lat=[vehicle[0]],
                lon=[vehicle[1]],
                color_discrete_sequence=["blue"],
            ).data[0]
        )

    fig.update_layout(
        mapbox_style="open-street-map",
        # mapbox_zoom=12,
    )
    fig.update_geos(fitbounds="locations")
    fig.update_layout(margin={"r": 20, "t": 20, "l": 20, "b": 20})
    return fig