2

I want to read variables from an XML file generated by a WFS. I do this with WMS but I didn't find the equivalent of it in case of using WFS. Do you have any idea ?

here is my code :

ol.control.LayerControl.prototype.showNewLayerPanel = function(btn){
var this_ = this; //get it ready to be passed on listener functions
var urlsArray = this.options.capabilitiesURLs;
var capabJsonDocs = new Array();
  for (var i=0;i<urlsArray.length;i++){
      Ext.Ajax.request({
          url     : urlsArray[i],
          method  : 'GET', 
          async   : false, 
          success: function(response) {
              var parser = new ol.format.WMSCapabilities();
              capabJsonDocs.push(parser.read(response.responseXML));
              console.log("capabJsonDocs",capabJsonDocs)
          }
      });
  }

I have options.capabilitiesURLs : ['{my_path}/geoserver/PFE/wms?request=GetCapabilities']

1

I had the same problem and couldn't find it in the openlayers. I had to read the xml document to get the layers. Adding that to your existing logic would be something like below:

   ol.control.LayerControl.prototype.showNewLayerPanel = function(btn){
        var this_ = this; //get it ready to be passed on listener functions
        var urlsArray = this.options.capabilitiesURLs;
        var capabXMLDocs = new Array();
        for (var i=0;i<urlsArray.length;i++){
            Ext.Ajax.request({
                url     : urlsArray[i],
                method  : 'GET', 
                async   : false, 
                success: function(response) {
                    var parser = new DOMParser();
                    var xmlDoc = parser.parseFromString(response, "text/xml");
                    capabXMLDocs.push(xmlDoc);
                    console.log("capabXMLDocs",capabXMLDocs);
                }
            });
        }
   }

 You can read the variable xmlDoc like below: 
 var capabilities = xmlDoc.getElementsByTagName("wfs:WFS_Capabilities")[0];
 var layers_parent = capabilities.getElementsByTagName("FeatureTypeList")[0];
 var layers = layers_parent.getElementsByTagName("FeatureType");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.