2

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 comment): 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
}
nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Aug 27, 2012 at 20:56

1 Answer 1

5

The queriable information is contained in the WMS capabilities document, the one that gets returned when you hit http://host:port/geoserver/ows?request=GetCapabilities&service=WMS

OpenLayers has this class to parse it: http://dev.openlayers.org/docs/files/OpenLayers/Format/WMSCapabilities-js.html

answered Aug 28, 2012 at 6:12
2

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.