Click or drag to resize

Code Sample

The following is a complete code sample containing all of the pieces described in detail in the Visualization with Cesium topic. This demonstrates how to create a complex visualization containing multiple objects, and using analysis results to drive visualization.

Java
EarthCentralBody earth = CentralBodiesFacet.getFromContext().getEarth();
TwoLineElementSet issTle =
        new TwoLineElementSet("1 25544U 98067A   10172.34241898  .00007451  00000-0  60420-4 0  3627\r\n" +
                              "2 25544  51.6459 209.3399 0009135 352.3227 186.5240 15.71934500664129");

Point issPoint = new Sgp4Propagator(issTle).createPoint();
Platform iss = new Platform();
iss.setName("ISS");
iss.setLocationPoint(issPoint);
iss.setOrientationAxes(new AxesVehicleVelocityLocalHorizontal(earth.getFixedFrame(), issPoint));

LabelGraphics issLabel = new LabelGraphics();
// Note: toCesiumProperty is a static import of CesiumProperty.toCesiumProperty 
issLabel.setText(toCesiumProperty(iss.getName()));
issLabel.setFillColor(toCesiumProperty(Color.WHITE));
iss.getExtensions().add(new LabelGraphicsExtension(issLabel));

PolylineOutlineMaterialGraphics issPathMaterial = new PolylineOutlineMaterialGraphics();
issPathMaterial.setColor(toCesiumProperty(Color.WHITE));
issPathMaterial.setOutlineWidth(toCesiumProperty(1.0));
issPathMaterial.setOutlineColor(toCesiumProperty(Color.BLACK));

PathGraphics issPath = new PathGraphics();
issPath.setMaterial(toCesiumProperty(issPathMaterial));
issPath.setWidth(toCesiumProperty(2.0));
issPath.setLeadTime(toCesiumProperty(Duration.fromMinutes(44.0).getTotalSeconds()));
issPath.setTrailTime(toCesiumProperty(Duration.fromMinutes(44.0).getTotalSeconds()));
iss.getExtensions().add(new PathGraphicsExtension(issPath));

iss.getExtensions().add(new IdentifierExtension("ISS"));

Cartographic facilityLocation = new Cartographic(-1.3191780323141054, 0.69871349190638687, 0.0);
Point facilityPoint = new PointCartographic(earth, facilityLocation);
Platform facility = new Platform();
facility.setName("AGI HQ");
facility.setLocationPoint(facilityPoint);
facility.setOrientationAxes(new AxesEastNorthUp(earth, facilityPoint));

LabelGraphics facilityLabel = new LabelGraphics();
facilityLabel.setText(toCesiumProperty(facility.getName()));
facilityLabel.setFillColor(toCesiumProperty(Color.WHITE));
facility.getExtensions().add(new LabelGraphicsExtension(facilityLabel));

LinkInstantaneous link = new LinkInstantaneous(facility, iss);
CentralBodyObstructionConstraint constraint = new CentralBodyObstructionConstraint(link, earth);

AccessQueryCesiumProperty<Boolean> showProperty = new AccessQueryCesiumProperty<>();
showProperty.setQuery(constraint);
showProperty.setAccessExists(true);
showProperty.setAccessUnknown(false);
showProperty.setNoAccess(false);

LinkGraphics linkGraphics = new LinkGraphics();
linkGraphics.setShow(showProperty);
linkGraphics.setMaterial(toCesiumProperty(new SolidColorMaterialGraphics(Color.YELLOW)));
link.getExtensions().add(new LinkGraphicsExtension(linkGraphics));

Vector referenceVector = new VectorFixed(iss.getOrientationAxes(), Cartesian.toCartesian(UnitCartesian.getUnitZ()));
Axes sensorOrientation = new AxesTargetingLink(link, LinkRole.TRANSMITTER, referenceVector);
Platform sensor = new Platform();
sensor.setLocationPoint(facility.getLocationPoint());
sensor.setOrientationAxes(sensorOrientation);

RectangularPyramid rectangularPyramid = new RectangularPyramid();
rectangularPyramid.setXHalfAngle(Trig.degreesToRadians(8.0));
rectangularPyramid.setYHalfAngle(Trig.degreesToRadians(4.5));
rectangularPyramid.setRadius(500000.0);
sensor.getExtensions().add(new FieldOfViewExtension(rectangularPyramid));

SensorFieldOfViewGraphics fieldOfViewGraphics = new SensorFieldOfViewGraphics();

GridMaterialGraphics gridMaterial = new GridMaterialGraphics();
gridMaterial.setColor(toCesiumProperty(Color.WHITE));
gridMaterial.setCellAlpha(toCesiumProperty(0.0));
fieldOfViewGraphics.setDomeSurfaceMaterial(toCesiumProperty(gridMaterial));

Color transparentGreen = new Color(0x80008000, true);
SolidColorMaterialGraphics lateralSurfaceMaterial = new SolidColorMaterialGraphics(transparentGreen);
fieldOfViewGraphics.setLateralSurfaceMaterial(toCesiumProperty(lateralSurfaceMaterial));

sensor.getExtensions().add(new FieldOfViewGraphicsExtension(fieldOfViewGraphics));

TimeInterval interval = new TimeInterval(new JulianDate(new GregorianDate(2009, 1, 1)),
                                         new JulianDate(new GregorianDate(2009, 1, 2)));

CzmlDocument czmlDocument = new CzmlDocument();
czmlDocument.setName("CompleteExample");
czmlDocument.setDescription("A complete example");
czmlDocument.setRequestedInterval(interval);
Clock clock = new Clock();
clock.setInterval(interval);
clock.setCurrentTime(interval.getStart());
czmlDocument.setClock(clock);

czmlDocument.getObjectsToWrite().add(iss);
czmlDocument.getObjectsToWrite().add(facility);
czmlDocument.getObjectsToWrite().add(link);
czmlDocument.getObjectsToWrite().add(sensor);

try (Writer writer = Files.newBufferedWriter(outputPath.resolve("CompleteExample.czml"))) {
    czmlDocument.writeDocument(writer);
}