I use the following sample to add a shapefile to FeatureLayer but attributes won't carry over.
ArcGIS API for JavaScript Sandbox
Any idea how I can retain all attributes from shapefile?
Solved! Go to Solution.
You just need to specify the Feature Layers fields and outFields properties in that sample.
var featureLayer = new FeatureLayer({
popupTemplate: popupTemplate,
objectIdField: "FID",
source: graphics,
outFields: ['*'],
fields: layer.layerDefinition.fields
});
Hi Xiaowen,
Do you have screenshots or code you can share? Off the top of my head I would think that perhaps your shapefile is not a zip folder or your zip folder does not have all the necessary files in it to draw it with attributes.
You just need to specify the Feature Layers fields and outFields properties in that sample.
var featureLayer = new FeatureLayer({
popupTemplate: popupTemplate,
objectIdField: "FID",
source: graphics,
outFields: ['*'],
fields: layer.layerDefinition.fields
});
Thanks! adding "fields: layer.layerDefinition.fields" solved the issue.