如何在铯的SampledProperty中定义属性类型 [英] How to define property type in SampledProperty in Cesium
问题描述
我正在使用Cesiumjs创建在一个区域中移动的多边形.
I am using Cesiumjs to create a polygon which is moving around an area.
为了显示其运动,我尝试创建PolygonHierarchy
的sampledProperty
.每个样本都是一个Cartesian3
位置的数组(每个时间步长上我的多边形的三个端点).
To show its movement I tried to create a sampledProperty
of PolygonHierarchy
. Each sample is an array of Cartesian3
positions (three endpoints of my polygon at each time step).
我需要知道我在sampledProperty
中使用的property
的类型,正如在Cesiumjs网站中提到的那样:
I need to know the type of the property
that I am using in sampledProperty
as it is mentioned in Cesiumjs website: Cesiumjs.org/SampledProperty.
但是我不知道如何定义它,我在网站上找不到关于如何识别属性类型的任何解释,尤其是当每个样本本身都是属性数组时.
But I don't know how to define it and I couldn't find any explanation on the website on how to identify property type especially when each sample by itself is an array of properties.
推荐答案
SampledProperty
在这里不起作用,因为它试图在给定的点之间平滑地插值,并且不知道如何插值多边形层次.
The SampledProperty
doesn't work here, since it attempts to interpolate smoothly between the points you've given it, and it doesn't know how to interpolate a polygon hierarchy.
因此,您可以使用 TimeIntervalCollectionProperty
.此处的区别在于,此属性是逐步设置动画的,而不是插值的,因此该属性不需要知道如何构造控制点之间的中间值.
So instead, you can use a TimeIntervalCollectionProperty
. The difference here is that this property animates by steps, not interpolation, so the property does not need to know how to construct the intermediate values between control points.
我做了一个小演示,展示了它如何与多边形层次结构一起工作.点击底部的Run Code Snippet
,或将JavaScript复制并粘贴到 Sandcastle .
I made a small demo, to show how this works with a polygon hierarchy. Click Run Code Snippet
at the bottom, or copy-and-paste just the JavaScript into Sandcastle.
var viewer = new Cesium.Viewer('cesiumContainer', {
navigationInstructionsInitiallyVisible: false
});
// Set up a limited range of time for this demo.
var time = Cesium.JulianDate.fromIso8601('2016-04-08T12:00:00Z');
viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
viewer.clock.startTime = time;
viewer.clock.currentTime = time;
viewer.clock.stopTime = Cesium.JulianDate.addSeconds(time, 20, new Cesium.JulianDate());
viewer.clock.multiplier = 1;
viewer.timeline.updateFromClock();
viewer.timeline.zoomTo(time, viewer.clock.stopTime);
// Construct a TimeIntervalCollection showing the changes to the hierarchy over time.
var hierarchy = new Cesium.TimeIntervalCollectionProperty();
for (var i = 0; i < 40; ++i) {
var nextTime = Cesium.JulianDate.addSeconds(time, 0.5, new Cesium.JulianDate());
// Inside the loop, per iteration we add one window of time for this polygon.
hierarchy.intervals.addInterval(new Cesium.TimeInterval({
start: time,
stop: nextTime,
isStartIncluded : true,
isStopIncluded : false,
data : Cesium.Cartesian3.fromDegreesArrayHeights([-108.0+i/4, 35.0, 100000,
-100.0+i/4, 35.0, 100000,
-100.0+i/4, 40.0, 100000,
-108.0+i/4, 40.0, 100000])
}));
time = nextTime;
}
// Create the polygon, using the animated hierarchy.
var orangePolygon = viewer.entities.add({
name : 'Orange polygon with time-varying position',
polygon : {
hierarchy : hierarchy,
extrudedHeight: 0,
perPositionHeight : true,
material : Cesium.Color.ORANGE.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.WHITE
}
});
viewer.zoomTo(viewer.entities);
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
font-family: sans-serif;
}
<link href="http://cesiumjs.org/releases/1.19/Build/Cesium/Widgets/widgets.css"
rel="stylesheet"/>
<script src="http://cesiumjs.org/releases/1.19/Build/Cesium/Cesium.js">
</script>
<div id="cesiumContainer"></div>
这篇关于如何在铯的SampledProperty中定义属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!