With JS 3x, I was able to do an onclick event on GraphicsLayer. This came is handy for moving the points somewhere else, etc. Is there a way to do this in JS4x? Or is this functionality planned for the future?
Thank you!
Solved! Go to Solution.
Daniel,
View.hitTest is how this is handled in the 4.x API.
// Get the screen point from the view's click event
view.on("click", function (event) {
var screenPoint = {
x: event.x,
y: event.y
};
// Search for graphics at the clicked location
view.hitTest(screenPoint).then(function (response) {
if (response.results.length) {
var graphic = response.results.filter(function (result) {
// check if the graphic belongs to the layer of interest
return result.graphic.layer === myLayer;
})[0].graphic;
// do something with the result graphic
console.log(graphic.attributes);
}
});
});
See this sample:
Access features with pointer events | ArcGIS API for JavaScript 4.10
Daniel,
View.hitTest is how this is handled in the 4.x API.
// Get the screen point from the view's click event
view.on("click", function (event) {
var screenPoint = {
x: event.x,
y: event.y
};
// Search for graphics at the clicked location
view.hitTest(screenPoint).then(function (response) {
if (response.results.length) {
var graphic = response.results.filter(function (result) {
// check if the graphic belongs to the layer of interest
return result.graphic.layer === myLayer;
})[0].graphic;
// do something with the result graphic
console.log(graphic.attributes);
}
});
});
See this sample:
Access features with pointer events | ArcGIS API for JavaScript 4.10