I have an ArcGIS Experience Builder application, which uses a Web Map I host in ArcGIS online. This Web Map contains a feature layer with several attributes, and I can use these in Experience Builder with the stock widgets (i.e. updating dynamic text based on attributes when the user clicks on a certain feature). I am now trying to write a custom widget using Jimu which displays some text when the user clicks on a feature:
jmv.view.on('click', evt => {
const point: Point = jmv.view.toMap({
x: evt.x,
y: evt.y
})
jmv.view.hitTest(evt).then((response) => {
console.log(response.results[0].graphic.attributes)
// Do things with the attributes of the clicked feature
})
})
However, this code only returns the ObjectID
attribute of the clicked feature, and none of the others. How do I access the rest of the features?
1 Answer 1
The outFields
property on the feature layer needs to be set to provide the desired fields before accessing the hitTest
results.
Using a wildcard to enable all fields:
var layer = jmv.view.map.layers.getItemAt(0)
layer.outFields = ["*"]
// hitTest code below
Explore related questions
See similar questions with these tags.