Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -180,8 +180,11 @@ app_ui = ui.page_fluid(
|
|
| 180 |
ui.panel_sidebar(
|
| 181 |
ui.div(
|
| 182 |
ui.input_slider("zoom", "Map zoom level", value=12, min=1, max=18),
|
| 183 |
-
ui.
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
| 185 |
),
|
| 186 |
),
|
| 187 |
ui.panel_main(
|
|
@@ -292,6 +295,19 @@ def server(input, output, session):
|
|
| 292 |
|
| 293 |
# Initialize and display when the session starts (1)
|
| 294 |
map = L.Map(center=(current_gps['location']['lat'], current_gps['location']['lng']), zoom=12, scroll_wheel_zoom=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
map.add_layer(L.TileLayer(url='https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}', name='Natural Map'))
|
| 296 |
|
| 297 |
# Add a distance scale
|
|
@@ -339,20 +355,43 @@ def server(input, output, session):
|
|
| 339 |
def _():
|
| 340 |
ui.update_slider("zoom", value=reactive_read(map, "zoom"))
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
# Everytime the map's bounds change, update the output message (3)
|
| 343 |
# rerun when a user do some reactive changes.
|
| 344 |
-
@
|
| 345 |
-
|
| 346 |
-
async def map_bounds():
|
| 347 |
center = reactive_read(map, "center")
|
| 348 |
if len(center) == 0:
|
| 349 |
-
return
|
| 350 |
-
|
| 351 |
-
lat = round(center[0], 4)
|
| 352 |
lon = (center[1] + 180) % 360 - 180
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
return ui.p(f"Longitude: {lon}", ui.br(), f"Latitude: {lat}")
|
| 356 |
|
| 357 |
def update_or_create_heatmaps(output_datasets, scale):
|
| 358 |
"""
|
|
|
|
| 180 |
ui.panel_sidebar(
|
| 181 |
ui.div(
|
| 182 |
ui.input_slider("zoom", "Map zoom level", value=12, min=1, max=18),
|
| 183 |
+
ui.div(
|
| 184 |
+
ui.input_numeric("lat", "Latitude", value=38.53667742),
|
| 185 |
+
ui.input_numeric("long", "Longitude", value=-121.75387309),
|
| 186 |
+
),
|
| 187 |
+
style=css(display="flex", justify_content="center", align_items="center", gap="1rem"),
|
| 188 |
),
|
| 189 |
),
|
| 190 |
ui.panel_main(
|
|
|
|
| 295 |
|
| 296 |
# Initialize and display when the session starts (1)
|
| 297 |
map = L.Map(center=(current_gps['location']['lat'], current_gps['location']['lng']), zoom=12, scroll_wheel_zoom=True)
|
| 298 |
+
|
| 299 |
+
@reactive.isolate()
|
| 300 |
+
def update_text_inputs(lat: Optional[float], long: Optional[float]) -> None:
|
| 301 |
+
req(lat is not None, long is not None)
|
| 302 |
+
lat = round(lat, 8)
|
| 303 |
+
long = round(long, 8)
|
| 304 |
+
if lat != input.lat():
|
| 305 |
+
input.lat.freeze()
|
| 306 |
+
ui.update_text("lat", value=lat)
|
| 307 |
+
if long != input.long():
|
| 308 |
+
input.long.freeze()
|
| 309 |
+
ui.update_text("long", value=long)
|
| 310 |
+
|
| 311 |
map.add_layer(L.TileLayer(url='https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}', name='Natural Map'))
|
| 312 |
|
| 313 |
# Add a distance scale
|
|
|
|
| 355 |
def _():
|
| 356 |
ui.update_slider("zoom", value=reactive_read(map, "zoom"))
|
| 357 |
|
| 358 |
+
@reactive.Effect
|
| 359 |
+
def location():
|
| 360 |
+
"""Returns tuple of (lat,long) floats--or throws silent error if no lat/long is
|
| 361 |
+
selected"""
|
| 362 |
+
# Require lat/long to be populated before we can proceed
|
| 363 |
+
req(input.lat() is not None, input.long() is not None)
|
| 364 |
+
|
| 365 |
+
try:
|
| 366 |
+
long = input.long()
|
| 367 |
+
# Wrap longitudes so they're within [-180, 180]
|
| 368 |
+
long = (long + 180) % 360 - 180
|
| 369 |
+
if round(map.center[0], 8) == input.lat() and round(map.center[1], 8) == long:
|
| 370 |
+
return
|
| 371 |
+
map.center = (input.lat(), long)
|
| 372 |
+
|
| 373 |
+
except ValueError as e:
|
| 374 |
+
error_modal = ui.modal(
|
| 375 |
+
str(e),
|
| 376 |
+
title="Invalid latitude/longitude specification. Please refresh",
|
| 377 |
+
easy_close=True,
|
| 378 |
+
size="xl",
|
| 379 |
+
footer=None,
|
| 380 |
+
fade=True
|
| 381 |
+
)
|
| 382 |
+
# print_with_line_number("Show error modal")
|
| 383 |
+
ui.modal_show(error_modal)
|
| 384 |
+
traceback.print_exc()
|
| 385 |
+
|
| 386 |
# Everytime the map's bounds change, update the output message (3)
|
| 387 |
# rerun when a user do some reactive changes.
|
| 388 |
+
@reactive.Effect
|
| 389 |
+
def map_bounds():
|
|
|
|
| 390 |
center = reactive_read(map, "center")
|
| 391 |
if len(center) == 0:
|
| 392 |
+
return
|
|
|
|
|
|
|
| 393 |
lon = (center[1] + 180) % 360 - 180
|
| 394 |
+
update_text_inputs(center[0], lon)
|
|
|
|
|
|
|
| 395 |
|
| 396 |
def update_or_create_heatmaps(output_datasets, scale):
|
| 397 |
"""
|