如何生成<a> list from published layers in Geoserver?

时间:2017-07-26 08:46:54

标签: javascript jquery openlayers-3 geoserver wms

I am building a webmapping app. I parse the WMS request to have the title of each layer in layers:

var xhr = new XMLHttpRequest();
        xhr.open('GET', 'http://localhost:8082/geoserver/wms?service=wms&request=GetCapabilities', true);
        xhr.onload = function() {
            var parser = new ol.format.WMSCapabilities();
            var capabilities = parser.read(xhr.responseText);
            var layers = capabilities.Capability.Layer.Layer.Title; 
};

But then I fail to access to the titles contain in layers:

$.each(layers, function(i)
            {
                var list = $('</br><a/>')
                .text(layers[i])
                .appendTo($('div.myDiv'));
            });

What did I miss? Thanx for the help.

1 个答案:

答案 0 :(得分:0)

我认为问题是,您需要图层的名称,而不是标题才能调用它。

所以你要解析这样的功能:

var layers = capabilities.Capability.Layer.Layer.Name;