Select to view content in your preferred language

Failing to query attributes of custom LayerView

393
1
Jump to solution
06-13-2022 02:19 PM
TonyGraham
Occasional Contributor

I'm generating and adding graphics to a client-side feature layer, but, after the LayerView updates, I cannot query on all of its attributes--only on its OBJECTID.  Why am I not getting any other attributes?

To the "Create a FeatureLayer with client-side graphics" example, I have added the following snippet in addToView().  (See Codepen.)

view.whenLayerView(layer).then(lyrView => {
    lyrView.watch("updating", updating => {
        if (!updating) {
            console.error("Assert > 1 availableFields", lyrView.availableFields.length > 1);
            lyrView.queryFeatures({outFields: ["OBJECTID","url"]}).then((graphics)=>{
                console.error("Assert _any_ graphics have an 'OBJECTID' attribute", graphics.features.filter(f => {return f.attributes["OBJECTID"]}).length > 0);
                console.error("Assert _any_ graphics have a 'url' attribute", graphics.features.filter(f => {return f.attributes["url"]}).length > 0);
            })
        }
    });
});
 
The console output I receive follows:
 

Assert > 1 availableFields false

_Any_ graphics have an 'OBJECTID' attribute true

_Any_ graphics have a 'url' attribute false

I expected to see availableFields having a length of 2 and to find "url" attributes in the query results.

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

You'll need to add the outFields parameter to your layer's constructor:

outFields: ["OBJECTID","url"],

 

This is somewhat implied by the documentation for the availableFields property.

View solution in original post

1 Reply
JoelBennett
MVP Regular Contributor

You'll need to add the outFields parameter to your layer's constructor:

outFields: ["OBJECTID","url"],

 

This is somewhat implied by the documentation for the availableFields property.