Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +39 -68
src/streamlit_app.py
CHANGED
|
@@ -1,107 +1,78 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import streamlit.components.v1 as components
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
df = pd.read_excel("data/jj_with_footfall.xlsx") # Update path if needed
|
| 7 |
-
|
| 8 |
st.set_page_config(layout="wide")
|
| 9 |
-
st.title("π
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
for i, row in df.iterrows():
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
billboard: {{
|
| 22 |
-
image: 'https://cdn-icons-png.flaticon.com/512/854/854878.png',
|
| 23 |
-
width: 30,
|
| 24 |
-
height: 30
|
| 25 |
-
}}
|
| 26 |
-
}});
|
| 27 |
|
| 28 |
-
|
| 29 |
-
"""
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
html_code = f"""
|
| 33 |
<!DOCTYPE html>
|
| 34 |
<html lang="en">
|
| 35 |
<head>
|
| 36 |
<meta charset="utf-8">
|
| 37 |
-
<title>CesiumJS
|
| 38 |
<script src="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Cesium.js"></script>
|
| 39 |
<link href="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
|
| 40 |
<style>
|
| 41 |
html, body, #cesiumContainer {{
|
| 42 |
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
|
| 43 |
}}
|
| 44 |
-
.coordinates {{
|
| 45 |
-
position: absolute;
|
| 46 |
-
bottom: 10px;
|
| 47 |
-
left: 10px;
|
| 48 |
-
background: rgba(0, 0, 0, 0.75);
|
| 49 |
-
color: #fff;
|
| 50 |
-
padding: 6px 12px;
|
| 51 |
-
font-family: sans-serif;
|
| 52 |
-
z-index: 1;
|
| 53 |
-
}}
|
| 54 |
</style>
|
| 55 |
</head>
|
| 56 |
<body>
|
| 57 |
<div id="cesiumContainer"></div>
|
| 58 |
-
<div class="coordinates" id="coords">π§ Drag any marker to get coordinates.</div>
|
| 59 |
<script>
|
| 60 |
-
Cesium.Ion.defaultAccessToken = '
|
| 61 |
|
| 62 |
const viewer = new Cesium.Viewer('cesiumContainer', {{
|
| 63 |
terrainProvider: Cesium.createWorldTerrain()
|
| 64 |
}});
|
| 65 |
|
| 66 |
-
|
| 67 |
-
destination: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048, 15000)
|
| 68 |
-
}});
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
draggingEntity = picked.id;
|
| 80 |
-
viewer.scene.screenSpaceCameraController.enableRotate = false;
|
| 81 |
-
}}
|
| 82 |
-
}}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
| 83 |
-
|
| 84 |
-
handler.setInputAction(function(movement) {{
|
| 85 |
-
if (draggingEntity) {{
|
| 86 |
-
const cartesian = viewer.camera.pickEllipsoid(movement.endPosition);
|
| 87 |
-
if (cartesian) {{
|
| 88 |
-
draggingEntity.position = cartesian;
|
| 89 |
-
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
| 90 |
-
const lon = Cesium.Math.toDegrees(cartographic.longitude).toFixed(5);
|
| 91 |
-
const lat = Cesium.Math.toDegrees(cartographic.latitude).toFixed(5);
|
| 92 |
-
document.getElementById("coords").innerText = `π Moved: Lon: ${{lon}}, Lat: ${{lat}}`;
|
| 93 |
}}
|
| 94 |
-
}}
|
| 95 |
-
}}
|
| 96 |
|
| 97 |
-
|
| 98 |
-
draggingEntity = null;
|
| 99 |
-
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
| 100 |
-
}}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
| 101 |
</script>
|
| 102 |
</body>
|
| 103 |
</html>
|
| 104 |
"""
|
| 105 |
|
| 106 |
-
# Render the Cesium map
|
| 107 |
components.html(html_code, height=700)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
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("π Dubai Footfall Visualizer β CesiumJS Draggable Map")
|
| 9 |
+
|
| 10 |
+
# Load data
|
| 11 |
+
st.info("π¦ Loading footfall data...")
|
| 12 |
+
df = pd.read_excel("data/jj_with_footfall.xlsx")
|
| 13 |
+
df = df.dropna(subset=["longitude", "latitude"])
|
| 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 |
+
geojson = {
|
| 27 |
+
"type": "FeatureCollection",
|
| 28 |
+
"features": features
|
| 29 |
+
}
|
| 30 |
|
| 31 |
+
geojson_str = json.dumps(geojson)
|
| 32 |
+
|
| 33 |
+
# Cesium HTML
|
| 34 |
html_code = f"""
|
| 35 |
<!DOCTYPE html>
|
| 36 |
<html lang="en">
|
| 37 |
<head>
|
| 38 |
<meta charset="utf-8">
|
| 39 |
+
<title>CesiumJS Dynamic Points</title>
|
| 40 |
<script src="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Cesium.js"></script>
|
| 41 |
<link href="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
|
| 42 |
<style>
|
| 43 |
html, body, #cesiumContainer {{
|
| 44 |
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
|
| 45 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
</style>
|
| 47 |
</head>
|
| 48 |
<body>
|
| 49 |
<div id="cesiumContainer"></div>
|
|
|
|
| 50 |
<script>
|
| 51 |
+
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0M2VmOTcyMi0wZDIyLTRjMjktOTNlNi0zNjg2MmQyNTFjYTQiLCJpZCI6Mjk3Njk1LCJpYXQiOjE3NDU3NzgyMzh9.0FuHB-PidaNCTRT1sdcp20ufMJ5Z8DEEArhr47BOo4A';
|
| 52 |
|
| 53 |
const viewer = new Cesium.Viewer('cesiumContainer', {{
|
| 54 |
terrainProvider: Cesium.createWorldTerrain()
|
| 55 |
}});
|
| 56 |
|
| 57 |
+
const data = {geojson_str};
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
data.features.forEach((feature, index) => {{
|
| 60 |
+
const coords = feature.geometry.coordinates;
|
| 61 |
+
viewer.entities.add({{
|
| 62 |
+
id: 'point_' + index,
|
| 63 |
+
position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1]),
|
| 64 |
+
billboard: {{
|
| 65 |
+
image: 'https://cdn-icons-png.flaticon.com/512/684/684908.png',
|
| 66 |
+
width: 32,
|
| 67 |
+
height: 32
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}}
|
| 69 |
+
}});
|
| 70 |
+
}});
|
| 71 |
|
| 72 |
+
viewer.zoomTo(viewer.entities);
|
|
|
|
|
|
|
|
|
|
| 73 |
</script>
|
| 74 |
</body>
|
| 75 |
</html>
|
| 76 |
"""
|
| 77 |
|
|
|
|
| 78 |
components.html(html_code, height=700)
|