CZML-Writer Question

All,

Over the last few days I’ve been trying to take the data from open flights and show worldwide air traffic as a series of green arcs. Attached is a screen shot of what I’ve done so far.

Right now I have one particular problem that is baffling me:

For some reason, when I generate multiple packets (PacketCesiumWriter packet = stream.openPacket(output); …do stuff…packet.close()), the resultant json outputted from the StringWriter does not have brackets around the packet objects (to make an array of objects), so I get complaints from dojo.

So far I’m manually writing the brackets in by using string concatenation ( “[”+sw.toString()+"]" ), but this doesn’t seem like a good solution. I’m sure it’s something obvious, but I can’t figure it out.

Also, the polylines sometimes disappear if I go into 2D or Columbus (though I haven’t had that issue in a few iterations, might not be a real issue).

-TJ

Hey TJ,

You’re the second person today to have this same problem, so I think we have a usability problem on our hands! Fortunately, the solution is easy. Before opening your first packet, call WriteStartSequence on the CesiumOutputStream, and call WriteEndSequence after the last one.

The reason it doesn’t do this automatically is because the CZML writers can also be used to write packets in Event Stream format. In that format, the packets aren’t members of an array, but are instead each stuffed into a separate event. CZML event streams are read using the browsers EventSource API, which allows packets to be handled incrementally. With standard JSON, the entire JSON document must be downloaded before it can be processed.

Perhaps we should assume JSON format, and require explicit configuration to skip writing the array. I’ll have to think about it, but if you have any ideas let me know.

Kevin

Kevin,

Works perfect, and your reasoning makes sense as this is supposed to be a ‘lower level’ implementation.

EventSource will work even with single element arrays, so you could put brackets around everything ‘just in case’, but that’s not very elegant.

Maybe you could create a CesiumOutputDocument class that extends CesiumOutputStream that works more like a JSON document. I created a stub for myself:

public class CesiumOutputDocument extends CesiumOutputStream {

public CesiumOutputDocument(Writer writer) {

super(writer);

this.writeStartSequence();

}

public void close(){

this.writeEndSequence();

}

}

-TJ