Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +64 -57
src/streamlit_app.py
CHANGED
|
@@ -2,82 +2,89 @@ 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 |
<!DOCTYPE html>
|
| 9 |
<html lang="en">
|
| 10 |
-
|
| 11 |
-
<meta charset="utf-8"
|
| 12 |
-
<
|
| 13 |
-
<
|
|
|
|
| 14 |
<style>
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
</style>
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
terrainProvider: Cesium.createWorldTerrain()
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
|
|
|
| 42 |
destination: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048, 15000)
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
position: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048),
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
}
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
const
|
| 59 |
-
if (Cesium.defined(
|
| 60 |
-
|
| 61 |
-
|
| 62 |
}
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
if (
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
</html>
|
| 81 |
"""
|
| 82 |
|
| 83 |
-
components.html(
|
|
|
|
| 2 |
import streamlit.components.v1 as components
|
| 3 |
|
| 4 |
st.set_page_config(layout="wide")
|
| 5 |
+
st.title("π Streamlit with CesiumJS β Draggable Marker + Coordinates")
|
| 6 |
|
| 7 |
+
html_code = """
|
| 8 |
<!DOCTYPE html>
|
| 9 |
<html lang="en">
|
| 10 |
+
<head>
|
| 11 |
+
<meta charset="utf-8">
|
| 12 |
+
<title>CesiumJS Draggable Marker</title>
|
| 13 |
+
<script src="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Cesium.js"></script>
|
| 14 |
+
<link href="https://cesium.com/downloads/cesiumjs/releases/1.104/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
|
| 15 |
<style>
|
| 16 |
+
html, body, #cesiumContainer {
|
| 17 |
+
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
|
| 18 |
+
}
|
| 19 |
+
.coordinates {
|
| 20 |
+
position: absolute;
|
| 21 |
+
bottom: 10px;
|
| 22 |
+
left: 10px;
|
| 23 |
+
background: rgba(42, 42, 42, 0.8);
|
| 24 |
+
padding: 5px;
|
| 25 |
+
color: #fff;
|
| 26 |
+
font-family: sans-serif;
|
| 27 |
+
z-index: 1;
|
| 28 |
+
}
|
| 29 |
</style>
|
| 30 |
+
</head>
|
| 31 |
+
<body>
|
| 32 |
+
<div id="cesiumContainer"></div>
|
| 33 |
+
<div class="coordinates" id="coords">π§ Drag the marker to see coordinates.</div>
|
| 34 |
+
<script>
|
| 35 |
+
// Set Cesium Ion Access Token
|
| 36 |
+
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0M2VmOTcyMi0wZDIyLTRjMjktOTNlNi0zNjg2MmQyNTFjYTQiLCJpZCI6Mjk3Njk1LCJpYXQiOjE3NDU3NzgyMzh9.0FuHB-PidaNCTRT1sdcp20ufMJ5Z8DEEArhr47BOo4A';
|
| 37 |
|
| 38 |
+
const viewer = new Cesium.Viewer('cesiumContainer', {
|
| 39 |
terrainProvider: Cesium.createWorldTerrain()
|
| 40 |
+
});
|
| 41 |
|
| 42 |
+
// Center on Dubai
|
| 43 |
+
viewer.camera.flyTo({
|
| 44 |
destination: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048, 15000)
|
| 45 |
+
});
|
| 46 |
|
| 47 |
+
// Add a draggable marker
|
| 48 |
+
const marker = viewer.entities.add({
|
| 49 |
position: Cesium.Cartesian3.fromDegrees(55.2708, 25.2048),
|
| 50 |
+
billboard: {
|
| 51 |
+
image: 'https://cdn-icons-png.flaticon.com/512/684/684908.png',
|
| 52 |
+
width: 32,
|
| 53 |
+
height: 32
|
| 54 |
}
|
| 55 |
+
});
|
| 56 |
|
| 57 |
+
let isDragging = false;
|
| 58 |
+
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
| 59 |
|
| 60 |
+
handler.setInputAction(function(click) {
|
| 61 |
+
const pickedObject = viewer.scene.pick(click.position);
|
| 62 |
+
if (Cesium.defined(pickedObject) && pickedObject.id === marker) {
|
| 63 |
+
isDragging = true;
|
| 64 |
+
viewer.scene.screenSpaceCameraController.enableRotate = false;
|
| 65 |
}
|
| 66 |
+
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
| 67 |
|
| 68 |
+
handler.setInputAction(function(movement) {
|
| 69 |
+
if (isDragging) {
|
| 70 |
+
const cartesian = viewer.camera.pickEllipsoid(movement.endPosition, viewer.scene.globe.ellipsoid);
|
| 71 |
+
if (cartesian) {
|
| 72 |
+
marker.position = cartesian;
|
| 73 |
+
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
| 74 |
+
const longitude = Cesium.Math.toDegrees(cartographic.longitude).toFixed(5);
|
| 75 |
+
const latitude = Cesium.Math.toDegrees(cartographic.latitude).toFixed(5);
|
| 76 |
+
document.getElementById('coords').innerText = `π Longitude: ${longitude}, Latitude: ${latitude}`;
|
| 77 |
+
}
|
| 78 |
}
|
| 79 |
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
| 80 |
|
| 81 |
+
handler.setInputAction(function() {
|
| 82 |
+
isDragging = false;
|
| 83 |
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
| 84 |
+
}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
| 85 |
+
</script>
|
| 86 |
+
</body>
|
| 87 |
</html>
|
| 88 |
"""
|
| 89 |
|
| 90 |
+
components.html(html_code, height=700)
|