Skip to content

Commit f9e01e0

Browse files
committed
use locations endpoint
1 parent 4efcb3a commit f9e01e0

3 files changed

Lines changed: 107 additions & 104 deletions

File tree

polarrouteserver/frontend/__init__.py

Lines changed: 91 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -36,106 +36,100 @@
3636

3737
ns = Namespace("polarRoute", "mapFunctions")
3838

39-
favourites = {
40-
"bird": {"lat": -54.025, "lon": -38.044, "display_name": "Bird Island"},
41-
"falklands": {"lat": -51.731, "lon": -57.706, "display_name": "Falklands"},
42-
"halley": {"lat": -75.059, "lon": -25.840, "display_name": "Halley"},
43-
"rothera": {"lat": -67.764, "lon": -68.02, "display_name": "Rothera"},
44-
"kep": {"lat": -54.220, "lon": -36.433, "display_name": "King Edward Point"},
45-
"signy": {"lat": -60.720, "lon": -45.480, "display_name": "Signy"},
46-
"nyalesund": {"lat": 78.929, "lon": 11.928, "display_name": "Ny-Ålesund"},
47-
"harwich": {"lat": 51.949, "lon": 1.255, "display_name": "Harwich, UK"},
48-
"rosyth": {"lat": 56.017, "lon": -3.440, "display_name": "Rosyth, UK"},
49-
}
50-
51-
5239
eventHandlers = dict(
5340
mousemove=ns("mousemove"),
5441
click=ns("click"),
5542
)
5643

5744

58-
app.layout = html.Div(
59-
children=[
60-
dcc.Store(id="routes-store", data=[], storage_type="memory"),
61-
dcc.Store(id="route-visibility-store", data=[], storage_type="memory"),
62-
dcc.Store(id="marker-store", storage_type="memory", data={}),
63-
dcc.Interval(id="recent-routes-interval", interval=10000),
64-
html.Header(header),
65-
site_development_notice,
66-
dl.Map(
67-
[
68-
dl.TileLayer(
69-
id="basemap",
70-
attribution=("© OpenStreetMap contributors"),
71-
zIndex=0,
72-
),
73-
dl.FullScreenControl(),
74-
dl.LayersControl(
75-
[
76-
dl.Overlay(
77-
amsr_layer(default_sic_date),
78-
name="AMSR",
79-
checked=False,
80-
id="amsr-overlay",
81-
),
82-
],
83-
id="layers-control",
84-
),
85-
dl.FeatureGroup(id="routes-fg"),
86-
dl.FeatureGroup(id="marker-fg", children=[]),
87-
],
88-
center=[-60, -67],
89-
zoom=3,
90-
style={"height": "50vh", "cursor": "crosshair"},
91-
id="map",
92-
eventHandlers=eventHandlers,
93-
),
94-
html.Span(" ", id="mouse-coords-container"),
95-
dcc.Slider(
96-
min=-30,
97-
max=0,
98-
step=1,
99-
value=0,
100-
id="amsr-date-slider",
101-
marks=None,
102-
tooltip={"placement": "top", "always_visible": False},
103-
),
104-
html.Span("", id="test-output-container"),
105-
dbc.Row(
106-
[
107-
dbc.Col(
108-
[
109-
dbc.Row(
110-
[
111-
dbc.Col(html.H2("Recent Routes"), width=4),
112-
dbc.Col(
113-
dbc.Button(
114-
html.I(className="bi bi-arrow-clockwise me-2"),
115-
id="refresh-routes-button",
116-
class_name="bsk-btn bsk-btn-primary",
117-
)
118-
),
119-
],
120-
justify="start",
121-
),
122-
dcc.Loading([html.Div(id="recent-routes-table")]),
123-
html.Div(id="recent-routes-tooltips"),
124-
],
125-
class_name="col-12 col-md-6",
126-
),
127-
dbc.Col(
128-
[
129-
html.H2("Request Route"),
130-
html.Span(
131-
"Select start and end points from dropdown or by clicking on map."
132-
),
133-
html.Div(route_request_form(favourites), id="route-request"),
134-
],
135-
class_name="col-12 col-md-6",
136-
),
137-
]
138-
),
139-
html.Footer(footer),
140-
],
141-
)
45+
def serve_layout():
46+
return html.Div(
47+
children=[
48+
dcc.Store(id="routes-store", data=[], storage_type="memory"),
49+
dcc.Store(id="route-visibility-store", data=[], storage_type="memory"),
50+
dcc.Store(id="marker-store", storage_type="memory", data={}),
51+
dcc.Interval(id="recent-routes-interval", interval=10000),
52+
# dcc.Interval(id="route-request-form-interval", interval=1, n_intervals=0, max_intervals=1),
53+
html.Header(header),
54+
site_development_notice,
55+
dl.Map(
56+
[
57+
dl.TileLayer(
58+
id="basemap",
59+
attribution=("© OpenStreetMap contributors"),
60+
zIndex=0,
61+
),
62+
dl.FullScreenControl(),
63+
dl.LayersControl(
64+
[
65+
dl.Overlay(
66+
amsr_layer(default_sic_date),
67+
name="AMSR",
68+
checked=False,
69+
id="amsr-overlay",
70+
),
71+
],
72+
id="layers-control",
73+
),
74+
dl.FeatureGroup(id="routes-fg"),
75+
dl.FeatureGroup(id="marker-fg", children=[]),
76+
],
77+
center=[-60, -67],
78+
zoom=3,
79+
style={"height": "50vh", "cursor": "crosshair"},
80+
id="map",
81+
eventHandlers=eventHandlers,
82+
),
83+
html.Span(" ", id="mouse-coords-container"),
84+
dcc.Slider(
85+
min=-30,
86+
max=0,
87+
step=1,
88+
value=0,
89+
id="amsr-date-slider",
90+
marks=None,
91+
tooltip={"placement": "top", "always_visible": False},
92+
),
93+
html.Span("", id="test-output-container"),
94+
dbc.Row(
95+
[
96+
dbc.Col(
97+
[
98+
dbc.Row(
99+
[
100+
dbc.Col(html.H2("Recent Routes"), width=4),
101+
dbc.Col(
102+
dbc.Button(
103+
html.I(
104+
className="bi bi-arrow-clockwise me-2"
105+
),
106+
id="refresh-routes-button",
107+
class_name="bsk-btn bsk-btn-primary",
108+
)
109+
),
110+
],
111+
justify="start",
112+
),
113+
dcc.Loading([html.Div(id="recent-routes-table")]),
114+
html.Div(id="recent-routes-tooltips"),
115+
],
116+
class_name="col-12 col-md-6",
117+
),
118+
dbc.Col(
119+
[
120+
html.H2("Request Route"),
121+
html.Span(
122+
"Select start and end points from dropdown or by clicking on map."
123+
),
124+
html.Div(route_request_form(), id="route-request"),
125+
],
126+
class_name="col-12 col-md-6",
127+
),
128+
]
129+
),
130+
html.Footer(footer),
131+
],
132+
)
133+
134+
135+
app.layout = serve_layout

