lib/generate.js
/**
 * Process a single feed
 *
 * @param {object} feedData the data returned by the graphql query for this feed
 * @return {object} an object containing arrays of processed patterns and stops
 */
Process a single feed
@param {object} feedData the data returned by the graphql query for this feed
@return {object} an object containing arrays of processed patterns and stops
Process a single feed @param { object } feedData the data returned by the graphql query for this feed @return { object } an object containing arrays of processed patterns and stops
function processFeed (feedData) {
  const patterns = []
  for (let rte of feedData.feeds[0].routes) {
    for (let ptn of rte.patterns) {
      ptn.route_short_name = rte.route_short_name
      ptn.coordsGM = ptn.geometry.coordinates.map(c =>
        GlobalMercator.latLonToMeters(c[1], c[0]))
      ptn.coordsPx = {} 
      for (let zoom = 0; zoom <= config.render.maxZoom; zoom++) {
        ptn.coordsPx[zoom] = ptn.coordsGM.map(c => GlobalMercator.metersToPixels(c[0], c[1], zoom))
      }
      patterns.push(ptn)
    }
  }
  console.log('- read ' + patterns.length + ' patterns')
  const stops = feedData.feeds[0].stops.map(stop => {
    stop.coord = GlobalMercator.latLonToMeters(parseFloat(stop.stop_lat), parseFloat(stop.stop_lon))
    stop.coordsPx = {} 
    for (let zoom = 0; zoom <= config.render.maxZoom; zoom++) {
      stop.coordsPx[zoom] = GlobalMercator.metersToPixels(stop.coord[0], stop.coord[1], zoom)
    }
    return stop
  })
  console.log('- read ' + stops.length + ' stops')
  return { patterns, stops }
}
function processFeed ( feedData ) { const patterns = [ ] for ( let rte of feedData . feeds [ 0 ] . routes ) { for ( let ptn of rte . patterns ) { ptn . route_short_name = rte . route_short_name ptn . coordsGM = ptn . geometry . coordinates . map ( c => GlobalMercator . latLonToMeters ( c [ 1 ] , c [ 0 ] ) ) ptn . coordsPx = { } for ( let zoom = 0 ; zoom <= config . render . maxZoom ; zoom ++ ) { ptn . coordsPx [ zoom ] = ptn . coordsGM . map ( c => GlobalMercator . metersToPixels ( c [ 0 ] , c [ 1 ] , zoom ) ) } patterns . push ( ptn ) } } console . log ( '- read ' + patterns . length + ' patterns' ) const stops = feedData . feeds [ 0 ] . stops . map ( stop => { stop . coord = GlobalMercator . latLonToMeters ( parseFloat ( stop . stop_lat ) , parseFloat ( stop . stop_lon ) ) stop . coordsPx = { } for ( let zoom = 0 ; zoom <= config . render . maxZoom ; zoom ++ ) { stop . coordsPx [ zoom ] = GlobalMercator . metersToPixels ( stop . coord [ 0 ] , stop . coord [ 1 ] , zoom ) } return stop } ) console . log ( '- read ' + stops . length + ' stops' ) return { patterns , stops } }
Process a single feed
 @param {object} feedData the data returned by the graphql query for this feed
 @return {object} an object containing arrays of processed patterns and stops
Process a single feed @param { object } feedData the data returned by the graphql query for this feed @return { object } an object containing arrays of processed patterns and stops
// process patterns // convert to Global Mercator meters // convert to pixels for each zoom level up to the max // maps zoom level to array of pixel coords // process stops // convert to Mercator meters // convert to pixels for each zoom level up to the max // maps zoom level to array of pixel coords