Aaron
Aaron

Reputation: 1

OpenLayers v3.4 getting layer bounding box and CRS data from GeoServer

I'm looking into OpenLayers v3.4 along with GeoServer. I'm trying to collect the correct bounding box / extent data from a shape file which I've already uploaded to GeoServer.

Here I am collecting the layer from the server.

var vectorLayer = new ol.layer.Tile({
    source: new ol.source.TileWMS({
        preload: Infinity,
        url: 'http://localhost:8080/geoserver/Newcastle/wms',
        serverType: 'geoserver',
        params: {
            'LAYERS': "Newcastle:Newcastle_Coverage", 'TILED': true
        }
    })
});
map.addLayer(vectorLayer);

I would have thought I could have just called the extent from the layer.

var extent = vectorLayer.extent;

But alas, the extent is alwayd 'undefined' which is totally useless to me. I then try to collect the data from using the WMSCapabilities function directly from the XML server download.

    var featurePrefix = '***';
    var featureType = '***';
    var url = 'http://localhost:8080/geoserver/wms?request=GetCapabilities&service=WMS&version=1.1.1';
    var parser = new ol.format.WMSCapabilities();


    $.ajax(url).then(function (response) {
        //window.alert("word");
        var result = parser.read(response);
        console.log(result);
        window.alert(result);
        var Layers = result.Capability.Layer.Layer;
        var extent;
        for (var i = 0, len = Layers.length; i < len; i++) {

            var layerobj = Layers[i];
            window.alert(layerobj.Name);

            if (layerobj.Name == "Newcastle:Newcastle_Coverage")
            {
                extent = layerobj.BoundingBox[0].extent;
            }
        }
    });

This works to some degree, it does return the bounding box of the defined CRS of the data. In this case its EPSG:28356 (MGA56). I know its MGA56 because I uploaded it and told it what it was.

What I need is to get the CRS details for shape files that I don't know. How do I know if its MGA55 or MGA54 etc. I cannot find a way to get this particular information out.

Upvotes: 0

Views: 2049

Answers (1)

bartvde
bartvde

Reputation: 2126

I think it's easier to use EX_GeographicBoundingBox instead, which you know will be always in EPSG:4326

See: https://github.com/MapStory/story-tools/blob/master/examples/common.js#L368:L379 for an example

Upvotes: 1

Related Questions