Spaces:
Sleeping
Sleeping
Added positioning feature #2
Browse files- app.py +2 -0
- apps/device_loc.py +43 -0
- apps/timelapse.py +34 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -4,6 +4,7 @@ from apps import (
|
|
4 |
basemaps,
|
5 |
census,
|
6 |
deck,
|
|
|
7 |
gee,
|
8 |
gee_datasets,
|
9 |
heatmap,
|
@@ -32,6 +33,7 @@ apps.add_app("Heatmaps", heatmap.app)
|
|
32 |
apps.add_app("Add Web Map Service (WMS)", wms.app)
|
33 |
apps.add_app("Google Earth Engine (GEE)", gee.app)
|
34 |
apps.add_app("Awesome GEE Community Datasets", gee_datasets.app)
|
|
|
35 |
|
36 |
# The main app
|
37 |
apps.run()
|
|
|
4 |
basemaps,
|
5 |
census,
|
6 |
deck,
|
7 |
+
device_loc,
|
8 |
gee,
|
9 |
gee_datasets,
|
10 |
heatmap,
|
|
|
33 |
apps.add_app("Add Web Map Service (WMS)", wms.app)
|
34 |
apps.add_app("Google Earth Engine (GEE)", gee.app)
|
35 |
apps.add_app("Awesome GEE Community Datasets", gee_datasets.app)
|
36 |
+
apps.add_app("Get Device Location", device_loc.app)
|
37 |
|
38 |
# The main app
|
39 |
apps.run()
|
apps/device_loc.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from bokeh.models.widgets import Button
|
3 |
+
from bokeh.models import CustomJS
|
4 |
+
from streamlit_bokeh_events import streamlit_bokeh_events
|
5 |
+
import leafmap.foliumap as leafmap
|
6 |
+
|
7 |
+
|
8 |
+
def app():
|
9 |
+
|
10 |
+
loc_button = Button(label="Get Device Location", max_width=150)
|
11 |
+
loc_button.js_on_event(
|
12 |
+
"button_click",
|
13 |
+
CustomJS(
|
14 |
+
code="""
|
15 |
+
navigator.geolocation.getCurrentPosition(
|
16 |
+
(loc) => {
|
17 |
+
document.dispatchEvent(new CustomEvent("GET_LOCATION", {detail: {lat: loc.coords.latitude, lon: loc.coords.longitude}}))
|
18 |
+
}
|
19 |
+
)
|
20 |
+
"""
|
21 |
+
),
|
22 |
+
)
|
23 |
+
result = streamlit_bokeh_events(
|
24 |
+
loc_button,
|
25 |
+
events="GET_LOCATION",
|
26 |
+
key="get_location",
|
27 |
+
refresh_on_update=False,
|
28 |
+
override_height=75,
|
29 |
+
debounce_time=0,
|
30 |
+
)
|
31 |
+
|
32 |
+
if result:
|
33 |
+
if "GET_LOCATION" in result:
|
34 |
+
loc = result.get("GET_LOCATION")
|
35 |
+
lat = loc.get("lat")
|
36 |
+
lon = loc.get("lon")
|
37 |
+
st.write(f"Lat, Lon: {lat}, {lon}")
|
38 |
+
|
39 |
+
m = leafmap.Map(center=(lat, lon), zoom=16)
|
40 |
+
m.add_basemap("ROADMAP")
|
41 |
+
popup = f"lat, lon: {lat}, {lon}"
|
42 |
+
m.add_marker(location=(lat, lon), popup=popup)
|
43 |
+
m.to_streamlit()
|
apps/timelapse.py
CHANGED
@@ -4,6 +4,9 @@ import datetime
|
|
4 |
import geopandas as gpd
|
5 |
import folium
|
6 |
import streamlit as st
|
|
|
|
|
|
|
7 |
import geemap.colormaps as cm
|
8 |
import geemap.foliumap as geemap
|
9 |
from datetime import date
|
@@ -61,6 +64,37 @@ def app():
|
|
61 |
|
62 |
with row1_col2:
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
keyword = st.text_input("Search for a location:", "")
|
65 |
if keyword:
|
66 |
locations = geemap.geocode(keyword)
|
|
|
4 |
import geopandas as gpd
|
5 |
import folium
|
6 |
import streamlit as st
|
7 |
+
from bokeh.models.widgets import Button
|
8 |
+
from bokeh.models import CustomJS
|
9 |
+
from streamlit_bokeh_events import streamlit_bokeh_events
|
10 |
import geemap.colormaps as cm
|
11 |
import geemap.foliumap as geemap
|
12 |
from datetime import date
|
|
|
64 |
|
65 |
with row1_col2:
|
66 |
|
67 |
+
loc_button = Button(label="Get Device Location", max_width=150)
|
68 |
+
loc_button.js_on_event(
|
69 |
+
"button_click",
|
70 |
+
CustomJS(
|
71 |
+
code="""
|
72 |
+
navigator.geolocation.getCurrentPosition(
|
73 |
+
(loc) => {
|
74 |
+
document.dispatchEvent(new CustomEvent("GET_LOCATION", {detail: {lat: loc.coords.latitude, lon: loc.coords.longitude}}))
|
75 |
+
}
|
76 |
+
)
|
77 |
+
"""
|
78 |
+
),
|
79 |
+
)
|
80 |
+
result = streamlit_bokeh_events(
|
81 |
+
loc_button,
|
82 |
+
events="GET_LOCATION",
|
83 |
+
key="get_location",
|
84 |
+
refresh_on_update=False,
|
85 |
+
override_height=75,
|
86 |
+
debounce_time=0,
|
87 |
+
)
|
88 |
+
|
89 |
+
if result:
|
90 |
+
if "GET_LOCATION" in result:
|
91 |
+
loc = result.get("GET_LOCATION")
|
92 |
+
lat = loc.get("lat")
|
93 |
+
lon = loc.get("lon")
|
94 |
+
popup = f"lat, lon: {lat}, {lon}"
|
95 |
+
m.add_marker(location=(lat, lon), popup=popup)
|
96 |
+
m.set_center(lon, lat, 16)
|
97 |
+
|
98 |
keyword = st.text_input("Search for a location:", "")
|
99 |
if keyword:
|
100 |
locations = geemap.geocode(keyword)
|
requirements.txt
CHANGED
@@ -3,5 +3,6 @@ keplergl
|
|
3 |
streamlit
|
4 |
streamlit-folium
|
5 |
streamlit-keplergl
|
|
|
6 |
git+git://github.com/giswqs/leafmap
|
7 |
git+git://github.com/giswqs/geemap
|
|
|
3 |
streamlit
|
4 |
streamlit-folium
|
5 |
streamlit-keplergl
|
6 |
+
streamlit-bokeh-events
|
7 |
git+git://github.com/giswqs/leafmap
|
8 |
git+git://github.com/giswqs/geemap
|