Layer.getExtent() returns undefined when working with a Layer sourced by a GPX file
See original GitHub issuethe problem
When trying to work with a Layer sourced by a GPX file, I had a hard time trying to figure out why gpxLayer.getExtent()
was undefined
… until I found out that gpxLayer.getSource().getExtent()
was the right way to get its extent.
the proposed solution
I think it would be easier for newcomers if a method like Layer.getExtent()
always return the correct extent, no matter what is behind the scenes, whether it is a Tile layer, a Vector layer or an Overlay layer.
some sample code
// this is the code that works
map.getView().fit(buffer(gpxLayer.getSource().getExtent(), 1000))
// this is the code that doesn't work nowadays
map.getView().fit(buffer(gpxLayer.getExtent(), 1000))
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to get the extent of a GPX file to display it on a map ...
The source won't load unless the layer is visible on the map. ... getExtent()); }); // open the view to force a load...
Read more >layer get extent returns null openlayers 4 - GIS Stack Exchange
In your code, you are using getExtent for layer1 . According to the API docs, it "returns the extent of the layer".
Read more >OpenLayers v7.2.2 API - Class: Layer
When undefined , a zIndex of 0 is assumed for layers that are added to the map's layers collection, or Infinity when the...
Read more >OpenLayers 3 API Reference - Class: Vector
Returns : The contrast of the layer. getExtent(){ol.Extent|undefined} inherited.
Read more >CSV, TXT, and GPX files—ArcGIS Online Help | Documentation
When you add a CSV file without location information to Map Viewer, a table layer is published and added to the map. If...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The layer’s
getExtent()
function returns the layer extent, if you specified one to restrict the visible area of the layer. This is documented in https://openlayers.org/en/latest/apidoc/module-ol_layer_Vector-VectorLayer.html#getExtent.This is because in OpenLayers, the
Layer
is a lightweight container that configures things that influence the way the layer is rendered (e.g. styles, rendered extent, etc.). Whereas theSource
represents the underlying data. So to get the extent of the data, you’ll need to ask the source for the extent.I see… I will close this issue then.
But maybe this explanation could be added to VectorLayer.getExtent docs.