Closed iskandari closed 7 years ago
Hi @iskandari, thanks for pointing out the inconsistency in the sample data. startTime
and endTime
are not actually used by the TripsLayer
. I will remove them from the example to avoid confusion.
Thanks for that clarification @Pessimistress. How should one understand the negative numbers in the timestamp? In the sample data, does the counter loop begin at 0 ms and end at 60000 ms? If so, how do the negative timestamps factor into the loop?
_animate() {
const timestamp = Date.now();
const loopLength = 1800;
const loopTime = 60000;
this.setState({
time: ((timestamp % loopTime) / loopTime) * loopLength
});
Let's say that I want to input my own sample data - all trips that occurred over the course of one day (the timestamp
range would be 0:86400 as there are 86400 seconds in one day). I would like to condense this into a 60-second loop that animates the trips as they happened in order. For example, in the sample data below, the first trip occurs at the start of the day, the second in the middle of the day, and the third at the end of the day. What parameters would have to be changed so as to create a 60-second loop that goes through the range of timestamps 0:86400?
{
"vendor": 0,
"segments": [
[ -79.87493, 43.25175, 0],
[ -79.87499, 43.25165,100],
[ -79.87499, 43.25165, 200],
[-79.87501, 43.25162, 300],
[-79.87500, 43.25163, 400]
]
},
{
"vendor": 0,
"segments": [
[-79.90765, 43.26102, 40000],
[-79.90765, 43.26111, 40100],
[-79.90765, 43.26111, 40200],
[-79.90763, 43.26110, 40300],
]
},
{
"vendor": 0,
"segments": [
[-79.90927, 43.26067, 80000],
[-79.90925, 43.26052, 80100],
[-79.90920, 43.26055, 80200],
[-79.90920, 43.26055, 80300],
[-79.90927, 43.26060, 80400]
]
}
+1 for negative timestamp problem .
And why the center of the map is hardcoded , it can't be generated using segments data ??
@iskandari The absolute timestamps does not matter - it's the difference between a timestamp and the currentTime
prop that determines the animation frame. You may as well use UNIX timestamps and have your timer loop between, say, 1483228800
and 1483315200
.
If that makes sense, then trips with negative timestamps in your context are just trips that started the previous day and ended on the current day.
As for the time loop, you may consider using tween.js to manage your timer, something like:
new TWEEN.Tween({currentTime: 0})
.to({currentTime: 86400}, 60 * 1000);
@amanjuneja3012 The code in question is meant to be a minimal example showing how to write a custom layer. The layer itself doesn't manage the viewport, the app does. You can use it as a starting point and implement the features that make sense to you.
I am working with the sample data in
examples/trips
which animates the individual paths of trips from a json array of coordinate pairs intrips/data/trips.json
and their timestamp (under thesegments
key):My question is regarding the time attributes. Why is it that
startTime
andendTime
do not always correspond to the first and last objects in thesegments
array? ? For example, in the first object,startTime
is -6009 but the first coordinate pair has a timestamp of -240. In the second object, theendTime
is 4871 but the last coordinate pair has a timestamp of 1835. How should one understand thestartTime
andendTime
and how they relate to the timestamp? This is not accurately explained in the documentation and any clarification would help.