# Camera control from CZML

**URL:** <https://community.cesium.com/t/camera-control-from-czml/4891>\
**Category:** CesiumJS\
**Created:** [December 6, 2016, 7:36pm UTC](https://community.cesium.com/t/camera-control-from-czml/4891 "2016-12-06T19:36:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Vollrath](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Adam\_Vollrath](https://community.cesium.com/u/Adam_Vollrath)\
**Post date:** [December 6, 2016, 7:36pm UTC](https://community.cesium.com/t/camera-control-from-czml/4891/1 "2016-12-06T19:36:12Z")

</div>

Good afternoon,

We’re migrating our geospatial content management and display appliances from Google Earth to Cesium, and we need some more feature parity to make this happen. Specifically, we need granular Camera control from files within our CMS, as we’re now doing with KML and Earth.

I see CZML has nearly all the features we need (and more!), and we’re happy to convert our customers’ existing content from KML. But the big missing piece is fine control of the camera, as KML does through `gx:Tour` elements. CZML specifies positions for all those other visual elements in both time and space, so can we add camera control to it as well? Maybe add a “camera” element to the special “id”: “document” element next to “clock”?

We have a mandate for dozens of hours to add this capability to the upstream `cesium` core, with automated tests any anything else y’all require, and I look forward to working with you all!

Adam Vollrath

End Point Liquid Galaxy

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [December 6, 2016, 7:47pm UTC](https://community.cesium.com/t/camera-control-from-czml/4891/2 "2016-12-06T19:47:29Z")

</div>

Hello,

There’s nothing in the CZML spec for camera control. Instead, you can accomplish this with code on the client side.

See the ‘fly in a city’ part of this example: [http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Camera.html&label=Showcases](http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Camera.html&label=Showcases)

You can see how to zoom to an entity once the CZML is loaded here: [http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=CZML%20Model.html&label=CZML](http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=CZML%20Model.html&label=CZML)

Instead of setting viewer.tracked entity, you would start your camera tour logic.

Alternatively, Cesium does have KML support for many KML features and I believe we do suppport gx: Tour. You may not need to convert your files to CZML. If we’re missing a KML feature you’re using, let me know and I can add that to our KML roadmap.

Best,

Hannah

---

<div class="post-metadata">

**Author:** ![Adam\_Vollrath1](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@Adam\_Vollrath1](https://community.cesium.com/u/Adam_Vollrath1)\
**Post date:** [December 6, 2016, 7:50pm UTC](https://community.cesium.com/t/camera-control-from-czml/4891/3 "2016-12-06T19:50:39Z")

</div>

Thank you for replying, Hannah,

Yes, we see how to control the Camera from the API, but we really need a way to serialize this into a file within our CMS, preferably the same file that contains the visual elements.

---

<div class="post-metadata">

**Author:** ![Andrew\_Leahy](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/andrew_leahy/32/2390_2.png) [@Andrew\_Leahy](https://community.cesium.com/u/Andrew_Leahy)\
**Post date:** [December 6, 2016, 8:53pm UTC](https://community.cesium.com/t/camera-control-from-czml/4891/4 "2016-12-06T20:53:11Z")

</div>

Hi Adam, do you have an example KML with the camera poses in gx:Tour that Cesium isn’t rendering well.

Is the example at [https://developers.google.com/kml/documentation/touring](https://developers.google.com/kml/documentation/touring) a good stress test?

Andrew

---

<div class="post-metadata">

**Author:** ![Adam\_Vollrath1](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@Adam\_Vollrath1](https://community.cesium.com/u/Adam_Vollrath1)\
**Post date:** [December 6, 2016, 9:26pm UTC](https://community.cesium.com/t/camera-control-from-czml/4891/5 "2016-12-06T21:26:28Z")

</div>

Andrew!

It’s my understanding from [https://github.com/AnalyticalGraphicsInc/cesium/issues/873](https://github.com/AnalyticalGraphicsInc/cesium/issues/873) that Cesium doesn’t support `gx:Tour` at all, tho I admit I haven’t yet tried loading one. Is it working but not documented?

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [December 7, 2016, 5:54am UTC](https://community.cesium.com/t/camera-control-from-czml/4891/6 "2016-12-07T05:54:17Z")

</div>

Ah, sorry, it looks like we don’t have Tour implemented at the moment. I was getting that confused with gx:Track from our KML bike ride example: [http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=KML.html&label=DataSources](http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=KML.html&label=DataSources)

-Hannah

---

<div class="post-metadata">

**Author:** ![Adam\_Vollrath](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Adam\_Vollrath](https://community.cesium.com/u/Adam_Vollrath)\
**Post date:** [December 7, 2016, 6:13pm UTC](https://community.cesium.com/t/camera-control-from-czml/4891/7 "2016-12-07T18:13:37Z")

</div>

We’d like to add this feature, either within KML or CZML or both. Is there an existing ticket for this specifically? Where should we start?

To get this working quickly, we’re also considering serializing the camera control in another JavaScript file, then loading it from the CMS with `jQuery.getScript()` or similar. We’d strongly prefer camera control to reside within the same file as the visual elements, but we’ll take what we can get.

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [December 8, 2016, 4:39am UTC](https://community.cesium.com/t/camera-control-from-czml/4891/8 "2016-12-08T04:39:56Z")

</div>

I’m not sure if this is something we would want to add to the CZML specification, so starting with KML or your own custom data source would probably be your best bet.

For KML, In order to have the exact same behavior seen in Google Earth you will need to make changes to both the Camera.flyTo functionality and the KmlDataSource. Currently, camera flights operate independently from the clock on the timeline. In order to make the camera fly back and forth as you scrub the timeline, you would need to make the camera update happen based on the application clock instead of the system clock. Then in KmlDataSource.load you would need to write code to create camera flights based on whatever data is in the KML document. Finally, you would need to make some changes to KmlDataSource.update to move the camera based on the time. I think that would be it. This isn’t part of the code I’m super familiar with, so I’d have to ask other members of the team to see if there’s something I’m forgetting.

If you would like to take a stab at implementing this, let me know and I’ll create an issue on our GitHub with some more details. And if you get it working, we would really appreciate the contribution back!

Best,

Hannah
