Not all attributes for graphic(s) are returned when querying FeatureLayer

1502
4
Jump to solution
12-22-2020 04:54 AM
Namibian
New Contributor II

Hi,

I am creating a FeatureLayer containing Point graphics client-side from data retrieved from my database. This is how that looks like:

const pointLayer = new FeatureLayer({
  id: unitType.unitTypeName.replace(' ', '-'),
  source: pointGraphics,
  fields: layerSchema,
  renderer: {
     type: 'unique-value', // autocasts as new UniqueValueRenderer()
     field: 'unitId',
     uniqueValueInfos: [...infos.values()]
  }
});

pointGraphics is an array of graphics with each graphic defined as follows:

const g = new Graphic({
   geometry: {
      type: 'point', // autocasts as new Point()
      longitude: unit.point.geometry.coordinates[0],
      latitude: unit.point.geometry.coordinates[1]
   },
   attributes: {
      OBJECTID: objectCounter,
      unitId: unit.unitId,
      areaId: unit.assignment.areaId,
      areaColor: unit.assignment.config.color
   }
});

layersSchema which represents the fields is defined like so:

const layerSchema = [{
       name: 'OBJECTID',
       type: 'oid'
   }, {
       name: 'unitId',
       type: 'string'
   }, {
       name: 'areaId',
       type: 'string'
   }, {
       name: 'areaColor',
       type: 'string'
   }
];

and lastly, infos is defined as a Map from which the values() is extracted for the uniqueValuesInfos:

infos.set(unit.unitId, {
   value: unit.unitId,
   symbol: {
      type: 'simple-marker',
      color: unit.assignment.config.color,
      outline: { // autocasts as new SimpleLineSymbol()
          color: 'grey',
          width: 0.5
      },
      style: overlay.pointStyle.toLowerCase(),
      size: overlay.pointSize
   }
});

 

The layer renders correctly with each graphic representing a unit, colored correctly based on the unit's assignment.

I query the layer using a graphic . The query is defined like so:

// create a query and set its geometry parameter to the
// polygon that was drawn on the view
const query = {
   geometry: graphic.geometry,
   spatialRelationship: 'contains',
   outFields: ['*']
};

I then highlight the selected feature(s) like this:

viewLayer.queryFeatures(query)
   .then((results) => {
        graphics = graphics.concat(results.features);
        if (graphics.length > 0) {
            // highlight query results
            this.highlight.push(viewLayer.highlight(graphics));
        }
});

The selected features highlights correctly as expected

When I look at the attribute property of any of the graphics return from the query, it only show the 'OBJECTID' and the 'unitId' attributes, and not all the attributes as defined above.

  1. Is this expected behavior? 
  2. What do I need to define differently to be able to see ALL attributes when query returns?

Right now, I have to use the 'OBJECTID' and the perform another find operation on the associated layer's source to retrieve all the other attributes

Thanks in advance!

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

Not sure without a codepen/jsbin/other, but you might try setting the 'outFields' parameter of the layer (or maybe the Query) to an explicit list of field names (don't use "*").  If using a FeatureLayerView, check the 'availableFields' parameter before calling queryFeatures(...).

View solution in original post

4 Replies
Namibian
New Contributor II
Thanks for your response.
0 Kudos
JohnGrayson
Esri Regular Contributor

Not sure without a codepen/jsbin/other, but you might try setting the 'outFields' parameter of the layer (or maybe the Query) to an explicit list of field names (don't use "*").  If using a FeatureLayerView, check the 'availableFields' parameter before calling queryFeatures(...).

Namibian
New Contributor II

Setting the outFields to a discrete list did the trick!

0 Kudos