Skip to content

Instantly share code, notes, and snippets.

@shunter
Created October 30, 2015 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shunter/7fa5107bfe6e4008b0bf to your computer and use it in GitHub Desktop.
Save shunter/7fa5107bfe6e4008b0bf to your computer and use it in GitHub Desktop.
Writing Custom CZML
using System;
using System.Collections.Generic;
using CesiumLanguageWriter;
namespace CustomCzml
{
internal class Program
{
private static void Main(string[] args)
{
var cesiumOutputStream = new CesiumOutputStream(Console.Out)
{
PrettyFormatting = true
};
// A CZML file contains an array of objects which the following starts.
cesiumOutputStream.WriteStartSequence();
var cesiumStreamWriter = new CesiumStreamWriter();
// Create the document packet
using (var packetWriter = cesiumStreamWriter.OpenPacket(cesiumOutputStream))
{
packetWriter.WriteId("document");
packetWriter.WriteVersion("1.0");
}
// Create packet for an object
using (var packetWriter = cesiumStreamWriter.OpenPacket(cesiumOutputStream))
{
packetWriter.WriteId("1");
packetWriter.WriteName("Name");
// Add position to object's packet
using (var positionWriter = packetWriter.OpenPositionProperty())
{
positionWriter.WriteCartographicDegrees(new Cartographic(-75.5966, 40.0386, 0.0));
}
// Add label to object's packet
using (var labelWriter = packetWriter.OpenLabelProperty())
{
labelWriter.WriteTextProperty("Exton");
}
// Custom constant string property
using (var customWriter = new StringCesiumWriter("stringProperty"))
{
customWriter.Open(cesiumOutputStream);
customWriter.WriteString("Some Value");
}
// Custom sampled double property
using (var customWriter = new DoubleCesiumWriter("doubleProperty"))
{
customWriter.Open(cesiumOutputStream);
var dates = new List<JulianDate>
{
new JulianDate(new GregorianDate(2015, 10, 30, 12, 0, 0)),
new JulianDate(new GregorianDate(2015, 10, 30, 23, 0, 0))
};
var values = new List<double>
{
1,
100
};
customWriter.WriteNumber(dates, values, 0, 2);
}
}
// end the array
cesiumOutputStream.WriteEndSequence();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment