title: Turf.js to find bounding box of data loaded with Mapbox GL JS?
body: <p>I'm using Mapbox GL JS to load in GeoJSON from an external URL on some pages. I would like to automatically fit the map to the boundaries of the polygon I'm loading.</p>
  
  <p>I understand that <a href="http://turfjs.org/docs#bbox" rel="nofollow noreferrer">turf.js's bbox method</a> can help with this, but I'm not sure how to get the GeoJSON into the <code>turf.bbox</code> call.</p>
  
  <p>This is my code right now:</p>
  
  <pre><code>map.addSource('mylayer', {
      type: 'geojson',
      data: '/boundaries.geojson'
  });
  map.addLayer({
      "id": "mylayer",
      "type": "fill",
      "source": "mylayer",
      'paint': {
          'fill-color': '#088',
          'fill-opacity': 0.6
      }
  });
  var bbox = turf.bbox('mylayer');
  map.fitBounds(bbox, {padding: 20});
  </code></pre>
  
  <p>But it fails with <code>turf.min.js:1 Uncaught Error: Unknown Geometry Type</code>. The docs say that <code>bbox</code> wants "any GeoJSON object". </p>
  
  <p>How do I do this correctly? I'd obviously rather not load the external file twice.</p>