[OpenLayers-Users] data extent for wms layer?

Sveen Atle Frenvik (Geomatikk IKT) Atle.Frenvik.Sveen at geomatikk.no
Thu Nov 10 03:09:41 EST 2011


Might be worth pointing out that the bbox you get here is in EPSG:4326, 
so if your map is in another projection you'd have to reproject the bbox?

(Well, it seems like that this solution won't do the trick for Charles 
anyways, but should anyone stumble upon this in the future it might be 
an idea to know this)

-a

On 2011-11-09 16:57, Andreas Hocevar wrote:
> Hi,
>
> the best way to do this is to issue a GetCapabilities request, parse the response with OpenLayers.Format.WMSCapabilities, and look for the layer's bbox or llbbox in the capabilities object. An untested snippet to show you what I mean:
>
> var myLayerName = "my_layer";
> var obj = new OpenLayers.Format.WMSCapabilities().read(response.responseText);
> var capability = obj.capability;
> for (var i=0, len=capability.layers.length; i<len; i++) {
>      var layerObj = capability.layers[i];
>      if (layerObj.name === myLayerName) {
>          map.zoomToExtent(OpenLayers.Bounds.fromArray(layerObj.llbbox));
>          break;
>      }
> }
>
> Andreas.
>
> On Nov 9, 2011, at 15:54 , Charles Galpin wrote:
>
>> I'm drawing a blank on the best way to do this.  I have a wms layer (for performance)  that I'd like to zoom to the data extent for, but it looks like this is not available for a wms layer like you can for a vector layer.
>>
>> Is there a fast call I can make to get the extent only and then use this to zoom?  I am using geoserver on the server side.  Any suggestions would be appreciated.
>>
>> Thanks,
>> charles
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>


-- 
Atle Frenvik Sveen
Utvikler
Geomatikk IKT AS
tlf: 45 27 86 89
atle.frenvik.sveen at geomatikk.no


More information about the Users mailing list