Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request SampledProperty exposes its _times #12245

Open
s3xysteak opened this issue Oct 10, 2024 · 3 comments · May be fixed by #12253
Open

Request SampledProperty exposes its _times #12245

s3xysteak opened this issue Oct 10, 2024 · 3 comments · May be fixed by #12253

Comments

@s3xysteak
Copy link
Contributor

s3xysteak commented Oct 10, 2024

Feature

It looks like:

class SampledProperty {
  // ...
  getLatestTime() {
    return this._times[this._times.length - 1]
  }
}

Assumed API

  1. sampledProperty.getLatestTime() like above.
  2. Readonly sampledProperty.times which exposed _times attribute.
  3. sampledProperty.getTime(index) which receive a number. index < 0 indicate reverse index.
  4. sampledProperty.getTimeByIndex(index) A clear but cumbersome alias of getTime.

I prefer getTime or getTimeByIndex because it is more comprehensive than getLatestTime. Expose _times correctly maybe challenging because it is a array returned an address. We don't want user can change _times by other means than addSample(s).

Use Case:

  1. Assume we have a real-time location entity:
const pos = new Cesium.SampledProperty(Cesium.Cartesian3)
viewer.entities.add({
  position: new Cesium.CallbackProperty(time => {
    const val = pos.getValue(time)
    return val ?? pos.getValue(pos.getLatestTime())
  })
})

If just use SampledProperty, the entity will hide when SampledProperty.getValue return undefined. Most time we prefer to make it stay put if there is no value returned at that time, instead of suddenly disappear and suddenly appear when the data was updated.

  1. Similarly, for a real-time rotate entity:
const ori = new Cesium.SampledProperty(Cesium.Quaternion)
viewer.entities.add({
  orientation: new Cesium.CallbackProperty(time => {
    const val = ori.getValue(time)
    return val ?? ori.getValue(ori.getLatestTime())
  })
})

When providing a null value, the entity will suddenly return to the default value (if orientation: ori). With getLatestTime() we can make it stay to wait for the updated data.

@ggetz
Copy link
Contributor

ggetz commented Oct 11, 2024

Thanks for the suggestion @s3xysteak.

I think if we exposed this functionality, we'd likely want to name the functions getSamples for clarity.

Is this something you'd be interested in contributing?

@s3xysteak
Copy link
Contributor Author

I'm happy to create a PR for this! Additionally, getSamples seems to correspond with addSamples, which receives a list and return a list. Would using the name getSample, to align with addSample, make it more intuitive?
This API is like:

function getSample(index: number): Cesium.JulianDate

@ggetz
Copy link
Contributor

ggetz commented Oct 14, 2024

@s3xysteak Sounds great!

Yes, I agree.

@s3xysteak s3xysteak linked a pull request Oct 15, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants