cesium – Updating a CZML ‘description’ upon opening the InfoBox ?

updating-CZML-description

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

//------ create CZML ------

var czml = 
 [{"id" : "document",
 "version" : "1.0"
 },{"id" : "Boston",
 "label":{"text":"Boston"},
 "position":{"cartographicDegrees":[-71.0589,42.3601,0]},
 "description":"Boston is a city...",
 },{"id" : "New York City",
 "label":{"text":"New York"},
 "description":"New York is a city...",
 "position":{"cartographicDegrees":[-74.0059,40.7127,0]},
 }];

var promise = Cesium.CzmlDataSource.load(czml);
promise.then(function(dataSource) {
 viewer.dataSources.add(dataSource);

   //------ Get the array of entities
 var entities = dataSource.entities.values;
   //------ Loop entities
   for (var i = 0; i < entities.length; i++) {
     var entity = entities[i];
     var name = entity.label;
     entity.label.translucencyByDistance = new Cesium.NearFarScalar(100000,1.0,500000,0.0);
   }
}).otherwise(function(error){
   //------ Display error
 window.alert(error);
});

    //------ Use SSEH to update to current description

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(click) {
  var pickedObject = scene.pick(click.position);
  if (Cesium.defined(pickedObject)) {

    pickedObject.id.description =  'The current temperature is...';
   }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);    

Setting the description property should update it.  Here is an example:


var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(click) {
    var pickedObject = scene.pick(click.position);
    if (Cesium.defined(pickedObject)) {
        pickedObject.id.description = 'New description';
    }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);


pickedObject.id is the entity.
Share

Leave a Reply

Your email address will not be published. Required fields are marked *