1

I'm trying to figure out the best approach to fetch data from a geojson file by date. Each feature point has a time parameter and I need to show the points in the map that match a specific date and time.

I also have a date select picker which will show the points in the map based on the date selected.

Any ideas? This is how I envision the code process would look like:

// 1. Geojson data:
{ 'type':'FeatureCollection',
  'crs': {...},
  'features': {
    'type': 'Feature',
    'geometry': {...},
    'properties': {
      'reportStartTime': '2015-12-04T00:55:00Z',
      'id': '3421',
      ...
    }
  }
}
// 2. Get current date
var now = new Date(new Date());
var hour = now.getHours();
var nextHour = hour + 1; // I need to know when the next hour starts
var hourDiff = // I need to get the hours from 00:00 to 00:59min

// 3. Show points in the map that match the current date
function fetchData(feature, timeSelected) {
    var reportStartTime = feature.get('reportStartTime');
    if(reportStartTime == timeSelected){
      return // Show the map points
    }
}
fetchData(feature, hourDiff);

// 4. Filter date picker (using bootstrap date picker)
var newTimeSelected = $('#datetimepicker1').find('input').val(); // i.e returns 12/10/2015 11:57 AM

// 5. Change the map points that match the date selected from the date picker
$('button').submit(function() {
    fetchData(feature, newTimeSelected);
});
Jose Gómez
  • 3,110
  • 2
  • 32
  • 54
Nicolas T
  • 327
  • 1
  • 5
  • 15
  • I think you'll have to show a piece of your geojson data and output format from this datepicker. – Jonatas Walker Dec 09 '15 at 11:06
  • You'll have to do some date operations. That's not an easy task with JavaScript, do you mind to use a helper library like [Moment.js](http://momentjs.com/)? Or take a look at [these answers](http://stackoverflow.com/q/492994/4640499) – Jonatas Walker Dec 09 '15 at 12:24

0 Answers0