-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
90 lines (80 loc) · 2.91 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<head>
<style>
body {
margin: 0;
}
</style>
<script src="//unpkg.com/react/umd/react.production.min.js"></script>
<script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
<script src="//unpkg.com/@babel/standalone"></script>
<script src="//unpkg.com/react-globe.gl"></script>
<script src="CoordinateDto.js"></script>
<!--<script src="../../dist/react-globe.gl.js"></script>-->
</head>
<body>
<div id="globeViz"></div>
<script type="text/jsx">
// Utility function to generate a random color
const getRandomColor = () => {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
};
const { useState, useEffect } = React;
const World = ({ traceResponseData }) => {
const [vesselPaths, setVesselPaths] = useState([]);
useEffect(() => {
if (traceResponseData && traceResponseData.length > 0) {
let vesselPaths = [];
traceResponseData.forEach((featureCollection) => {
featureCollection.features.forEach(({ geometry, properties }) => {
geometry.coordinates.forEach((coords) => {
const randomColor = getRandomColor();
vesselPaths.push({ coords, vessel: { properties, color: randomColor } });
});
});
});
setVesselPaths(vesselPaths);
console.log('Vessel trace data processed:', vesselPaths);
} else {
console.error('Invalid or missing features array in trace data:', traceResponseData);
}
}, [traceResponseData]);
return (
<Globe
globeImageUrl="//unpkg.com/three-globe/example/img/earth-dark.jpg"
bumpImageUrl="//unpkg.com/three-globe/example/img/earth-topology.png"
backgroundImageUrl="//unpkg.com/three-globe/example/img/night-sky.png"
pathsData={vesselPaths}
pathPoints="coords"
pathPointLat={(p) => p[1]}
pathPointLng={(p) => p[0]}
pathColor={(path) => path.vessel.color}
pathLabel={path => path.vessel.properties.vessel.imo + "\n" + path.vessel.properties.vessel.name}
pathDashLength={0.1}
pathDashGap={0.008}
pathDashAnimateTime={12000}
/>
);
};
const filePath = 'server/vessel_trace_data.json';
fetch(filePath)
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((traceResponseData) => {
console.log('Trace Response Data:', traceResponseData);
ReactDOM.render(
<World traceResponseData={traceResponseData} />,
document.getElementById('globeViz')
);
})
.catch((error) => console.error('Error loading trace data:', error));
</script>
</body>