铯采样属性标签上的文字?

时间:2017-01-15 23:08:35

标签: cesium

类似于如何使用时间戳“烘焙”值到位置属性(或颜色等),是否可以让标签根据时间戳更改其文本?

1 个答案:

答案 0 :(得分:0)

是的,请使用TimeIntervalCollectionProperty。这是一个例子,点击"运行代码段"此代码底部的按钮:



var viewer = new Cesium.Viewer('cesiumContainer', {
    navigationInstructionsInitiallyVisible: false,
    // These next 5 lines are just to avoid the Bing Key error message.
    imageryProvider : Cesium.createTileMapServiceImageryProvider({
        url : Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII')
    }),
    baseLayerPicker : false,
    geocoder : false,
    // This next line fixes another Stack Snippet error, you may omit
    // this setting from production code as well.
    infoBox : false
});

var startTime = Cesium.JulianDate.fromIso8601('2016-08-01T00:00:00Z');
var intervalStart = startTime;

// Here we construct a TimeIntervalCollectionProperty for the
// label text that changes over time.
var labelText = new Cesium.TimeIntervalCollectionProperty();

// As a demo, this creates a day's worth of one-second time intervals, each
// one with its own label text.
for (var x = 0; x < 86400; ++x) {
    var intervalStop = Cesium.JulianDate.addSeconds(startTime, x, new Cesium.JulianDate());
    labelText.intervals.addInterval(new Cesium.TimeInterval({
        start: intervalStart,
        stop: intervalStop,
        data: 'Time ' + x
    }));
    intervalStart = intervalStop;
}

// Set up some clock properties here.
var clock = viewer.clock;
clock.startTime = startTime;
clock.stopTime = intervalStart;
clock.currentTime = startTime;
clock.clockRange = Cesium.ClockRange.CLAMPED;
clock.multiplier = 30;
viewer.timeline.zoomTo(clock.startTime, clock.stopTime);

// Finally, create and add an entity with a label, using the labelText
// collection above from the TimeIntervalCollectionProperty we constructed.
viewer.entities.add({
    position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
    label : {
        text : labelText
    }
});
&#13;
html, body, #cesiumContainer {
  width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
  font-family: sans-serif;
}
&#13;
<link href="http://cesiumjs.org/releases/1.29/Build/Cesium/Widgets/widgets.css" 
      rel="stylesheet"/>
<script src="http://cesiumjs.org/releases/1.29/Build/Cesium/Cesium.js">
</script>
<div id="cesiumContainer"></div>
&#13;
&#13;
&#13;