can anyone help in this code
Requirement is create one orbit around the earth which should be 360 degree vertically and then put one 3d satellite model which should revolve continuously around their.
after that when satellite is near to ground station or any latitude of longitude it should connect with ground station on particular point of time it with revolving satellite till 30 secs polyline should their after that remove it i tried this but not working can any one help me in that
<script type="text/javascript" src="{% static 'Cesium/Build/CesiumUnminified/Cesium.js' %}"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
@import url("{% static 'Cesium/Build/CesiumUnminified/Widgets/widgets.css' %}");
@import url("{% static 'Cesium/Apps/Sandcastle/templates/bucket.css' %}");
#cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script>
var viewer = new Cesium.Viewer('cesiumContainer', {
infoBox: true,
selectionIndicator: true,
shouldAnimate: true,
baseLayerPicker: true,
geocoder: true,
timeline: true,
});
var orbitPath = viewer.entities.add({
name: 'Orbit Path',
polyline: {
positions: createVerticalOrbitPositions(),
width: 1,
material: Cesium.Color.RED,
},
});
// Create a satellite entity with a 3D model
var satellite = viewer.entities.add({
name: 'Satellite',
position: new Cesium.ConstantPositionProperty(createVerticalOrbitPositions()[0]), // Initial position
model: {
uri: "{% static 'Cesium/Apps/SampleData/models/CesiumAir/satelite3.glb' %}",
minimumPixelSize: 2000,
maximumScale: 40000,
},
});
// Create a constant orientation property for the satellite
var satelliteOrientation = new Cesium.ConstantProperty(Cesium.Transforms.headingPitchRollQuaternion(
satellite.position.getValue(viewer.clock.currentTime), new Cesium.HeadingPitchRoll(0.0, 0.0, 0.0)));
// Set the satellite's orientation
satellite.orientation = satelliteOrientation;
var currentTime = Cesium.JulianDate.now();
viewer.clock.currentTime = currentTime;
// Decrease the multiplier to slow down the animation over time
var initialMultiplier = 60;
viewer.clock.multiplier = initialMultiplier;
viewer.clock.onTick.addEventListener(function(clock) {
var secondsElapsed = Cesium.JulianDate.secondsDifference(clock.currentTime, currentTime);
var numPoints = createVerticalOrbitPositions().length;
// Calculate the index based on time to move along the orbit path
var index = Math.floor((secondsElapsed % 60) / 60 * numPoints);
// Calculate the new multiplier to decrease speed over time
var newMultiplier = initialMultiplier / (60 + secondsElapsed / 60);
// Update the satellite's position based on the orbit path
satellite.position.setValue(createVerticalOrbitPositions()[index]);
// Update the viewer's clock multiplier to decrease speed
viewer.clock.multiplier = newMultiplier;
// Modify the satellite orientation if needed example: rotate north)
// adjust the HeadingPitchRoll values as per your requirement
var heading = 40.0; // Adjust the heading as desired
var pitch = Cesium.Math.toRadians(90.0); // Adjust the pitch as desired
var roll = 60.0; // Adjust the roll as desired
var newOrientation = Cesium.Transforms.headingPitchRollQuaternion(
satellite.position.getValue(clock.currentTime), new Cesium.HeadingPitchRoll(heading, pitch, roll));
// Update the satellite's orientation
satelliteOrientation.setValue(newOrientation);
});
//==========================================================================================
//
//var satelliteOrientation = new Cesium.ConstantProperty(Cesium.Transforms.headingPitchRollQuaternion(
// satellite.position.getValue(viewer.clock.currentTime), new Cesium.HeadingPitchRoll(0.0, 0.0, 0.0)));
//
//satellite.orientation = satelliteOrientation;
//
//var currentTime = Cesium.JulianDate.now();
//viewer.clock.currentTime = currentTime;
//
//var initialMultiplier = 60;
//viewer.clock.multiplier = initialMultiplier;
//
//var connectionPolyline; // Variable to hold the connection polyline
//
//viewer.clock.onTick.addEventListener(function(clock) {
// var secondsElapsed = Cesium.JulianDate.secondsDifference(clock.currentTime, currentTime);
// var numPoints = createVerticalOrbitPositions().length;
//
// var index = Math.floor((secondsElapsed % 60) / 60 * numPoints);
//
// var newMultiplier = initialMultiplier / (10 + secondsElapsed / 60);
//
// satellite.position.setValue(createVerticalOrbitPositions()[index]);
//
// viewer.clock.multiplier = newMultiplier;
//
// // Calculate the distance between the satellite and ground station
// var satellitePosition = satellite.position.getValue(clock.currentTime);
// var groundStationPosition = Cesium.Cartesian3.fromDegrees(79.131099, 21.577714, 0); // Ground station coordinates
// var distance = Cesium.Cartesian3.distance(satellitePosition, groundStationPosition);
//
// if (distance < 100000 && secondsElapsed < 30) { // Add the connection if satellite is near and time is less than 30 seconds
// if (!connectionPolyline) {
// connectionPolyline = viewer.entities.add({
// name: 'Connection',
// polyline: {
// positions: [satellitePosition, groundStationPosition],
// width: 2,
// material: Cesium.Color.YELLOW,
// },
// });
// } else {
// // Update the positions of the existing connection polyline
// connectionPolyline.polyline.positions = [satellitePosition, groundStationPosition];
// }
// } else if (connectionPolyline) {
// // Remove the connection if it exists and conditions are not met
// viewer.entities.remove(connectionPolyline);
// connectionPolyline = undefined;
// }
//
// var heading = 40.0; // Adjust the heading as desired
// var pitch = Cesium.Math.toRadians(90.0); // Adjust the pitch as desired
// var roll = 60.0; // Adjust the roll as desired
//
// var newOrientation = Cesium.Transforms.headingPitchRollQuaternion(
// satellite.position.getValue(clock.currentTime), new Cesium.HeadingPitchRoll(heading, pitch, roll));
//
// satelliteOrientation.setValue(newOrientation);
//});
//==============================================================================================================
// Define ground stations
var groundStations = [
{ name: 'Ground Station 1', longitude:27.335613 , latitude: 24.020175 },
];
// Create ground station entities from the array
for (var i = 0; i < groundStations.length; i++) {
var station = groundStations[i];
var groundStation = viewer.entities.add({
name: station.name,
position: Cesium.Cartesian3.fromDegrees(station.longitude, station.latitude, 0), // Set the ground station's position (longitude, latitude, altitude)
model: {
uri: "{% static 'Cesium/Apps/SampleData/models/CesiumAir/satellite_ground_station.glb' %}",
minimumPixelSize: 128,
maximumScale: 4000,
},
});
// Create a constant orientation property for the ground station (optional)
var groundStationOrientation = new Cesium.ConstantProperty(Cesium.Transforms.headingPitchRollQuaternion(
groundStation.position.getValue(viewer.clock.currentTime), new Cesium.HeadingPitchRoll(80.0, 0.0, 0.0)));
// Set the ground station's orientation (optional)
groundStation.orientation = groundStationOrientation;
}
function createVerticalOrbitPositions() {
var positions = [];
var numPoints = 360;
var altitude = 8000000; // Height in meters
for (var i = 0; i <= numPoints; i++) {
var angle = Cesium.Math.toRadians(i);
var x = 0;
var y = altitude * Math.sin(angle);
var z = altitude * Math.cos(angle);
var position = new Cesium.Cartesian3(x, y, z);
positions.push(position);
}
return positions;
}
</script>
correct the code help me for this