|
POST
|
Yes! Also, I have no need for the changeRenderer function and I'm altering the addShapefileToMap function because I need to get the featureColleciton result into an existing feature layer client side (or graphic layer, can't remember). Ultimately, the results of the upload will get dissolved into existing features.
... View more
04-25-2018
11:00 AM
|
0
|
0
|
2215
|
|
POST
|
Robert, Thanks for working thru this one, turns out that it was a combination of the request method defaulting to GET (and me not correctly forcing POST) and then me failing to properly reference the "uploadForm" in the form attribute of the request. Full function updated with working version. Thank you again! generateFeatureCollection: function(fileName) {
var name = fileName.split(".");
//Chrome and IE add c:\fakepath to the value - we need to remove it
//See this link for more info: http://davidwalsh.name/fakepath
name = name[0].replace("c:\\fakepath\\", "");
//this.uploadstatus.innerHTML = '<b>Loading… </b>' + name;
//Define the input params for generate see the rest doc for details
//http://www.arcgis.com/apidocs/rest/index.html?generate.html
console.log("var params name: ", name)
var params = {
'name': name,
'targetSR': this.map.spatialReference,
'maxRecordCount': 1000,
'enforceInputFileSizeLimit': true,
'enforceOutputJsonSizeLimit': true
};
console.log("var 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(this.map, 40000);
var resolution = extent.getWidth() / this.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)
//use the rest generate operation to generate a feature collection from the zipped shapefile.
request({
url: this.portalUrl + '/sharing/rest/content/features/generate',
content: myContent,
form: dom.byId('uploadForm'), //this.uploadForm,
handleAs: 'json',
load: lang.hitch(this, function (response) {
if (response.error) {
console.log("response.error: ", response.error)
this.errorHandler(response.error);
return;
}
var layerName = response.featureCollection.layers[0].layerDefinition.name;
//this.uploadstatus.innerHTML = '<b>Loaded: </b>' + layerName;
this.addShapefileToMap(response.featureCollection);
}),
error: lang.hitch(this, this.errorHandler)
}, { usePost: 'true', });
},
... View more
04-25-2018
10:39 AM
|
0
|
2
|
2215
|
|
POST
|
*Edit: The issue below may be related to the form: this.uploadForm attribute of the request. I've changed this to form: dom.byId('uploadForm') and it will now run thru without error to the addShapefileToMap function (but I have an error in there now so I'm working thru that). Never would have thought to add it there! Thanks! The generate request appears to be correct now and method is POST. Unfortunately, I the error.message is printing in the console output as: errorHandler: Unable to generate features The Network response in dev tools is: {"error":{"code":400,"message":"Unable to generate features","details":["'itemid', 'sourceUrl' or 'text' must be specified."]}} Your assistance is appreciated! I'll continue to work on this, can't believe how much this is fighting me.
... View more
04-25-2018
10:18 AM
|
0
|
0
|
2215
|
|
POST
|
Yes, that is correct! Also, on the network tab (dev tools) generate looks entirely different and is not issuing POST only GET requests. My implementation: Sandbox:
... View more
04-25-2018
08:25 AM
|
0
|
6
|
2215
|
|
POST
|
Yes, and I've used them in the ESRI sandbox example https://developers.arcgis.com/javascript/3/samples/portal_addshapefile/
... View more
04-25-2018
07:58 AM
|
0
|
8
|
4138
|
|
POST
|
Robert -- no, it doesn't add the shapefile. I made sure to zip a shapefile with WGS Web Mercator Aux Sphere too. You see below that I added a console.log() in the errorHandler, which when I run everything it prints "errorHandler: Method not supported". Also, I added "usePost" attribute to the request. Thanks! Here's the full function: generateFeatureCollection: function(fileName) {
var name = fileName.split(".");
//Chrome and IE add c:\fakepath to the value - we need to remove it
//See this link for more info: http://davidwalsh.name/fakepath
name = name[0].replace("c:\\fakepath\\", "");
//this.uploadstatus.innerHTML = '<b>Loading… </b>' + name;
//Define the input params for generate see the rest doc for details
//http://www.arcgis.com/apidocs/rest/index.html?generate.html
var params = {
'name': this.name,
'targetSR': this.map.spatialReference,
'maxRecordCount': 1000,
'enforceInputFileSizeLimit': true,
'enforceOutputJsonSizeLimit': true
};
//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(this.map, 40000);
var resolution = extent.getWidth() / this.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'
};
//use the rest generate operation to generate a feature collection from the zipped shapefile.
console.log("portalUrl: ", this.portalUrl)
request({
url: this.portalUrl + '/sharing/rest/content/features/generate',
usePost: 'true',
content: myContent,
form: this.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;
this.uploadstatus.innerHTML = '<b>Loaded: </b>' + layerName;
this.addShapefileToMap(response.featureCollection);
}),
error: lang.hitch(this, this.errorHandler)
});
},
errorHandler: function (error) {
//this.uploadstatus.innerHTML = "<p style='color:red'>" + error.message + "</p>";
console.log("req: ", request)
console.log("errorHandler: ", error.message)
},
... View more
04-25-2018
06:20 AM
|
0
|
12
|
4138
|
|
POST
|
Hey thanks! Updated error debugging: If I comment out the callback html attribute, I get past previous error, var myContent = { 'filetype': 'shapefile', 'publishParameters': JSON.stringify(params), 'f': 'json'//, //'callback.html': 'textarea' }; However, I'm now getting this response from the generate request: {"error":{"code":405,"messageCode":"GWM_0005","message":"Method not supported.","details":[]}} I notice that it's a GET request, but if I execute the esri sample its a POST. Prior debugging: I've got it fit in pretty well I think, however I'm tripping the errorHandler function with "errorHandler: Unexpected token <". The full url: parameter prints out as, "http://www.arcgis.com/sharing/rest/content/features/generate" This is the complete request as seen in dev tools: https://www.arcgis.com/sharing/rest/content/features/generate?filetype=shapefile&publishParameters=%7B%22name%22%3A%22uploadconditionclass%22%2C%22targetSR%22%3A%7B%22wkid%22%3A102100%7D%2C%22maxRecordCount%22%3A1000%2C%22enforceInputFileSizeLimit%22%3Atrue%2C%22enforceOutputJsonSizeLimit%22%3Atrue%2C%22generalize%22%3Atrue%2C%22maxAllowableOffset%22%3A10.583354500042818%2C%22reducePrecision%22%3Atrue%2C%22numberOfDigitsAfterDecimal%22%3A0%7D&f=json&callback.html=textarea Thanks again!
... View more
04-24-2018
11:40 AM
|
0
|
14
|
4138
|
|
POST
|
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: http://davidwalsh.name/fakepath
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
//http://www.arcgis.com/apidocs/rest/index.html?generate.html
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
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) {
//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) {
map.infoWindow.setFeatures([event.graphic]);
});
//change default symbol if desired. Comment this out and the layer will draw with the default symbology
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.
... View more
04-23-2018
11:37 AM
|
0
|
16
|
7343
|
|
POST
|
I won't be able to implement this until finished up another requirement. Seems like your answer will be the way to go and I'll go ahead and mark as the answer.
... View more
04-23-2018
08:08 AM
|
0
|
0
|
2124
|
|
POST
|
I'm attempting to integrate THIS example into an existing widget I'm developing. So far, I've added the "Choose File" dialog that allows for navigating to a directory Pretty simple, just added this to my widget's html: <div class="jimu-btn" data-dojo-attach-event="click:toggleManualDrawTool">Manually Draw Boundary</div>
<div class="jimu-btn finish-select" data-dojo-attach-event="click:onConfirmSelection">Add Selected Features to Boundary</div>
<br /><br />
<form enctype="multipart/form-data" method="post" id="uploadForm">
<div class="field">
<label class="file-upload">
<span><strong>Upload a Shapefile</strong></span>
<input type="file" name="file" id="inFile" />
</label>
</div>
</form>
<br /><br />
Now I'm trying to implement the actual process to get the upload processed into the graphics layer. I'm running into an issue when attempting to hook this into the widget's js file. So far I've just attempted to implement as in the example, by adding the various functions within my widget.js file and then adding this into my startup() function startup: function () {
on(dom.byId("uploadForm"), "change", function (event) {
var fileName = event.target.value.toLowerCase();
if (sniff("ie")) { //filename is full path in IE so extract the file name
var arr = fileName.split("\\");
fileName = arr[arr.length - 1];
}
if (fileName.indexOf(".zip") !== -1) {//is file a zip - if not notify user
console.log("genFeatColl function fired")
this.generateFeatureCollection(fileName);
}
else {
dom.byId('upload-status').innerHTML = '<p style="color:red">Add shapefile as .zip file</p>';
}
}); It hits the first log "genFeatColl function fired", however I'm getting this error on line 11 ("this.generateFeatureCollection") Uncaught TypeError: this.generateFeatureCollection is not a function at HTMLFormElement.<anonymous>
... View more
04-23-2018
08:01 AM
|
0
|
2
|
1705
|
|
POST
|
That makes sense. This should be fun and infuriating... I can tell already. Thanks again!
... View more
04-20-2018
12:59 PM
|
0
|
0
|
2124
|
|
POST
|
Can anyone point me to an example/sample of labeling polygon geometry at each vertex? I have a requirement to label each vertex with coordinate info. Javascript 3.x Update: I've attempted to implement the Points for Labeling method on the Geometry service, as seen in this example but I'm getting an error init.js:114 TypeError: Cannot read property '0' of undefined at Object.labelPoints (init.js:2548) getLabelPoints: function (geom) {
var geometryService = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
var geographicGeometries = [];
geographicGeometries.push(esri.geometry.webMercatorToGeographic(geom));
if (geom.rings.length > 0) {
geometryService.labelPoints(this.geom, function(labelPoints) {
var font = new Font("20px", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_BOLDER);
array.forEach(this.labelPoints, function (labelPoint) {
// create a text symbol
var textSymbol = new TextSymbol(
"X: " + number.format(labelPoint.x) + ", Y: " + number.format(this.labelPoint.y),
font, new Color([0, 0, 0]));
var labelPointGraphic = new Graphic(this.labelPoint, textSymbol);
// add the label point graphic to the map
map.graphics.add(labelPointGraphic);
});
});
}
},
... View more
04-20-2018
12:11 PM
|
0
|
3
|
2524
|
|
POST
|
Yes, "Exterior_Electrical" is a feature dataset inside the GDB. I'm not sure what you mean by rework the path references... Don't just set a variable reference to the full path of the feature class like you've done, gdfcin = r'C:\Projects\MDC\DataUpdate_20180315\MDC_PhysModel_FieldID_20180315.gdb\Exterior_Electrical\Phase_Converter_Exterior' Use os.path.join() to build up the reference workspace = r'C:\Projects\MDC\DataUpdate_20180315\MDC_PhysModel_FieldID_20180315.gdb\Exterior_Electrical'
fcName = 'Phase_Converter_Exterior'
gdfcin = os.path.join(workspace, fcName)
... View more
04-16-2018
10:35 AM
|
0
|
0
|
2261
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|