czml import - labels, description

Hi,

I recently found out about Cesium and love the application so far.

I’m learning js atm and ran into a problem I just can’t solve on my own - so maybe someone here has an advice for me and could explain what’s going on.

var czml = [
{“id”:“document”,“name”:“CZML Position Definitions”,“version”:“1.0”},
{“id”:“1”,“name”:“xxx”,“properties”:{“1”:“xx”,“2”:“xx”,“3”:“xx”},“position”:{“cartographicDegrees”:[71.7072,-15.0921,0]}},
{“id”:“2”,“name”:“xxx”,“properties”:{“1”:“xx”,“2”:“xx”,“3”:“xx”},“position”:{“cartographicDegrees”:[-90,0,0]}}
];

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var scene = viewer.scene;
scene.debugShowFramesPerSecond = true;

var Spoints = scene.primitives.add(new Cesium.PointPrimitiveCollection());
var Slabels = scene.primitives.add(new Cesium.LabelCollection());

var fleetdata = new Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(Cesium.CzmlDataSource.load(czml));

fleetdata.then(function(fleet){
var ships = fleet.entities.values;
for (var i = 0; i < ships.length; i++) {
var ship = ships[i];
var pos = ship.position._value;

    Spoints.add({
        position: pos,
        color: Cesium.Color.YELLOW,                
    });
    Slabels.add({
        position: pos,
        text: ship.name,
        scale: 0.5
    });
}

});

This is the code snippet and it works fine. Since I want to add thousands of points, I thought I follow https://cesium.com/blog/2016/03/02/performance-tips-for-points/ for better performance.

I can edit the labels, points and everything - except for the description when I click on a label or point. I want to create an individual description for each ship (with lon/lat/height, display of different properties and so on).
I read somewhere (can’t remember…sry) that when you load a czml that those entities aren’t drawn/displayed, only loaded so you can work with them - I can’t express this well as I haven’t really understood it…

So maybe someone can point me in the right direction to solve this problem.

best regards

Hi Hellmood,

Good to hear you’re enjoying Cesium so far!

You can set the “description” property, which will show up in the info box when you click the entity. See this Sandcastle example.

Hope that helps, thanks!

Gabby

Hi Gabby,

thanks for answering!

Yes I know that example but my problem is:

I want to create a live map with thousands of moving points so my idea to get this done was:

  • create 1 czml file to define all the points with every property (point layout, description, initial position, custom properties and so on) which gets updated accordingly
  • create 1 czml stream file which only updates the position of the corresponding ID.

Since this is fed by a SQL database with hundreds of entries every 5 to 10 seconds, I thought about other methods to save some throughput.

But when I take the above code and add

ship.description({})

it doesn’t do anything but I’m sure I saw this in some example code somewhere.

So does this mean I really have to have the description in the czml file?

best regards

You should be able to set an entity’s description to a string or string of html like so:

ship.description = “

  1. My description
”;

``

You might also want to look at CZML Reference Properties if you want to have one “master” copy to refence.