Intended effect
When user clicks on view, hitTest() returns geometry from visible polygons that are to be used in a query by location on localitiesLayer (point features). Code snippet and photo below to demonstrate desired behavior.
view.on("click", function(event) {
selectFeaturesFromClick(event);
});
function selectFeaturesFromClick(clickEvent) {
var includeLayers = [countiesLayer, neighborhoodsLayer, regionsLayer,
clientFeatureLayer]
view.hitTest(clickEvent, {include: includeLayers}).then(function(response) {
if (response.results.length > 0) {
selectFeatures(clickFeature);
}
});
function selectFeatures(feature) {
var geometry = feature.geometry;
var query = {
geometry: geometry,
spatialRelationship: "intersects",
outFields: ["*"],
returnGeometry: true
};
localitiesLayer.queryFeatures(query).then(function(results) {
...
});
});[Image of app with desired behavior (Riverside)]: https://i.stack.imgur.com/BIQrN.png
Issue
When certain features from the hosted feature layer countiesLayer are clicked, the query request cannot be completed with the following error message: "Cannot perform query. Invalid query parameters".
For whatever reason, this seems to occur with most of the features but not with all of them. As shown with the photo above, it works as intended when "Riverside" is clicked but not "Los Angeles" as shown in the image below.
[Image of app displaying bug (Los Angeles]: https://i.stack.imgur.com/Rj80G.png
Troubleshooting
At first I thought it might have something to do with the localityLayer being not loaded at the time of the .query(), but that wouldn't account for the other feature layers working just fine.
I can't seem to figure out what would be different in the features that do seem to work and those that don't. The other feature layers included in the hit test seem to work as expected.
When a LayerView of the localitiesLayer is used for the query, the app works as intended. However I would rather not have to continuously update the a LayerView as it seems to impact performance when users are constantly panning/zooming around the map. And furthermore, I have had issues querying all fields from a LayerView.
Question
Is this specifically related to the way that I have written the hitTest()?
I've included a link to a CodePen with the app for anyone who would like to take a look.
[CodePen of app with bug]: https://codepen.io/dmarkbreiter/pen/BaLLOmq