AnsweredAssumed Answered

ArcGIS REST API: Generate

Question asked by jamesfreddyc Champion on Apr 23, 2018
Latest reply on Aug 17, 2020 by levmichael

I'm not sure what to do as I don't see any error and dev tools doesn't report anything.  I'm attempting to implement this Add Shapefile sample into a button click on a new custom widget.  The issue seems to be happening in setting up the "request"


        generateFeatureCollection: function (fileName) {
            var name1 = fileName.split(".");
            //Chrome and IE add c:\fakepath to the value - we need to remove it
            //See this link for more info:
            var name = name1[0].replace("c:\\fakepath\\", "");
            console.log("processing filename: ", name)
            //dom.byId('upload-status').innerHTML = '<b>Loading </b>' + name;

            //Define the input params for generate see the rest doc for details
            var params = {
                'name': name,
                'targetSR': map.spatialReference,
                'maxRecordCount': 1000,
                'enforceInputFileSizeLimit': true,
                'enforceOutputJsonSizeLimit': true
            console.log("params: ", params)

            //generalize features for display Here we generalize at 1:40,000 which is approx 10 meters
            //This should work well when using web mercator.
            var extent = scaleUtils.getExtentForScale(map, 40000);
            var resolution = extent.getWidth() / map.width;
            params.generalize = true;
            params.maxAllowableOffset = resolution;
            params.reducePrecision = true;
            params.numberOfDigitsAfterDecimal = 0;

            var myContent = {
                'filetype': 'shapefile',
                'publishParameters': JSON.stringify(params),
                'f': 'json',
                'callback.html': 'textarea'
            console.log("myContent: ", myContent)
            console.log("setting up request")
            //use the rest generate operation to generate a feature collection from the zipped shapefile
                url: portalUrl + '/sharing/rest/content/features/generate',
                content: myContent,
                form: lang.hitch(this, dom.byId('uploadForm')),
                form: dom.byId('uploadForm'),
                handleAs: 'json',
                load: lang.hitch(this, function (response) {
                    if (response.error) {
                        var layerName = response.featureCollection.layers[0];
                        console.log("layerName: ", layerName)
                error: lang.hitch(this, this.errorHandler)

        errorHandler: function (error) {
            //dom.byId('upload-status').innerHTML = "<p style='color:red'>" + error.message + "</p>";
            console.log("1 errorHandler: ", error.message)
        addShapefileToMap: function (featureCollection) {
            //add the shapefile to the map and zoom to the feature collection extent
            //If you want to persist the feature collection when you reload browser you could store the collection in
            //local storage by serializing the layer using featureLayer.toJson()  see the 'Feature Collection in Local Storage' sample
            //for an example of how to work with local storage.
            var fullExtent;
            var layers = [];

            console.log("addShapefileToMap initiated")
            arrayUtils.forEach(featureCollection.layers, function (layer) {
                var infoTemplate = new InfoTemplate("Details", "${*}");
                var featureLayer = new FeatureLayer(layer, {
                    infoTemplate: infoTemplate
                //associate the feature with the popup on click to enable highlight and zoom to
                featureLayer.on('click', function (event) {
                //change default symbol if desired. Comment this out and the layer will draw with the default symbology
                fullExtent = fullExtent ?
                  fullExtent.union(featureLayer.fullExtent) : featureLayer.fullExtent;
            map.setExtent(fullExtent.expand(1.25), true);

            dom.byId('upload-status').innerHTML = "";


I've added a few console.log prints to try and track down what's going wrong.  No errors, but request doesn't seem to do anything (it's supposed to call "addShapefileToMap" function but seems to just go right to errorHandler: function. 


Line #37 above console.log("setting up request") is the last thing in the console before errorHandler is then reached.  Hopefully just something silly I'm doing.