4

I want to access to some entities in my czml data source for keep tracking in the viewer but after the loading, as one of the options for camera. I know that I can access entities in my czml file while I am loading them, but I don't know how I can access to them after loading. Here I have an example:

  var viewer = new Cesium.Viewer('cesiumContainer'); 
  var czmlDataSource = new Cesium.CzmlDataSource();
  viewer.dataSources.add(czmlDataSource);
  czmlDataSource.load('../../SampleData/Vehicle.czml').then(function(){
         var myEntity= czmlDataSource.entities.getById('Vehicle');
          viewer.trackedEntity=myEntity;
         });

This code works fine, but I want to give option to the viewer to choose the camera, then I need to have access to Vehicle after I finished loading, I tried several methods, but non of them works. I have some example bellow:

  var viewer = new Cesium.Viewer('cesiumContainer'); 
  var czmlDataSource = new Cesium.CzmlDataSource();
  viewer.dataSources.add(czmlDataSource);
  czmlDataSource.load('../../SampleData/Vehicle.czml');
  var myEntity= czmlDataSource.entities.getById('Vehicle');
  viewer.trackedEntity=myEntity;

Do you know how I can define an entity from those which are already in my czml file?

CodeMonkey
  • 22,825
  • 4
  • 35
  • 75
azar
  • 283
  • 3
  • 21

1 Answers1

2

The reason your second block of code doesn't work appears to be simply because you haven't waited for the asynchronous load of the czmlDataSource.

Try modifying your second block of code, take off the last 2 lines and wrap them in a button onClick callback. If you click the button before the CZML is loaded, myEntity will be undefined and the camera won't change. If you click the same button again after the CZML loads, it should work fine.

emackey
  • 11,818
  • 2
  • 38
  • 58
  • I don't know how to do that, I used the sandcastle.addToolbarButton and that didn't work – azar Sep 23 '15 at 22:34
  • You were right, it was because I define a reset option and in that one I removed dataSources. Now I need to figure out how I can define different level of buttons. – azar Sep 23 '15 at 22:54