Looking for Java CZML-Writer Example

I have been intermittently writing simple czml files with my own (simple) Java program in order to learn how all of it works since May.

Last week I noticed the czml-writer Java Library and am excited to start using it, since I will be creating more complex scenarios soon.

However, most of my attempts with the library haven’t been successful.

So, I am curious if I could get an example Java class that writes a simple scenario with (start/stop dates, a simple trajectory path, and possibly an outline of a country!)

This would be much appreciated and should get me (and anyone else with the same question) moving.

Note: I have been examining the unit tests provided with the library, but am looking for a more “direct” example of the writer working.


Ethan Laughlin

Hi Ethan,

Examples and documentation are still pretty lacking for the czml-writer library. Can you share the code you’ve written so far? I could help you fix that up, and then that could form an example for others.

There’s one easy thing to check, though. Have you updated to the last version of Cesium in master since June 29? That’s when the “viewer” branch was merged into master, containing the changes necessary to load any CZML file created by czml-writer. If you’re using a branch other than master, it’s possible that those changes have still not yet been merged in.



Here’s a very basic java attempt. I believe the general flow of using the writer is correct; however, there are some problems I run into.

  1. Is it correct to convert http URL, to an image, to base64 encoding?

  2. When making a “Path” what properties are needed in order to create a moving object in the viewer?

Currently the viewer will load the output of this (it correctly loads the time and target URL (after a conversion)) but no path appears.

Note: The creation of the path is using a stand alone class for parsing a file containing - Time,X,Y,Z - for the trajectory.

TestScenario.java (3.01 KB)

Hi Ethan,

Thanks for sharing your code.

You’re right that you should encode your image as a base64 data URL. We intend to make that easy, but right now it’s kind of a hassle in the Java version (easier in .NET). External URLs are OK, too, but they have to be enabled for CORS, and I don’t think wikipedia is.

One problem I see in this example is that you’re writing the “id” and “availability” properties twice in the same packet, which results in invalid JSON. CesiumLanguageWriter is a low-level library with speed as a major goal, so it doesn’t check for problems like this. As a general rule, don’t call the same method twice on the same object or invalid JSON will be generated.

Another problem is that the “path” primitive is not yet supported in Cesium. It’s on our near-term to-do list to hook that up, but currently it is ignored. Consider using a “polyline” primitive instead, which gets its points from the “vertexPositions” property.

I attached a new version of your TestScenario that generates CZML that loads correctly in the Cesium Viewer at http://cesium.agi.com/CesiumViewer/. You can test it by writing the output to a file and dragging it into the viewer.


TestScenario.java (3.43 KB)

Thank you for the help!

This definitely helped me understand the process for using the Java Library.

With the Path primitive not being supported yet.

How would you go about creating a moving object (“billboard”) using Java or .NET? (or anything else).



Hey Ethan,

To create a moving billboard, you just need to add the billboard.image and position properties. Of course, if you’re also trying to show a line for the object’s track using a polyline, you’ll need to put position data in both the position and vertexPositions properties. That’s a little unfortunate, and one of the things that the path primitive is meant to solve once it’s hooked up.