how can i display entity lat and lon info with label while animating by czml?

Hi,every

I am developing a flight demo, I shown plane entity flight trace by czml data, I also want to display lat and lon info with the label followed entity. but i failed, can anyone give me some tips? thank you.

in czml data, use clock and position property:

"clock": {

"currentTime": “2012-08-04T10:00:00Z”,

"multiplier": 10

}

"position" : {

"epoch" : “2012-08-04T10:00:00Z”,

"cartographicDegrees" : […

to display label info, i do like the below;

viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)).then(function(ds) {

var plane = ds.entities.getById(‘path’);

** plane.label.text = viewer.currentTime.toString();**

viewer.trackedEntity = plane;

**}); **

i want to get position info with this method,but i cannot get the time value because of czml data.

var position = entity.position.getValue(time);

var czml = [{
    "id" : "document",
    "name" : "CZML Path",
    "version" : "1.0",
    "clock": {
        "currentTime": "2012-08-04T10:00:00Z",
        "multiplier": 10
    }
}, {
    "id" : "path",
    "name" : "path with GPS flight data",
    "availability" : "2012-08-04T10:00:00Z/2012-08-04T15:00:00Z",
    "path" : {
        "material" : {
            "polylineOutline" : {
                "color" : {
                    "rgba" : [255, 0, 255, 255]
                },
                "outlineColor" : {
                    "rgba" : [0, 255, 255, 255]
                },
                "outlineWidth" : 5
            }
        },
        "width" : 8,
        "leadTime" : 10,
        "trailTime" : 1000,
        "resolution" : 5
    },
    "position" : {
        "epoch" : "2012-08-04T10:00:00Z",
        "cartographicDegrees" : [
            0,-122.93797,39.50935,1776,
            10,-122.93822,39.50918,1773,
            20,-122.9385,39.50883,1772,
            30,-122.93855,39.50842,1770...

Hi there,

I would update the label text in a callbackProperty. The plane will have a Property for it’s position, that is a Cartesian3. You can retrieve that value, then convert it to a Cartographic to get the lat/long, like so:

function getPositionLength(time) {

var position = plane.position.getValue(time);

var location = Cesium.Cartographic.fromCartesian(position);

return "lat: " + location.latitude + " long: " + location.longitude;

}

plane.label.text = new Cesium.CallbackProperty(getPosition, false);

Hi, Gabby

Thank u for your example, it works. since CallbackProperty is designed to be called every frame, so I finally use setInterval() to update the label text. much appreciate.

thanks!

Jorbin

setInterval(function() {

var position = plane.position.getValue(viewer.clock.currentTime);

var location = Cesium.Cartographic.fromCartesian(position);

plane.label.text = “long” + Cesium.Math.toDegrees(location.longitude) + “\nlat” + Cesium.Math.toDegrees(location.latitude);

console.log(location);

}, 1000);