view.on("click", function (event) {
event.stopPropagation();
var htr; // a single result from HitTestResult results[]
view.hitTest(event)
.then(function (response) {
if (response.results.length){
htr = response.results.filter(function (result) {
return result.graphic.layer === lyr;
})[0];
console.log(htr);
if (htr !== undefined){
var arr = [];
arr.push(htr.graphic);
view.popup.open({
location: htr.mapPoint,
features: arr
});
}
}
});
});
I'm using the above hitTest function to check wether the user clicked on a feature that is overlapped by a query result feature and open its popup. It is working fine but when clicking on two or more features at the same time i want the arrow to appear in the popup, so the user can switch through. Is it possible to return more than one result?
Solved! Go to Solution.
Michael,
No the hit test will return one graphic. If you need to get the overlapping graphics you have to do a query using the click point as the queries geometry.
Michael,
No the hit test will return one graphic. If you need to get the overlapping graphics you have to do a query using the click point as the queries geometry.
I have such a query working client-side for any given FeatureLayerView, but how to do the same for a GraphicsLayerView? GraphicsLayerView supports a queryGraphics() method, but this simply returns all records and there is no way to do a client-side filter that leverages a spatial index (geographically comparing all graphics would be too slow).
The MapView.hitTest doc indicates, "At 4.22 and later, a hit test will return *all* graphics from GraphicsLayer that intersect the specified coordinates.". I'm using version 4.22.2 and in my testing it is only returning a single graphic from the GraphicsLayer, and I don't see any option to affect this. IMO the doc seems to be misleading?
I need to use a GraphicsLayer because I want to create a unique CIMSymbol for each feature depending on multiple attributes / complex logic.