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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't know how to do that, I used the sandcastle.addToolbarButton and that didn't work
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.