【问题标题】:How to get the index of data in CesiumCesium中如何获取数据的索引
【发布时间】:2021-04-27 02:33:03
【问题描述】:

我已经成功实施了有关如何构建飞行跟踪器的教程。我希望能够在我的应用程序的当前时间访问我的数据索引。换句话说,当铯显示飞机沿着飞行路径的动画时,我怎样才能得到飞机的当前索引? (我的数据的索引)。

我有两个实体,一个在循环下生成路径的所有点,另一个用于加载飞机模型。我需要将我的应用程序的其他部分与 Cesium 的当前状态同步。 (如果我暂停 Cesium,我需要暂停其他事情等)

我正在使用 Resium。顺便提一句。这是我的飞机模型。它根据派生自 const positionProperty = new SampledPositionProperty();的位置属性进行动画处理

 // this is the loop that draws the path with points
 {flightData.map((data, i) => {
    const time = JulianDate.fromIso8601(data.timestamp);
    const position = Cartesian3.fromDegrees(
      data.longitude,
      data.latitude,
      data.height + 5.0
    );
    // here we add a sample, per object in the array 
    positionProperty.addSample(time, position);

    return (
      <Entity
        key={`${i}${position}`}
        position={position}
        point={{ pixelSize: 5, color: PhaseColors[data.phase] }}
      />
    );
  })}

// this is the airplane model that follows the path above
<Entity
style={{ border: "10px solid green" }}
// Here is where we pass the positionProperty sample. How can I get the current index out of this? 
position={positionProperty} 
// Automatically compute the orientation from the position.
orientation={new VelocityOrientationProperty(positionProperty)}
tracked
selected
model={{ uri: model, minimumPixelSize: 100, maximumScale: 100.0 }}
path={
  new PathGraphics({
    width: 3,
    material: Color.fromCssColorString("#202025"),
  })
}
availability={
  new TimeIntervalCollection([
    new TimeInterval({ start: start, stop: stop }),
  ])
}

我认为的一种方法是使用时钟并获取时间戳。使用时间戳我可以查找我自己的数据。但我想避免这种情况,这非常昂贵。

那里有任何铯专家吗? :D

【问题讨论】:

    标签: javascript reactjs cesium


    【解决方案1】:

    您可能正在寻找SampledPositionProperty.getValue(...)

    您有一个变量positionProperty,其类型为SampledPositionProperty。它被标记为const,但我认为这是不正确的,因为您是在构建后向其中添加样本。

    无论如何,要从那里获取数据,您需要这样调用:

    var currentPos = positionProperty.getValue(clock.currentTime);
    

    请注意,这将返回完整的 Cartesian3 位置,而不是索引。这是因为clock.currentTime 可能会落在索引之间,而positionProperty 会在中间时间平滑插值。

    【讨论】:

    • 非常感谢您的回答。在这种情况下,我仍然需要使用 Cartesian3 位置来查找我的数据。对吗?
    • 视情况而定。您是否试图在点之间的某个特定采样时间取回纬度/经度/高度?或者你真的需要索引原始数据,查找一些不是位置的额外信息?如果是后者,该信息是否会随时间变化,是否需要在点之间进行插值?
    • 肯定是后者。我们确实需要索引原始数据。我们需要的额外信息是为了显示文本字段(如通知)以及随时间变化的数据。我们真的不需要点之间的插值,因为我们可以选择最接近的值。
    • 哦,我的立场是正确的。如果您为每个点创建一个带有日期范围的Cesium.TimeIntervalCollection,则有一个TimeIntervalCollection.indexOf 函数将返回索引本身。但是,由于插值,这在采样属性上不可用。
    • 当然可以,但可用性需要以单个间隔覆盖飞机的整个飞行。我建议一个单独的属性,可能是“描述”,或者它可能只是您自己的代码中与实体分开的自定义属性,您可以将所有较小的间隔加载到列表中(可能在每个间隔)。然后你可以随时获取值或获取索引。
    猜你喜欢
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    • 2022-06-19
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多