polarrouteserver/frontend/layouts.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import json
2-
31
import dash_bootstrap_components as dbc
42
from dash_extensions.enrich import html
53

4+
from .utils import get_favourites
5+
66

77
def coords_input(loc, favourites):
88
return html.Div(
@@ -11,10 +11,7 @@ def coords_input(loc, favourites):
1111
[
1212
dbc.InputGroupText(loc),
1313
dbc.Select(
14-
options=[
15-
{"label": v["display_name"], "value": json.dumps(v)}
16-
for v in favourites.values()
17-
],
14+
options=[{"label": f["name"], "value": f} for f in favourites],
1815
id={"type": "location-select", "index": loc},
1916
class_name="bsk-form-control",
2017
),
@@ -36,7 +33,10 @@ def coords_input(loc, favourites):
3633
)
3734

3835

39-
def route_request_form(favourites):
36+
def route_request_form(favourites: list[dict] = None):
37+
if not favourites:
38+
favourites = get_favourites()
39+
4040
return dbc.Form(
4141
[
4242
coords_input("start", favourites),

polarrouteserver/frontend/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import json
23
import os
34

45
import requests
@@ -47,6 +48,14 @@ def get_route_geojson(route: dict):
4748
return route["json"][0][0]
4849

4950

51+
def get_favourites() -> requests.Response:
52+
response = requests.get(
53+
url=server_url() + "/api/locations",
54+
)
55+
56+
return json.loads(response.text)
57+
58+
5059
def _summarise_route(route):
5160
keys_to_extract = [
5261
"id",

0 commit comments

Comments
 (0)