1. A concise explanation of the problem you’re experiencing.
I am trying to create entities from streaming data:
- I have set up an Html file that loads the Cesium sandcastle globe.
- Data is sent from a PHP file using Server Sent Events.
The code in the html file is:
/Create new CZML datasource
var czmlStream = new Cesium.CzmlDataSource();
var czmlStreamUrl = ‘http://czmlhost/sse.php’;
//set up EventSource
var czmlEventSource = new EventSource(czmlStreamUrl);
//Listen for EventSource data coming across as event: czml
czmlEventSource.addEventListener(‘message’, function(czmlUpdate) {
//process the ‘data:’ coming across as JSON into the datasource
console.log(‘xxxxxx’);
var dat = (czmlUpdate.data);
console.log(dat);
var xx = JSON.parse(dat);
console.log(xx);
czmlStream.load(xx);
console.log('Processing ’ + czmlStream);
viewer.dataSources.add(czmlStream);
``
The first entity sent and appears to be processed correctly and displays in the Chrome console as:
- {id: “document”, version: “1.0”}
- id:“document”
- version:“1.0”
- proto:Object
``
The second (billboard) entity is shown as
- {id: “2”, billboard: {…}, position: {…}}
- billboard:{image: “labels.jpg”, verticalOrigin: “BOTTOM”, show: true}
- id:“2”
- position:{cartographicDegrees: Array(3)}
- proto:Object
``
These suggests the structure of the JSON is correct (the JSON is shown as valid by a validator).
Trying to add the billboard entity results in a runtime error:
RuntimeError {name: “RuntimeError”, message: “The first CZML packet is required to be the document object.”, stack: “Error
at new RuntimeError (http://localhost:80…pps/Sandcastle/gallery/hello%20world2.html:54:14)”}
``
I can’t see why this error occurs - the first packet is the document object; the second packet has a different ID.
Please would it be possible to suggest where I am going wrong?
Many thanks,
Hugh