I would like to retrieve the extent of an ImageWMS layer in OpenLayers dynamically from the BBOX param.
I would use it for (e.g.) zooming to layers'extent.
At the moment, my code looks like this:
var layer2 = new ol.layer.Image({
title: 'zone',
visible: false,
source: wmsSource2,
extent: [952014.59,5571269.68,1272301.10,5862273.22]
});
...
// in the layers tab, zoom map to layer when zoom icon is clicked
$('.fa-search').on('click', function() {
var layer = layer2;
view.fit(layer.getExtent(), {
duration:1000
});
});
As you can see, now I am defining the extent in the layer
variable.
Rather, I would love to get it from the WMS itself, instead of re-defining it again in my js.
From the documentation, I see I can set the BBOX WMS parameter in the ol.source.ImageWMS params
option. Better, it's automagically set by OL4!
So, the question is: how would I retrieve the BBOX from this parameter if possible? I am using Mapserver as WMS server if that matters.