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
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!
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.