I would like to know a simple way to increase the end of a variable with an incremental number, then check it later.
For example creating var using with a for loop or a different method
Example:
var example0=new Date(property.time);
var example1=new Date(property.time);
var example2=new Date(property.time);
var example3=new Date(property.time);
UPDATE
thanks for the answer, I don't know whether to open another discussion but I actually underestimated the question believing to solve my problem, in reality the situation is more complex, I explain myself better: I tried to use an array like:
let startArray =[];
let endArray =[];
for(i=0; i< 4; i++) {
for(j=1; j< 5; j++) {
startArray.push new Date(demoTracks[0].properties.time[i]);
endArray.push new Date(demoTracks[0].properties.time[j]);
}
}
// Get start/end times
var timelineData = new vis.DataSet([{start: startArray[i], end:
endArray[i],
content: 'Tracks' }]);
}
but for my distraction in writing (I thought I could solve this way) what I would need is to break start time from end time to get two separate fragments.
putting everything in an array and not getting the result because it cannot separate properties.time[0] from properties.time[1] which also need to be incremented separately. I show exactly what I need:
var startTime1 = new Date(demoTracks[0].properties.time[0]);
var endTime1 = new Date(demoTracks[0].properties.time[1]);
var startTime2 = new Date(demoTracks[0].properties.time[1]);
var endTime2 = new Date(demoTracks[0].properties.time[2]);
var startTime3 = new Date(demoTracks[0].properties.time[2]);
var endTime3 = new Date(demoTracks[0].properties.time[3]);
to then call in:
var timelineData = new vis.DataSet([{start: startTime, end: endTime,
content: 'Tracks' },
for this I meant as the question how to increase only the end of a variable (which is creating a problem for me) thanks again .
Using you example data set , the below snippet explain in comment how to create a timeline for one demoTrack feature, using the time array data .
var tillicum = { "type": "Feature", "geometry": { "type": "MultiPoint", "coordinates": [ [-123.77252789, 44.37857221 ], [-123.77317087, 44.37864694 ], [-123.77383407, 44.37875853 ] ] }, "properties": { "title": "tillicum", "path_options": { "color": "red" }, "time": [ 1580403952000, 1580403990000, 1580404202000 ], "altitude": [ 0, 0, 0 ], "raw": [] }, "bbox": [ [-124.09386637, 44.34348063 ], [-124.09386637, 44.56531305 ], [-123.26148271, 44.56531305 ], [-123.26148271, 44.34348063 ] ] };
var demoTracks = [tillicum];
// DOM element where the Timeline will be attached
var container = document.getElementById('timeline');
//get items array for dataset from below created function
let trackItems = getItemArray(demoTracks[0]);
console.log(trackItems);
// create dataSet
let items = new vis.DataSet(trackItems);
// Configuration for the Timeline
var timelineOptions = {};
// crate vis dataset from items returned by below function
// Create a Timeline
var timeline = new vis.Timeline(container, items, timelineOptions);
// function that returns items in format to create vis dataset element
function getItemArray(demoTracksElement) {
let timeArray = [];
try {
let iter = 0;
// set length -1 to preent adding last elemnt as timeline element in graph
for(iter; iter < demoTracksElement.properties.time.length -1 ; iter++ ) {
timeArray.push({
id: iter,
content: 'Tracks '+iter,
start: demoTracksElement.properties.time[iter],
end:demoTracksElement.properties.time[iter+1]
})
}
return timeArray;
} catch (e) {
console.log(e);
alert("something went wong with sent data");
return null;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis-timeline-graph2d.min.css" rel="stylesheet" />
<div id="timeline"></div>