Skip to main content
2 of 4
added 1374 characters in body
Michal Zimmermann
  • 4.3k
  • 1
  • 23
  • 39

How to check if wms layer is queryable in openlayers?

I'm running a map with lots of different wms layers published by geoserver. Some of them are queryable, some of them are not. How can I tell that with openlayers api? I'm requesting getfeatureinfo and I need to request only the queryable layers, layers with queryable param set to false always return "Layer is not queryable" when requested - and that's what I want to hide from users. I looked into OpenLayers.Map.layers and found no "queryable" property.

UPDATE (to the first commnent): This works fine as long as I use it with localhost:8080/geoserver/wms?service=wms&version=1.1.1&request=GetCapabilities. When I tried to get capabilities from http://www.edpp.cz:8080/geoserver/wms?service=wms&version=1.1.1&request=GetCapabilities, i got empty array of layers as a result. I'm trying it with the following code:

function getCapabilities(offline) {
    var url = '';
    if (offline) {
        url = 'localhost:8080/geoserver/wms?service=wms&version=1.1.1&request=GetCapabilities';
    }
    else {
        url = 'http://www.edpp.cz:8080/geoserver/wms?service=wms&version=1.1.1&request=GetCapabilities'
    }
    var layers = []
        ,result
        ,request = OpenLayers.Request.GET({
            url: url
            ,success: function(response) {
                var format = new OpenLayers.Format.XML()
                    ,xml = format.read(response.responseText)
                    ,text = format.write(xml)
                    ,CAPformat = new OpenLayers.Format.WMSCapabilities()
                    ,cap = CAPformat.read(xml);
                    if (cap.capability) {
                        for (var len = cap.capability.layers.length-1; len >= 0; len -= 1) {
                            if (cap.capability.layers[len].queryable) {
                                layers.push(cap.capability.layers[len].name);
                            }
                        }
                    }
            }
        });
    return layers; //ARRAY
}
Michal Zimmermann
  • 4.3k
  • 1
  • 23
  • 39