Where can I set the attributes that are added to the Graphic on the Featurelayer in a WebMap

86
0
04-22-2020 03:38 AM
PHerk
by
New Contributor II

Working on a project for my customer. I use this code to get information about the features on the WebMap when I click on a feature:

     view.on("click", function(event){
         view.hitTest(event.screenPoint)
           .then(function(response){
           graphic = response.results[0].graphic;
           if (graphic) {
             console.log(JSON.stringify(response));

         // more code here...
           }
         });
     });

The project has 3 layers and about 8 attributes. So I want to know to which layer the feature belongs when clicked.

The first layer gives me in the attributes: 

"attributes": {
"OBJECTID_1": 56495,
"gewascateg": "Grasland"
},

The second layer gives me in the attributes: 

"attributes": {
"FID": 18
},

The third layer gives me in the attributes: 

"attributes": {
"FID": 45
},

I would like to add another field in the attributes, that has a unique name, for layer 2 and 3 and is present in the Graphic

Only the FID is present.

Right now, there is nothing to determine which layer belongs to the FID.

The first layer shows more attributes can be set.

Both layers can have the same FID numbers (only unique within the layer) but can be assigned to different area's / features.

The first layer shows, more attributes can be set, but I have no clue where to set which attribute comes with the Graphic.

Where can I set which attribute is assigned to the Graphic?

This is the total result on a click in JSON string format:

{
"screenPoint": {
"x": 843,
"y": 225
},
"results": [{
"mapPoint": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"x": 611540.7659679214,
"y": 6729471.200288476
},
"graphic": {
"geometry": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"rings": [
[
[611591.7725636219, 6729429.978571325],
[611543.9994209437, 6729434.755885593],
[611472.3397069264, 6729439.533199861],
[611505.7809068011, 6729525.524856682],
[611548.7767352115, 6729520.747542414],
[611553.5540494793, 6729515.970228146],
[611563.108678015, 6729515.970228146],
[611567.8859922828, 6729525.524856682],
[611567.8859922828, 6729530.30217095],
[611572.6633065506, 6729544.634113753],
[611625.2137634966, 6729539.856799485],
[611629.9910777644, 6729530.302170949],
[611610.8818206931, 6729463.419771199],
[611591.7725636219, 6729429.978571325]
]
]
},
"symbol": null,
"attributes": {
"FID": 45
},
"popupTemplate": null
}
}, {
"mapPoint": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"x": 611540.7659679214,
"y": 6729471.200288476
},
"graphic": {
"geometry": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"rings": [
[
[611591.7725636242, 6729429.978571325],
[611543.999420946, 6729434.755885593],
[611472.3397069287, 6729439.533199861],
[611505.7809068034, 6729525.524856682],
[611548.7767352138, 6729520.747542414],
[611553.5540494816, 6729515.970228146],
[611563.1086780173, 6729515.970228146],
[611567.8859922851, 6729525.524856682],
[611567.8859922851, 6729530.30217095],
[611572.6633065529, 6729544.634113753],
[611625.2137634989, 6729539.856799485],
[611629.9910777668, 6729530.302170949],
[611610.8818206955, 6729463.419771199],
[611591.7725636242, 6729429.978571325]
]
]
},
"symbol": null,
"attributes": {
"FID": 18
},
"popupTemplate": null
}
}, {
"mapPoint": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"x": 611540.7659679214,
"y": 6729471.200288476
},
"graphic": {
"geometry": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"rings": [
[
[611591.7725636219, 6729429.978571325],
[611543.9994209437, 6729434.755885593],
[611472.3397069264, 6729439.533199861],
[611505.7809068011, 6729525.524856682],
[611548.7767352115, 6729520.747542414],
[611553.5540494793, 6729515.970228146],
[611563.108678015, 6729515.970228146],
[611567.8859922828, 6729525.524856682],
[611567.8859922828, 6729530.30217095],
[611572.6633065506, 6729544.634113753],
[611625.2137634966, 6729539.856799485],
[611629.9910777644, 6729530.302170949],
[611610.8818206931, 6729463.419771199],
[611591.7725636219, 6729429.978571325]
]
]
},
"symbol": null,
"attributes": {
"OBJECTID_1": 56495,
"gewascateg": "Grasland"
},
"popupTemplate": null
}
}]
}

0 Kudos
0 Replies