index.js
function levels (extent, minZoom, maxZoom) {
  const extents = []
  if (extent === undefined) throw new Error('extent is required')
  if (minZoom === undefined) throw new Error('minZoom is required')
  if (maxZoom === undefined) throw new Error('maxZoom is required')

  // Single Array
  if (extent.length === 4 && extent[0][0] === undefined) { extents.push({bbox: extent, minZoom, maxZoom}) }

  // Multiple Array
  if (extent.length && extent[0][0] !== undefined) { extent.map(inner => extents.push({bbox: inner, minZoom, maxZoom})) }

  // GeoJSON
  featureEach(extent, feature => {
    const bbox = turfBBox(feature)
    const featureMinZoom = feature.properties.minZoom || feature.properties.minzoom || minZoom
    const featureMaxZoom = feature.properties.maxZoom || feature.properties.maxzoom || maxZoom
    extents.push({bbox, minZoom: featureMinZoom, maxZoom: featureMaxZoom})
  })
  const levels = []
  for (const {bbox, minZoom, maxZoom} of extents) {
    let [x1, y1, x2, y2] = bbox
    for (const zoom of range(minZoom, maxZoom + 1)) {
      if (y2 > 85) y2 = 85
      if (y2 < -85) y2 = -85
      const t1 = lngLatToTile([x1, y1], zoom)
      const t2 = lngLatToTile([x2, y2], zoom)

      // Columns
      let columns = []
      // Fiji - World divided into two parts
      if (t1[0] > t2[0]) {
        // right world +180 degrees
        const maxtx = Math.pow(2, zoom) - 1
        const rightColumns = range(t1[0], maxtx + 1)
        rightColumns.forEach(column => columns.push(column))

        // left world -180 degrees
        const mintx = 0
        const leftColumns = range(mintx, t2[0] + 1)
        leftColumns.forEach(column => columns.push(column))
      } else {
        // Normal World
        const mintx = Math.min(t1[0], t2[0])
        const maxtx = Math.max(t1[0], t2[0])
        columns = range(mintx, maxtx + 1)
      }

      // Rows
      const minty = Math.min(t1[1], t2[1])
      const maxty = Math.max(t1[1], t2[1])
      const rows = range(minty, maxty + 1)

      levels.push([columns, rows, zoom])
    }
  }
  return levels
}
function levels (extent, minZoom, maxZoom) {
  const extents = []
  if (extent === undefined) throw new Error('extent is required')
  if (minZoom === undefined) throw new Error('minZoom is required')
  if (maxZoom === undefined) throw new Error('maxZoom is required')

  // Single Array
  if (extent.length === 4 && extent[0][0] === undefined) { extents.push({bbox: extent, minZoom, maxZoom}) }

  // Multiple Array
  if (extent.length && extent[0][0] !== undefined) { extent.map(inner => extents.push({bbox: inner, minZoom, maxZoom})) }

  // GeoJSON
  featureEach(extent, feature => {
    const bbox = turfBBox(feature)
    const featureMinZoom = feature.properties.minZoom || feature.properties.minzoom || minZoom
    const featureMaxZoom = feature.properties.maxZoom || feature.properties.maxzoom || maxZoom
    extents.push({bbox, minZoom: featureMinZoom, maxZoom: featureMaxZoom})
  })
  const levels = []
  for (const {bbox, minZoom, maxZoom} of extents) {
    let [x1, y1, x2, y2] = bbox
    for (const zoom of range(minZoom, maxZoom + 1)) {
      if (y2 > 85) y2 = 85
      if (y2 < -85) y2 = -85
      const t1 = lngLatToTile([x1, y1], zoom)
      const t2 = lngLatToTile([x2, y2], zoom)

      // Columns
      let columns = []
      // Fiji - World divided into two parts
      if (t1[0] > t2[0]) {
        // right world +180 degrees
        const maxtx = Math.pow(2, zoom) - 1
        const rightColumns = range(t1[0], maxtx + 1)
        rightColumns.forEach(column => columns.push(column))

        // left world -180 degrees
        const mintx = 0
        const leftColumns = range(mintx, t2[0] + 1)
        leftColumns.forEach(column => columns.push(column))
      } else {
        // Normal World
        const mintx = Math.min(t1[0], t2[0])
        const maxtx = Math.max(t1[0], t2[0])
        columns = range(mintx, maxtx + 1)
      }

      // Rows
      const minty = Math.min(t1[1], t2[1])
      const maxty = Math.max(t1[1], t2[1])
      const rows = range(minty, maxty + 1)

      levels.push([columns, rows, zoom])
    }
  }
  return levels
}
function levels ( extent , minZoom , maxZoom ) { const extents = [ ] if ( extent === undefined ) throw new Error ( 'extent is required' ) if ( minZoom === undefined ) throw new Error ( 'minZoom is required' ) if ( maxZoom === undefined ) throw new Error ( 'maxZoom is required' ) // Single Array if ( extent . length === 4 && extent [ 0 ] [ 0 ] === undefined ) { extents . push ( { bbox : extent , minZoom , maxZoom } ) } // Multiple Array if ( extent . length && extent [ 0 ] [ 0 ] !== undefined ) { extent . map ( inner => extents . push ( { bbox : inner , minZoom , maxZoom } ) ) } // GeoJSON featureEach ( extent , feature => { const bbox = turfBBox ( feature ) const featureMinZoom = feature . properties . minZoom || feature . properties . minzoom || minZoom const featureMaxZoom = feature . properties . maxZoom || feature . properties . maxzoom || maxZoom extents . push ( { bbox , minZoom : featureMinZoom , maxZoom : featureMaxZoom } ) } ) const levels = [ ] for ( const { bbox , minZoom , maxZoom } of extents ) { let [ x1 , y1 , x2 , y2 ] = bbox for ( const zoom of range ( minZoom , maxZoom + 1 ) ) { if ( y2 > 85 ) y2 = 85 if ( y2 < - 85 ) y2 = - 85 const t1 = lngLatToTile ( [ x1 , y1 ] , zoom ) const t2 = lngLatToTile ( [ x2 , y2 ] , zoom ) // Columns let columns = [ ] // Fiji - World divided into two parts if ( t1 [ 0 ] > t2 [ 0 ] ) { // right world +180 degrees const maxtx = Math . pow ( 2 , zoom ) - 1 const rightColumns = range ( t1 [ 0 ] , maxtx + 1 ) rightColumns . forEach ( column => columns . push ( column ) ) // left world -180 degrees const mintx = 0 const leftColumns = range ( mintx , t2 [ 0 ] + 1 ) leftColumns . forEach ( column => columns . push ( column ) ) } else { // Normal World const mintx = Math . min ( t1 [ 0 ] , t2 [ 0 ] ) const maxtx = Math . max ( t1 [ 0 ] , t2 [ 0 ] ) columns = range ( mintx , maxtx + 1 ) } // Rows const minty = Math . min ( t1 [ 1 ] , t2 [ 1 ] ) const maxty = Math . max ( t1 [ 1 ] , t2 [ 1 ] ) const rows = range ( minty , maxty + 1 ) levels . push ( [ columns , rows , zoom ] ) } } return levels }
Creates a grid level pattern of arrays

@param {BBox|BBox[]|GeoJSON} extent BBox [west, south, east, north] order or GeoJSON Polygon
@param {number} minZoom Minimum Zoom
@param {number} maxZoom Maximum Zoom
@returns {GridLevel[]} Grid Level
@example
const levels = slippyGrid.levels([-180.0, -90.0, 180, 90], 3, 8)
//=levels
Creates a grid level pattern of arrays