title: How to get the extent of a GPX file to display it on a map (using openalyers)
body: <p>I am working on the GPX source example of openlayers 5.x available at <a href="https://openlayers.org/en/latest/examples/gpx.html" rel="nofollow noreferrer">https://openlayers.org/en/latest/examples/gpx.html</a></p>
  
  <p>I am able to successfully load my GPX file and to display it on a map, but I have been unable to get its extent to know the min/max latitudes and longitudes to fit it dynamically on the map.</p>
  
  <p>This is my code (identical to the example):</p>
  
  <pre><code>var GpxVector = new VectorLayer({
     source: new VectorSource({
        url: 'https://host.domain.com/filename.gpx',
        format: new GPX(),
     }),
     style: function(feature) {
        return GpxStyle[feature.getGeometry().getType()];
     }
  });
  
  map.addLayer(GpxVector);
  </code></pre>
  
  <p>The GPX file displays correctly but I am unable to get its extent to resize the map to zoom on it. I have tried:</p>
  
  <pre><code>console.log(GpxVector.getSource().getFeatures());
  </code></pre>
  
  <p>which gives no features to parse:</p>
  
  <pre><code>length: 0
  __proto__: Array(0)
  </code></pre>
  
  <p>note that the source is there, and displays correctly on the map:</p>
  
  <pre><code>console.log(GpxVector.getSource());
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>c {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_: 0, …}
  </code></pre>
  
  <p>but there are no extent: </p>
  
  <pre><code>console.log(GpxVector.getSource().getExtent());
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>[Infinity, Infinity, -Infinity, -Infinity]
  </code></pre>
  
  <p>Also the VectorLayer has no extent: </p>
  
  <pre><code>console.log(GpxVector.getExtent());
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>undefined
  </code></pre>
  
  <p>Can someone help me and tell me how I can access the extents of the GPX file or at least its points so I can calculate it myself ?</p>
  
  <p>Any help would be appreciated !</p>