diff --git a/public/js/aggregation.js b/public/js/aggregation.js index 9b60e47764d598fd7d19949b22df19a0dbee6059..e9114e5055092af009872b75b8bbb27c838e1cc9 100644 --- a/public/js/aggregation.js +++ b/public/js/aggregation.js @@ -24,6 +24,49 @@ function convertArray2JSON(arr) { } +/** + * + * @param {Array} array containing dates of type Date + * @param {Date} date date to look for in array + * @returns postition of the array where the date was matched + */ + +export const whereIsDateInArray = function(array, date) { + + const DAY = date.getDate(); + const MONTH = date.getMonth(); + var pos = -1; + + for (var i = 0; i < array.length; i++) { + var day = array[i].getDate(); + var month = array[i].getMonth(); + + if (day === DAY && MONTH === month) { + pos = i; + } + } + return pos; + +} + + +/** + * Converts the date string from DD.MM.YYYY obtained from HTML date picker to -> MM.DD.YYYY + * @param {String} selctedDate containing a date string in the format DD.MM.YYYY + * @returns {String} of the provided date in the format MM.DD.YYYY + */ +export const switchDayMonth_inDate = function(selectedDate) { + + + var splitedString = selectedDate.split('.'); + var newDate = []; + newDate.push(splitedString[1]); + newDate.push(splitedString[0]); + newDate.push(splitedString[2]); + return newDate.join('.');; +} + + /** * Format the response from SensorThings API to make it suitable for heatmap * @param {Array} obsArray Response from SensorThings API as array diff --git a/public/js/appCesium.js b/public/js/appCesium.js index 80c014d213b243815af871fc81028a399a24abd4..1625356495ef9a5bf57ac1045d8042fde5272a96 100644 --- a/public/js/appCesium.js +++ b/public/js/appCesium.js @@ -3,6 +3,8 @@ // Functions import { aggregateResponse, + switchDayMonth_inDate, + whereIsDateInArray, } from "./aggregation.js"; @@ -374,8 +376,21 @@ const activate3DTileFeaturePicking = function() { drawHeatMapHC(formatSTAResponseForHeatMap(agg.originalFormat)); drawLineChartHC(formatSTAResponseForLineChart(agg.originalFormat)); console.log(ALLDATA.length); - var selectedDate = document.getElementById("DateSelected").value; - console.log(selectedDate); + var selectedDate = document.getElementById("DateSelected").innerHTML; + + var date = new Date( + Date.parse( + switchDayMonth_inDate(selectedDate) + ) + ); + + var p = whereIsDateInArray(ALLDATA[0].timestamp, date); + if (p == -1) + console.log('date not found in date array'); + else + console.log('date found at position' + p); + + console.log(date); // alert('waiting...'); });