Export to CSV from a featureLayer with no url

525
0
09-19-2018 11:18 AM
LefterisKoumis
Occasional Contributor III

Just wanted to share this in case someone else comes across this issue.

This applies when you create a new featurelayer on the fly based on the results of a query or an analysis tool.

When you want to export the attributes of the new FL, even though the option to export to CSV is on, you will not be able to export because of the absence of the featurelayer.url. 

To resolve this issue go to the jimu.js/CSVUtils.js and add the lines 15-18. After you add these lines, you will be able to export the FL attributes.

exports.exportCSVFromFeatureLayer = function(filename, layer, options) {
          console.log(layer)
          console.log(options)
          console.log(filename)
      options = options || {};
      var exportOptions = {
        datas: options.datas,
        objectIds: options.objectIds,
        fromClient: options.fromClient,
        withGeometry: options.withGeometry,
        outFields: options.outFields,
        filterExpression : options.filterExpression,
        outSpatialReference: options.outSpatialReference
      };
       if(layer.url === null){
            exportOptions.fromClient = true;
            exportOptions.withGeometry =true;
       }
      return exports._getExportData(layer, exportOptions).then(function(result) {
        var formattedOptions = {
          formatNumber: options.formatNumber,
          formatDate: options.formatDate,
          formatCodedValue: options.formatCodedValue,
          popupInfo: options.popupInfo
        };
        return exports._formattedData(layer, result, formattedOptions)
          .then(function(formattedResult) {
            return exports.exportCSV(filename, formattedResult.datas, formattedResult.columns);
          });
      });
    };
0 Kudos
0 Replies