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
CentralBody 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();
issLabel.setText(new ConstantCesiumProperty<>(iss.getName()));
issLabel.setFillColor(new ConstantCesiumProperty<>(Color.WHITE));
iss.getExtensions().add(new LabelGraphicsExtension(issLabel));

PolylineOutlineMaterialGraphics issPathMaterial = new PolylineOutlineMaterialGraphics();
issPathMaterial.setColor(new ConstantCesiumProperty<>(Color.WHITE));
issPathMaterial.setOutlineWidth(new ConstantCesiumProperty<>(1.0));
issPathMaterial.setOutlineColor(new ConstantCesiumProperty<>(Color.BLACK));

PathGraphics issPath = new PathGraphics();
issPath.setMaterial(new ConstantCesiumProperty<>(issPathMaterial));
issPath.setWidth(new ConstantCesiumProperty<>(2.0));
issPath.setLeadTime(new ConstantCesiumProperty<>(60.0 * 44.0)); // 44 minutes
issPath.setTrailTime(new ConstantCesiumProperty<>(60.0 * 44.0));
iss.getExtensions().add(new PathGraphicsExtension(issPath));

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

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

LabelGraphics facilityLabel = new LabelGraphics();
facilityLabel.setText(new ConstantCesiumProperty<>(facility.getName()));
facilityLabel.setFillColor(new ConstantCesiumProperty<>(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(new ConstantCesiumProperty<>(new SolidColorMaterialGraphics(Color.YELLOW)));
linkGraphics.setFollowSurface(new ConstantCesiumProperty<>(false));
link.getExtensions().add(new LinkGraphicsExtension(linkGraphics));

Platform sensor = new Platform();
sensor.setLocationPoint(new ServiceProviderPoint(facility));

VectorFixed referenceVector = new VectorFixed(iss.getOrientationAxes(), Cartesian.toCartesian(UnitCartesian.getUnitZ()));
sensor.setOrientationAxes(new AxesTargetingLink(link, LinkRole.TRANSMITTER, referenceVector));

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(new ConstantCesiumProperty<>(Color.WHITE));
gridMaterial.setCellAlpha(new ConstantCesiumProperty<>(0.0));
fieldOfViewGraphics.setDomeSurfaceMaterial(new ConstantCesiumProperty<>(gridMaterial));

Color transparentGreen = new Color(0x80008000, true);
SolidColorMaterialGraphics lateralSurfaceMaterial = new SolidColorMaterialGraphics(transparentGreen);
fieldOfViewGraphics.setLateralSurfaceMaterial(new ConstantCesiumProperty<>(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);

FileWriter streamWriter = new FileWriter(new File(outputDirectory, "CompleteExample.czml"));
czmlDocument.writeDocument(streamWriter);
streamWriter.close();