Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +60 -66
src/streamlit_app.py
CHANGED
|
@@ -2,88 +2,82 @@ import streamlit as st
|
|
| 2 |
import streamlit.components.v1 as components
|
| 3 |
|
| 4 |
st.set_page_config(layout="wide")
|
| 5 |
-
st.title("🌍
|
| 6 |
|
| 7 |
-
|
| 8 |
-
html_code = """
|
| 9 |
<!DOCTYPE html>
|
| 10 |
<html lang="en">
|
| 11 |
-
<head>
|
| 12 |
-
<meta charset="utf-8"
|
| 13 |
-
<
|
| 14 |
-
<
|
| 15 |
-
<link href="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
|
| 16 |
<style>
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
</style>
|
| 31 |
-
</head>
|
| 32 |
-
<body>
|
| 33 |
-
<div id="cesiumContainer"></div>
|
| 34 |
-
<div
|
| 35 |
-
<script>
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
terrainProvider: Cesium.createWorldTerrain()
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
position: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048),
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
height: 32
|
| 48 |
}
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
viewer.scene.screenSpaceCameraController.enableRotate = false;
|
| 61 |
}
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
| 71 |
-
const longitude = Cesium.Math.toDegrees(cartographic.longitude).toFixed(5);
|
| 72 |
-
const latitude = Cesium.Math.toDegrees(cartographic.latitude).toFixed(5);
|
| 73 |
-
document.getElementById('coords').innerText = `Longitude: ${longitude}, Latitude: ${latitude}`;
|
| 74 |
-
}
|
| 75 |
}
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
isDragging = false;
|
| 81 |
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
| 82 |
-
|
| 83 |
-
</script>
|
| 84 |
-
</body>
|
| 85 |
</html>
|
| 86 |
"""
|
| 87 |
|
| 88 |
-
|
| 89 |
-
components.html(html_code, height=700)
|
|
|
|
| 2 |
import streamlit.components.v1 as components
|
| 3 |
|
| 4 |
st.set_page_config(layout="wide")
|
| 5 |
+
st.title("🌍 Dubai 3D Cesium Map with Drag-and-Drop Marker (Ion Enabled)")
|
| 6 |
|
| 7 |
+
cesium_html = """
|
|
|
|
| 8 |
<!DOCTYPE html>
|
| 9 |
<html lang="en">
|
| 10 |
+
<head>
|
| 11 |
+
<meta charset="utf-8" />
|
| 12 |
+
<script src="https://cesium.com/downloads/cesiumjs/releases/1.112/Build/Cesium/Cesium.js"></script>
|
| 13 |
+
<link href="https://cesium.com/downloads/cesiumjs/releases/1.112/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
|
|
|
|
| 14 |
<style>
|
| 15 |
+
html, body, #cesiumContainer {
|
| 16 |
+
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
|
| 17 |
+
}
|
| 18 |
+
#dragTip {
|
| 19 |
+
position: absolute;
|
| 20 |
+
top: 10px;
|
| 21 |
+
left: 10px;
|
| 22 |
+
z-index: 100;
|
| 23 |
+
background: rgba(0,0,0,0.5);
|
| 24 |
+
color: white;
|
| 25 |
+
padding: 10px;
|
| 26 |
+
font-size: 14px;
|
| 27 |
+
}
|
| 28 |
</style>
|
| 29 |
+
</head>
|
| 30 |
+
<body>
|
| 31 |
+
<div id="cesiumContainer"></div>
|
| 32 |
+
<div id="dragTip">🖱️ Drag the red marker to reposition</div>
|
| 33 |
+
<script>
|
| 34 |
+
// Set Ion access token
|
| 35 |
+
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0M2VmOTcyMi0wZDIyLTRjMjktOTNlNi0zNjg2MmQyNTFjYTQiLCJpZCI6Mjk3Njk1LCJpYXQiOjE3NDU3NzgyMzh9.0FuHB-PidaNCTRT1sdcp20ufMJ5Z8DEEArhr47BOo4A';
|
| 36 |
+
|
| 37 |
+
const viewer = new Cesium.Viewer("cesiumContainer", {
|
| 38 |
terrainProvider: Cesium.createWorldTerrain()
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
viewer.camera.flyTo({
|
| 42 |
+
destination: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048, 15000)
|
| 43 |
+
});
|
| 44 |
|
| 45 |
+
const redPin = viewer.entities.add({
|
| 46 |
+
name: "Draggable Marker",
|
| 47 |
position: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048),
|
| 48 |
+
point: {
|
| 49 |
+
pixelSize: 15,
|
| 50 |
+
color: Cesium.Color.RED,
|
|
|
|
| 51 |
}
|
| 52 |
+
});
|
| 53 |
|
| 54 |
+
let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
| 55 |
+
let pickedEntity;
|
|
|
|
| 56 |
|
| 57 |
+
handler.setInputAction(function (click) {
|
| 58 |
+
const picked = viewer.scene.pick(click.position);
|
| 59 |
+
if (Cesium.defined(picked) && picked.id === redPin) {
|
| 60 |
+
pickedEntity = picked.id;
|
| 61 |
+
viewer.scene.screenSpaceCameraController.enableRotate = false;
|
|
|
|
| 62 |
}
|
| 63 |
+
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
| 64 |
|
| 65 |
+
handler.setInputAction(function (movement) {
|
| 66 |
+
if (pickedEntity) {
|
| 67 |
+
const cartesian = viewer.camera.pickEllipsoid(movement.endPosition);
|
| 68 |
+
if (cartesian) {
|
| 69 |
+
pickedEntity.position = cartesian;
|
| 70 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
| 73 |
|
| 74 |
+
handler.setInputAction(function () {
|
| 75 |
+
pickedEntity = null;
|
|
|
|
| 76 |
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
| 77 |
+
}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
| 78 |
+
</script>
|
| 79 |
+
</body>
|
| 80 |
</html>
|
| 81 |
"""
|
| 82 |
|
| 83 |
+
components.html(cesium_html, height=800)
|
|
|