An error occurred while loading the file. Please try again.
-
Traboulsi authored5b512652
<!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) => {
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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'
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
},
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>