WaysAheadGlobal commited on
Commit
08c6b8e
Β·
verified Β·
1 Parent(s): a45ca4a

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Load Excel data
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("🌍 CesiumJS Map – Drag Footfall Points (Dubai)")
 
 
 
 
 
10
 
11
- # Generate Cesium entities for footfall
12
- marker_js = ""
13
  for i, row in df.iterrows():
14
- lat = row["latitude"]
15
- lon = row["longitude"]
16
- name = str(row["name"]).replace("'", "")
17
- marker_js += f"""
18
- const marker{i} = viewer.entities.add({{
19
- name: "{name}",
20
- position: Cesium.Cartesian3.fromDegrees({lon}, {lat}),
21
- billboard: {{
22
- image: 'https://cdn-icons-png.flaticon.com/512/854/854878.png',
23
- width: 30,
24
- height: 30
25
- }}
26
- }});
27
 
28
- draggableEntities.push(marker{i});
29
- """
 
 
30
 
31
- # Full HTML with JS logic
 
 
32
  html_code = f"""
33
  <!DOCTYPE html>
34
  <html lang="en">
35
  <head>
36
  <meta charset="utf-8">
37
- <title>CesiumJS Footfall Drag Demo</title>
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 = 'YOUR_CESIUM_TOKEN_HERE';
61
 
62
  const viewer = new Cesium.Viewer('cesiumContainer', {{
63
  terrainProvider: Cesium.createWorldTerrain()
64
  }});
65
 
66
- viewer.camera.flyTo({{
67
- destination: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048, 15000)
68
- }});
69
 
70
- const draggableEntities = [];
71
- {marker_js}
72
-
73
- const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
74
- let draggingEntity = null;
75
-
76
- handler.setInputAction(function(click) {{
77
- const picked = viewer.scene.pick(click.position);
78
- if (Cesium.defined(picked) && draggableEntities.includes(picked.id)) {{
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
- }}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
96
 
97
- handler.setInputAction(function() {{
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)