Hi,
I am going to create a ground Vehicle Tracking by passing packet of data( [{ lon: 78.60834078421288, lat: 19.977258721643523, time: “2020-03-09T02:10:00Z” }] ) and while converting time format from “2020-03-09T02:10:00Z” to JulianDate format I’m getting an error like (Cesium.js:1 Uncaught TypeError: Cannot set properties of undefined (setting ‘dayNumber’)).
well, I have added bit of code here,
const routeData1 = [{lon: 78.60834078421288, lat: 19.977258721643523, time: "2020-03-09T02:10:00Z" }];
function trackVehicle(vehicleid, waypoints) {
const start = routepath[0].time;
console.log('START ', start);
const stop = Cesium.JulianDate.addSeconds(waypoints[0].time); //ERROR LINE: Cannot set properties of undefined (setting 'dayNumber')
console.log('STOP ', stop);
//setting cesium clock
map.clock.startTime = start.clone();
map.clock.stopTime = stop.clone();
map.clock.currentTime = start.clone();
map.timeline.zoomTo(start, stop);
}
}
document.getElementById("pack1").onclick = function () {
trackVehicle('AA1012', routeData1);
};
ERROR LOG :
Cesium.js:1 Uncaught TypeError: Cannot set properties of undefined (setting 'dayNumber')
at setComponents (Cesium.js:1)
at Function.JulianDate.addSeconds (Cesium.js:1)
at trackVehicle (track.html:206)
at HTMLButtonElement.document.getElementById.onclick (track.html:261)
This happened to me once with Cartesian3 when I forgot to put it in import at the top of my index.js file when I first used webpack. Also sometimes I forget to add a file to import from cesium when i’ve made a new change.
If your using webpack maybe its a similar thing where you need to import one of the clock functions? Just guessing here, that’s all I got. Good Luck 
1 Like
Thanks, Actually for each 5 second I push a new packet of data( [{ lon: 78.60834078421288, lat: 19.977258721643523, time: “2020-03-09T02:10:00Z” }], [{ lon: 78.70834078421288, lat: 19.877258721643523, time: “2020-03-09T02:10:05Z” }] ). For each packet d/m/y is same, and it can’t able to set the dayNumber, that’s why we are getting this Error : Uncaught TypeError: Cannot set properties of undefined (setting ‘dayNumber’) …???
1 Like
In JavaScript almost everything is an object, null and undefined are exception. if a variable has been declared, but has not been assigned a value, is automatically assigned the value undefined . Therefore, if you try to access the value of such variable, it will throw Uncaught TypeError cannot set property ‘0’ of undefined/null .
JavaScript null and undefined is one of the main reasons to produce a runtime errors . This happens because you don’t check the value of unknown return variables before using it. If you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. The standard way to catch null and undefined simultaneously is this:
if (variable == null) {
// your code here.
}
Because null == undefined is true, the above code will catch both null and undefined.
Also you can write equivalent to more explicit but less concise:
if (variable === undefined variable === null) {
// your code here.
}
This should work for any variable that is either undeclared or declared and explicitly set to null or undefined.