[OpenLayers-Users] Problem with getting WFS capabilities

Phil Scadden p.scadden at gns.cri.nz
Mon Jul 21 14:08:31 PDT 2014


hmm. I use a custom WFSCapabilities parser but dont otherwise have an 
issue. Have checked your getcaps call directly as a browser URL (or 
looked at the return in the NET tab).
My code is like this: (It is within the context of an ExtJS form but you 
should see the essentials okay. It loads a store with a list of WFS layers).


function wfsGetCapabilities(node) {
     var url = node.data.sQURL;
     if (url.indexOf('?') < 0) url += '?';
     if ((url.indexOf('?') + 1) < url.length) url += '&';
     if (url != '?') {
         Ext.Ajax.request({
             url: 'FileHandling/adminproxy.jsp',
             success: addWfsLayers,
             params: {
                 url: url + 'service=WFS&request=GetCapabilities'
             }
         });
     }
}

function addWfsLayers(response) {
     var wfsGetCapabilitiesParsed = parseWFS(response.responseXML);
     var node = getSelNode();
     var layerData = [];
     var layerToSelect = '';
     for (i=0; i<wfsGetCapabilitiesParsed.featureTypes.length; i++) {
         var layer = wfsGetCapabilitiesParsed.featureTypes[i];
         layerData[i] = [layer.prefix + ':' + layer.name,layer.title];
         if (layer.name == node.data.sQFeatureType) layerToSelect = 
layer.title;
     }
     Ext.getStore('AvailableSpatialLayers').loadData(layerData);
     if (layerToSelect != '') {
         var spatialListCombo = Ext.ComponentQuery.query('libraryPanel 
libraryLayerDetailsPanel spatialListCombo')[0];
         spatialListCombo.setValue(layerToSelect);
         spatialListCombo.fireEvent('select',spatialListCombo,'');
     }
}

function parseWFS(xmlDoc) {
     var featureTypeList = {
         featureTypes: []
     };
     for (i=0; i<xmlDoc.documentElement.childElementCount; i++) {
         var elem = xmlDoc.documentElement.childNodes[i];
         if (elem.localName=='FeatureTypeList') {
             for (k=0; k<elem.childElementCount; k++) {
                 var childElem = elem.childNodes[k];
                 if (childElem.localName=='FeatureType') {
                     var featureType = {};
                     for (j=0; j<childElem.childElementCount; j++) {
                         var field = childElem.childNodes[j];
                         var name = field.localName;
                         var text = field.textContent;
                         if (name=='Name') {
                             var parts = text.split(':');
                             featureType.name = parts.pop();
                             featureType.prefix = parts.pop();
                         } else if (name=='Title') featureType.title = text;
                         else if (name=='DefaultSRS') featureType.srs = 
text;
                     }
                     featureTypeList.featureTypes.push(featureType);
                 }
             }
         }
     }
     return featureTypeList;
}


Notice: This email and any attachments are confidential.
If received in error please destroy and immediately notify us.
Do not copy or disclose the contents.



More information about the Users mailing list