Create a FeatureLayer with client-side graphics, attributes missing

518
3
Jump to solution
06-20-2019 01:46 PM
XiaowenHuang
New Contributor

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?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

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
            });

View solution in original post

3 Replies
DavidWilson3
Occasional Contributor

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.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

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
            });
XiaowenHuang
New Contributor

Thanks! adding "fields: layer.layerDefinition.fields" solved the issue.

0 Kudos