WaysAheadGlobal commited on
Commit
2b31433
·
verified ·
1 Parent(s): 08c6b8e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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("🌍 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>
 
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>