Why doesn't the mapview.hitTest method return any results?
Consider the simple example below:
If you modify this sample:
Access features with pointer events | ArcGIS API for JavaScript 4.5
and add the opacity property to the feature layer like this
...
var layer = new FeatureLayer({
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/1",
opacity: .4,
outFields: ["*"]
});...
The hit test response will not contain and values in the results array.
Here is a jsbin link showing what I am talking about:
Jack,
that is definitely a bug because when you revert back to 4.4 it works.
Yeah, looks like a bug to me. Seems that anything less than 1.0 opacity doesn't work with hitTest in a MapView.
What can I expect for a bug fix like this? Do I have to wait for 4.6 for a fix?
I'm not sure.
You could use something like this for the time being:
// evt: ClickEvent, view: MapView
function getFeatures(evt, view){
const pxRatio = view.extent.width / view.width,
// number of pixels to check in
pixelBuffer = 6,
halfExtent = pxRatio * pixelBuffer,
clickExtent = new Extent({
xmin: evt.mapPoint.x - halfExtent,
xmax: evt.mapPoint.x + halfExtent,
ymin: evt.mapPoint.y - halfExtent,
ymax: evt.mapPoint.y + halfExtent,
spatialReference: view.extent.spatialReference
});
let queries = view.layerViews.map(lv => {
let q = lv.layer.createQuery();
q.geometry = clickExtent;
q.geometryType = "esriGeometryEnvelope";
q.outFields = null;
q.where = null;
return lv.queryFeatures(q);
}).toArray();
return Promise.all(queries).then(results => {
return [].concat.apply([], results);
});
}
example: JS Bin - Collaborative JavaScript Debugging
This won't work as well as hitTest. If you rely on this, it may be better to stick with 4.4 for the time being.
Thanks for the work around. This doesn't seem to be fully working either unfortunately though. Try clicking the biggest bubble in the example on the bottom right side. It doesn't log any results. Is there a place where I can track a bug like this and watch for fixes?
Another workaround that seems to work is setting the layer's opacity to 1.0 but using a renderer to specify a symbol with opacity less than 1.0. This doesn't seem to interfere with hitTest: https://codepen.io/solowt/pen/PJJLrw?editors=1000#0
I reported the issue and I'll post here if I learn when it's going to be fixed.
This does work as a temporary work around. Thanks Thomas.
Looks like this will be fixed in 4.6, sometime in early December.
Thanks for following up on this Thomas.