An error occurred while loading the file. Please try again.
STC.html 5.25 KiB
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Space-Time Cube Visualization</title>
  <!-- Include necessary libraries -->
  <script src="https://cdn.jsdelivr.net/npm/@arcgis/core@latest"></script>
  <script src="https://cdn.jsdelivr.net/npm/plotly.js-dist@latest"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.1.2/echarts.min.js"></script>
  <style>
    body {
      background-color: white; /* Set the background color to white */
    #plotlyContainer {
      height: 100vh;
      position: absolute;
      bottom: 0;
      left: 0;
      top: 6%;
      right: 100; /* Assuming you meant right: 100px */
      width: 100%;
      z-index: 3;
      #toggleSpaceTime {
      padding: 10px 20px;
      font-size: 16px;
  </style>
</head>
<body>
  <!-- Add your HTML content here -->
  <button id="toggleSpaceTime">Bus Space-Time Cube Visualization </button>
  <div id="spaceTimeCubeContainer" style="display: none;">
    <!-- Container for the space-time cube visualization -->
    <div id="spaceTimeCube"></div>
  </div>
  <!-- Container for Plotly visualization -->
  <div id="plotlyContainer"></div>
  <script>
    document.getElementById("toggleSpaceTime").addEventListener("click", function () {
      const spaceTimeContainer = document.getElementById("spaceTimeCubeContainer");
      console.log("Toggle button clicked");
      console.log("Current display style:", spaceTimeContainer.style.display);
      spaceTimeContainer.style.display = spaceTimeContainer.style.display === "none" ? "block" : "none";
      console.log("New display style:", spaceTimeContainer.style.display);
      // If the space-time container is set to block initialize/reload the space-time visualization
      if (spaceTimeContainer.style.display === "block") {
        console.log("Initializing space-time visualization...");
        animateSpaceTimeRoute('https://ogcapi.hft-stuttgart.de/ogc_api_moving_features/collections/bus_1/items', 'spaceTimeCube', 'black', 'Bus');
    });
    function animateSpaceTimeRoute(url) {
    fetch(url)
        .then(response => response.json())
        .then(data => {
            if (!data || !data.features) {
                console.error('Invalid data format:', data);
                return;
            const frames = data.features.map((feature, index) => {
const coordinates = feature.geometry.coordinates; const timestamps = feature.properties.datetimes; if (!Array.isArray(coordinates) || !Array.isArray(timestamps)) { console.error('Invalid feature format:', feature); return; } return { data: [{ type: 'scatter3d', x: coordinates.map(coord => coord[0]), y: coordinates.map(coord => coord[1]), z: timestamps.map((time, i) => new Date(time).toISOString()), mode: 'lines+markers', // Change mode to display both points and lines marker: {color: 'black',size: 5}, line: {color: 'red',size: 3 }, name: 'Bus trajectory line', }, ], name: `frame${index + 1}`, }; }); const layout = { margin: { t: 0, b: 0, l: 0, r: 0 }, paper_bgcolor: 'white', plot_bgcolor: 'white', scene: { xaxis: { title: 'Long', titlefont: { family: 'Arial, sans-serif', size: 15, color: 'black' }, tickfont: { family: 'Arial, sans-serif', size: 15, color: 'black', bold: true } }, yaxis: { title: 'Lat', titlefont: { family: 'Arial, sans-serif', size: 15, color: 'black' }, tickfont: { family: 'Arial, sans-serif', size: 15, color: 'black', bold: true } }, zaxis: { title: 'Time', titlefont: { family: 'Arial, sans-serif', size: 16, color: 'black'
}, tickfont: { family: 'Arial, sans-serif', size: 15, color: 'black', bold: true } }, font: { family: 'Arial, sans-serif', size: 12, color: 'black', bold: true } }, legend: { traceorder: 'normal' // Set traceorder to 'normal' to display legends } }; // Initialize Plotly container Plotly.newPlot('plotlyContainer', frames[0].data, layout); Plotly.addFrames('plotlyContainer', frames); }) .catch(error => { console.error('Error fetching data:', error); }); } </script> </body> </html>