lib/generate.js
/**
 * Creates specified tile and recursively invokes self on all child tiles
 * within the rendering bounds
 *
 * @param {int} tx the tile x coordinate (relative to zoom level)
 * @param {int} ty the tile y coordinate (relative to zoom level)
 * @param {zoom} tx the current zoom level
 * @param {array} patterns a collection of patterns that potentially overlap tile
 * @param {array} stops a collection of stops that potentially overlap tile
 */
Creates specified tile and recursively invokes self on all child tiles
within the rendering bounds


Creates specified tile and recursively invokes self on all child tiles within the rendering bounds
function processTile (tx, ty, zoom, patterns, stops) {
  const bounds = GlobalMercator.tileBounds(tx, ty, zoom)
  const pixelOffsets = GlobalMercator.metersToPixels(bounds[0], bounds[1], zoom)
  stops = stops.filter(stop => {
    const x = stop.coordsPx[zoom][0] - pixelOffsets[0]
    const y = 256 - (stop.coordsPx[zoom][1] - pixelOffsets[1])
    const tol = 5
    return x > -tol && x < 256 + tol && y > -tol && y < 256 + tol
  })
  let visiblePatterns = []
  patterns.forEach(ptn => {
    const coordsPx = ptn.coordsPx[zoom]
    let isect = false
    for (let c = 0; c < coordsPx.length - 1; c++) {
      if (linegeom.isectRectangleLine(
          pixelOffsets[0], pixelOffsets[1], pixelOffsets[0] + 256, pixelOffsets[1] + 256,
          coordsPx[c][0], coordsPx[c][1], coordsPx[c + 1][0], coordsPx[c + 1][1])) {
        isect = true
        break
      }
    }
    if (!isect) return
    visiblePatterns.push(ptn)
  })
  if (visiblePatterns.length === 0 && stops.length === 0) return
  if (config.bounds) {
    if (bounds[3] < swBounds[1]) return 
    if (bounds[1] > neBounds[1]) return 
    if (bounds[0] > neBounds[0]) return 
    if (bounds[2] < swBounds[0]) return 
  }
  if (zoom >= config.render.minZoom) renderTile(tx, ty, zoom, visiblePatterns, stops)
  if (zoom < config.render.maxZoom) {
    for (let x = tx * 2; x <= tx * 2 + 1; x++) {
      for (let y = ty * 2; y <= ty * 2 + 1; y++) {
        processTile(x, y, zoom + 1, visiblePatterns, stops)
      }
    }
  }
}
function processTile ( tx , ty , zoom , patterns , stops ) { const bounds = GlobalMercator . tileBounds ( tx , ty , zoom ) const pixelOffsets = GlobalMercator . metersToPixels ( bounds [ 0 ] , bounds [ 1 ] , zoom ) stops = stops . filter ( stop => { const x = stop . coordsPx [ zoom ] [ 0 ] - pixelOffsets [ 0 ] const y = 256 - ( stop . coordsPx [ zoom ] [ 1 ] - pixelOffsets [ 1 ] ) const tol = 5 return x > - tol && x < 256 + tol && y > - tol && y < 256 + tol } ) let visiblePatterns = [ ] patterns . forEach ( ptn => { const coordsPx = ptn . coordsPx [ zoom ] let isect = false for ( let c = 0 ; c < coordsPx . length - 1 ; c ++ ) { if ( linegeom . isectRectangleLine ( pixelOffsets [ 0 ] , pixelOffsets [ 1 ] , pixelOffsets [ 0 ] + 256 , pixelOffsets [ 1 ] + 256 , coordsPx [ c ] [ 0 ] , coordsPx [ c ] [ 1 ] , coordsPx [ c + 1 ] [ 0 ] , coordsPx [ c + 1 ] [ 1 ] ) ) { isect = true break } } if ( ! isect ) return visiblePatterns . push ( ptn ) } ) if ( visiblePatterns . length === 0 && stops . length === 0 ) return if ( config . bounds ) { if ( bounds [ 3 ] < swBounds [ 1 ] ) return if ( bounds [ 1 ] > neBounds [ 1 ] ) return if ( bounds [ 0 ] > neBounds [ 0 ] ) return if ( bounds [ 2 ] < swBounds [ 0 ] ) return } if ( zoom >= config . render . minZoom ) renderTile ( tx , ty , zoom , visiblePatterns , stops ) if ( zoom < config . render . maxZoom ) { for ( let x = tx * 2 ; x <= tx * 2 + 1 ; x ++ ) { for ( let y = ty * 2 ; y <= ty * 2 + 1 ; y ++ ) { processTile ( x , y , zoom + 1 , visiblePatterns , stops ) } } } }
Creates specified tile and recursively invokes self on all child tiles
 within the rendering bounds
Creates specified tile and recursively invokes self on all child tiles within the rendering bounds
// filter stops by whether they are visible in this tile // filter patterns by whether they are visible in this tile // don't continue w/ this tile if there are no visible patterns or stops // don't continue if bounds are specified and this tile is outside of them // tile is south of bounds // tile is north of bounds // tile is east of bounds // tile is west of bounds // draw the tile, if we are at/past the minZoom level // recursively invoke on child tiles, if we have not yet reached the maxZoom level