Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +64 -47
src/streamlit_app.py
CHANGED
|
@@ -3,73 +3,90 @@ import streamlit.components.v1 as components
|
|
| 3 |
import pandas as pd
|
| 4 |
import json
|
| 5 |
|
| 6 |
-
# Set up Streamlit page
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
-
st.title("
|
| 9 |
|
| 10 |
-
# Load data
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# Convert to GeoJSON
|
| 16 |
-
features = []
|
| 17 |
-
for i, row in df.iterrows():
|
| 18 |
-
features.append({
|
| 19 |
"type": "Feature",
|
| 20 |
"geometry": {
|
| 21 |
"type": "Point",
|
| 22 |
-
"coordinates": [row["longitude"], row["latitude"]]
|
| 23 |
-
}
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"type": "FeatureCollection",
|
| 28 |
-
"features": features
|
| 29 |
-
}
|
| 30 |
|
| 31 |
-
geojson_str = json.dumps(
|
| 32 |
|
| 33 |
-
# Cesium HTML
|
| 34 |
html_code = f"""
|
| 35 |
<!DOCTYPE html>
|
| 36 |
<html lang="en">
|
| 37 |
<head>
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
</head>
|
| 48 |
<body>
|
| 49 |
<div id="cesiumContainer"></div>
|
| 50 |
<script>
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
}});
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
</script>
|
| 74 |
</body>
|
| 75 |
</html>
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import json
|
| 5 |
|
|
|
|
| 6 |
st.set_page_config(layout="wide")
|
| 7 |
+
st.title("Drag n Drop")
|
| 8 |
|
| 9 |
+
# Load footfall data
|
| 10 |
+
df = pd.read_excel("data/jj_with_footfall.xlsx").dropna(subset=["latitude", "longitude"])
|
| 11 |
+
features = [
|
| 12 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"type": "Feature",
|
| 14 |
"geometry": {
|
| 15 |
"type": "Point",
|
| 16 |
+
"coordinates": [row["longitude"], row["latitude"]],
|
| 17 |
+
},
|
| 18 |
+
}
|
| 19 |
+
for _, row in df.iterrows()
|
| 20 |
+
]
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
geojson_str = json.dumps({"type": "FeatureCollection", "features": features})
|
| 23 |
|
|
|
|
| 24 |
html_code = f"""
|
| 25 |
<!DOCTYPE html>
|
| 26 |
<html lang="en">
|
| 27 |
<head>
|
| 28 |
+
<meta charset="utf-8">
|
| 29 |
+
<title>Cesium Draggable Footfall</title>
|
| 30 |
+
<script src="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Cesium.js"></script>
|
| 31 |
+
<link href="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
|
| 32 |
+
<style>
|
| 33 |
+
html, body, #cesiumContainer {{
|
| 34 |
+
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
|
| 35 |
+
}}
|
| 36 |
+
</style>
|
| 37 |
</head>
|
| 38 |
<body>
|
| 39 |
<div id="cesiumContainer"></div>
|
| 40 |
<script>
|
| 41 |
+
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0M2VmOTcyMi0wZDIyLTRjMjktOTNlNi0zNjg2MmQyNTFjYTQiLCJpZCI6Mjk3Njk1LCJpYXQiOjE3NDU3NzgyMzh9.0FuHB-PidaNCTRT1sdcp20ufMJ5Z8DEEArhr47BOo4A';
|
| 42 |
+
const viewer = new Cesium.Viewer('cesiumContainer', {{
|
| 43 |
+
terrainProvider: Cesium.createWorldTerrain(),
|
| 44 |
+
selectionIndicator: false
|
| 45 |
+
}});
|
| 46 |
+
|
| 47 |
+
const data = {geojson_str};
|
| 48 |
+
const markers = [];
|
| 49 |
+
let pickedEntity = null;
|
| 50 |
+
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
| 51 |
|
| 52 |
+
data.features.forEach((feature, i) => {{
|
| 53 |
+
const [lon, lat] = feature.geometry.coordinates;
|
| 54 |
+
const entity = viewer.entities.add({{
|
| 55 |
+
id: `point_${i}`,
|
| 56 |
+
position: Cesium.Cartesian3.fromDegrees(lon, lat),
|
| 57 |
+
billboard: {{
|
| 58 |
+
image: 'https://cdn-icons-png.flaticon.com/512/684/684908.png',
|
| 59 |
+
width: 24,
|
| 60 |
+
height: 24
|
| 61 |
+
}}
|
| 62 |
}});
|
| 63 |
+
markers.push(entity);
|
| 64 |
+
}});
|
| 65 |
|
| 66 |
+
viewer.zoomTo(viewer.entities);
|
| 67 |
|
| 68 |
+
// Drag logic
|
| 69 |
+
handler.setInputAction((click) => {{
|
| 70 |
+
const picked = viewer.scene.pick(click.position);
|
| 71 |
+
if (Cesium.defined(picked) && picked.id) {{
|
| 72 |
+
pickedEntity = picked.id;
|
| 73 |
+
viewer.scene.screenSpaceCameraController.enableRotate = false;
|
| 74 |
+
}}
|
| 75 |
+
}}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
| 76 |
+
|
| 77 |
+
handler.setInputAction((movement) => {{
|
| 78 |
+
if (pickedEntity) {{
|
| 79 |
+
const cartesian = viewer.camera.pickEllipsoid(movement.endPosition, viewer.scene.globe.ellipsoid);
|
| 80 |
+
if (cartesian) {{
|
| 81 |
+
pickedEntity.position = cartesian;
|
| 82 |
+
}}
|
| 83 |
+
}}
|
| 84 |
+
}}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
| 85 |
|
| 86 |
+
handler.setInputAction(() => {{
|
| 87 |
+
pickedEntity = null;
|
| 88 |
+
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
| 89 |
+
}}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
| 90 |
</script>
|
| 91 |
</body>
|
| 92 |
</html>
|