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(".");
var name = name1[0].replace("c:\\fakepath\\", "");
console.log("processing filename: ", name)
var params = {
'name': name,
'targetSR': map.spatialReference,
'maxRecordCount': 1000,
'enforceInputFileSizeLimit': true,
'enforceOutputJsonSizeLimit': true
};
console.log("params: ", params)
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")
request({
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) {
this.errorHandler(response.error);
return;
}
var layerName = response.featureCollection.layers[0].layerDefinition.name;
console.log("layerName: ", layerName)
this.addShapefileToMap(response.featureCollection);
}),
error: lang.hitch(this, this.errorHandler)
});
},
errorHandler: function (error) {
console.log("1 errorHandler: ", error.message)
},
addShapefileToMap: function (featureCollection) {
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
});
featureLayer.on('click', function (event) {
map.infoWindow.setFeatures([event.graphic]);
});
changeRenderer(featureLayer);
fullExtent = fullExtent ?
fullExtent.union(featureLayer.fullExtent) : featureLayer.fullExtent;
layers.push(featureLayer);
});
map.addLayers(layers);
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.