Skip to main content
added 17 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95

In your code, you are using getExtent for layer1. According to the API docs, it "returns the extent of the layer". Then

Then if you look at what is an extent for an ol.layer.Tile (e.g layer1layer1) It's. It's "the bounding extent for layer rendering. The layer will not be rendered outside of this extent."

SoConclusion: you need to setget the extent manually... Iffrom somewhere but as you wereare not using an ol.layer.Vector, you couldcan't get geometries and deduce the extent (butas a WMS is not a vector layer)

To avoid settingThe way to get extent & center manually, you need"magically" is to get the "capabilities" from the WMS layer considering you already set in GeoServer the extent using the layer data (see http://docs.geoserver.org/latest/en/user/data/webadmin/layers.html#bounding-boxes)

What are "capabilities"? It's informations about available layers using OGC web Services (here WMS). You can get more detailed informations about each layer including bounds.

You can find a prototype showing how ityou can be doneuse them. As I don't own the remote demo GeoServer, I suffered some limitations in the prototype. The layer center seems to be the CRS center instead of the layer data center.

In your code, you are using getExtent for layer1. According to the API docs, it "returns the extent of the layer". Then if you look at what is an extent for an ol.layer.Tile (e.g layer1) It's "the bounding extent for layer rendering. The layer will not be rendered outside of this extent."

So you need to set the extent manually... If you were using an ol.layer.Vector, you could get geometries and deduce the extent (but a WMS is not a vector layer)

To avoid setting extent & center manually, you need to get the "capabilities" from the WMS layer considering you already set in GeoServer the extent using the layer data (see http://docs.geoserver.org/latest/en/user/data/webadmin/layers.html#bounding-boxes)

What are "capabilities"? It's informations about available layers using OGC web Services (here WMS) including bounds

You can find a prototype showing how it can be done. As I don't own the remote demo GeoServer, I suffered some limitations in the prototype. The layer center seems to be the CRS center instead of the layer data center.

In your code, you are using getExtent for layer1. According to the API docs, it "returns the extent of the layer".

Then if you look at what is an extent for an ol.layer.Tile (e.g layer1). It's "the bounding extent for layer rendering. The layer will not be rendered outside of this extent."

Conclusion: you need to get the extent from somewhere but as you are not using an ol.layer.Vector, you can't get geometries and deduce the extent (as a WMS is not a vector layer)

The way to get extent & center "magically" is to get the "capabilities" from the WMS layer considering you already set in GeoServer the extent using the layer data (see http://docs.geoserver.org/latest/en/user/data/webadmin/layers.html#bounding-boxes)

What are "capabilities"? It's informations about available layers using OGC web Services (here WMS). You can get more detailed informations about each layer including bounds.

You can find a prototype showing how you can use them. As I don't own the remote demo GeoServer, I suffered some limitations in the prototype. The layer center seems to be the CRS center instead of the layer data center.

Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95

In your code, you are using getExtent for layer1. According to the API docs, it "returns the extent of the layer". Then if you look at what is an extent for an ol.layer.Tile (e.g layer1) It's "the bounding extent for layer rendering. The layer will not be rendered outside of this extent."

So you need to set the extent manually... If you were using an ol.layer.Vector, you could get geometries and deduce the extent (but a WMS is not a vector layer)

To avoid setting extent & center manually, you need to get the "capabilities" from the WMS layer considering you already set in GeoServer the extent using the layer data (see http://docs.geoserver.org/latest/en/user/data/webadmin/layers.html#bounding-boxes)

What are "capabilities"? It's informations about available layers using OGC web Services (here WMS) including bounds

You can find a prototype showing how it can be done. As I don't own the remote demo GeoServer, I suffered some limitations in the prototype. The layer center seems to be the CRS center instead of the layer data center.