Adding Properties with czml-writer

I want to create a properties tag in my czml output. Something like this:
    
"properties" :{ "type":"B",
                 "domain":"sp" }

What API / classes do I use to create this? I tried using CustomPorpertiesCeisumWriter, but I don't see how to add a key/value map.

Because each custom property can have a different data type and/or different value specification (constant/sampled/interval/etc.) each custom property is created individually.

It sounds like you’re using the czml-writer project, so you can look at:

https://github.com/AnalyticalGraphicsInc/czml-writer/blob/master/DotNet/CesiumLanguageWriterTests/TestCustomPropertiesCesiumWriter.cs

for code examples creating custom properties of various types.
In general, the API is similar to how the rest of the czml-writer API works (open property, write data, close property).

1 Like

that is close to what I want. I really want a list of properties without having to define a type. But if I have to define a type that is fine. However, i can't get a list of properties, even with a type.
    "properties" : { "plane":{"string":"777"},
                     "car":{"string":"chevy"}
                    }
   is what I will take. but what I am getting is this:
    "properties":{
    "plane":{
      "string":"777"
    },
      "properties":{
         "car":{
        "string":"chevy"
      }
    }
}

I am using Java. Could the Java libraries not be working? I cannot get a list of properties, no matter what I do. here is the java code:

CustomPropertiesCesiumWriter property = packet.openPropertiesProperty();

CustomPropertyCesiumWriter customProperty = property.openCustomPropertyProperty(“DataType”);

customProperty.writeString(“Ships”);

customProperty = property.openCustomPropertyProperty(“Domain”);

customProperty.writeString(“AIR”);

and the output:

“properties”:{ “DataType”:{ “string”:“Ships”, “Domain”:{“string”:“AIR”}

Make sure that you’re not closing the properties writer after each property. Compare your code with the TestMultipleProperties method:

https://github.com/AnalyticalGraphicsInc/czml-writer/blob/master/DotNet/CesiumLanguageWriterTests/TestCustomPropertiesCesiumWriter.cs#L115

Note that the two custom properties are both opened, written, and closed while the containing properties writer remains open.

I figured it out. I needed to close the properties when done.

CustomPropertiesCesiumWriter property = packet.openPropertiesProperty();

CustomPropertyCesiumWriter customProperty = property.openCustomPropertyProperty(“DataType”);

customProperty.writeString(“Ships”);

customProperty.close();

customProperty = property.openCustomPropertyProperty(“Domain”);

customProperty.writeString(“AIR”);

customProperty.close();

property.close();

Correct, I didn’t realize you were using the Java version. In C# the using statements dispose each writer automatically at the end of the block.

In Java, you can do a similar thing using try-with-resources syntax:

try (CustomPropertiesCesiumWriter customPropertiesWriter = packet.openPropertiesProperty()) {

try (CustomPropertyCesiumWriter customPropertyWriter = customPropertiesWriter.openCustomPropertyProperty(“DataType”)) {

customPropertyWriter.writeString(“Ships”);

}

try (CustomPropertyCesiumWriter customPropertyWriter = customPropertiesWriter.openCustomPropertyProperty(“Domain”)) {

customPropertyWriter.writeString(“AIR”);

}

}

1 Like