Select to view content in your preferred language

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

487
2
12-24-2023 11:29 PM
csyuserchen
New Contributor

Hi,

I create a FeatureLayer from an array of client-side features, This is how that looks like:

 

function FeatureLayer(){
const graphic = new Graphic({
geometry: {
type: 'point',
longitude: -118.80657463861,
latitude: 34.0005930608889
},
symbol:{
type: "simple-marker",
color: [226, 119, 40], // Orange
outline: {
color: [255, 255, 255], // White
width: 1
}
},
attributes: {id: '123'},
})
const featureLayer= new FeatureLayer({
source: [graphic],
objectIdField: "OBJECTID",
outfields: ["id"],
fields: [{
name: "OBJECTID",
type: "oid"
}, {
name: "id",
type: "string"
}],
renderer: {
type: "simple",
symbol:{
type: "simple-marker",
color: [226, 119, 40], // Orange
outline: {
color: [255, 255, 255], // White
width: 1
}
},
}
});
map.add(featureLayer);
}

 

and then I Listen the click event,log the attributes,but it only has OBJECTID

csyuserchen_0-1703487741423.png

 

 

view.on('click', (event) => {
        view.hitTest(event).then((response) => {
          console.log(response.results[0].graphic).attributes
        })

 

 

this is my code in codesandbox:https://codesandbox.io/p/sandbox/arcgis-featurelayer-attributes-2hnm7d?file=%2Findex.html%3A50%2C12 

Thanks in advance!

0 Kudos
2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

FeatureLayer's outFields property has a wrong casing in your code. Please change it from 

 

outfields: ["id"],

 

 to 

 

outFields: ["id"],

 

Then it should work as expected.

0 Kudos
ViktorSafar
Frequent Contributor

@UndralBatsukh ment to write (use asterisk to represent "all fields")

outFields: ["*"],

 

0 Kudos