Thank you Nakul! I got it working, here is my code in case it helps others. Any suggestions for code cleanup are welcome.
I put my ServiceFeatureTable and QueryParameter objects right outside of the map view.
//Feature service for spatial query
ServiceFeatureTable {
id: countyBoundary
url: "https://hangis.hanoverva.gov/arcgis/rest/services/county_boundary/MapServer/0"
onQueryFeaturesStatusChanged: {
if (queryFeaturesStatus === Enums.TaskStatusCompleted) {
if (!queryFeaturesResult.iterator.hasNext) {
errorMsgDialog.visible = true;
return;
}
//Create array for features
var features = []
// get the features
while (queryFeaturesResult.iterator.hasNext) {
features.push(queryFeaturesResult.iterator.next());
}
//Since there is only one feature get the feature at the first index & retrieve geometry property
var countyGeometry = features[0].geometry
console.log("countyGeometry", countyGeometry)
//Get the current map point
var newPoint = mapView.currentViewpointCenter.center
console.log("newPoint", newPoint)
//Check to see if currrent point is within county boundary
var withinCounty = GeometryEngine.within(newPoint, countyGeometry)
console.log("withinCounty", withinCounty)
//If the point is within the county boundary, run nextPage function
if(withinCounty === true) {
nextPage();
}
//If not show alert box and do not continue to next page
else {
invalidGeometryAlertBox.text = qsTr("Invalid entry.");
invalidGeometryAlertBox.informativeText = qsTr("User must be within county boundary.")+"\n";
invalidGeometryAlertBox.visible = true;
}
}
}
}
//Parameters for query
QueryParameters {
id: queryParameters
//Query the first feature in the feature service
whereClause: "1=1"
//Whether feature geometries are returned in the result
returnGeometry: true
}
Then I edited the Next button, so it runs the query instead of going straight to the next page:
onClicked: {
if(app.captureType=="point") {
//Run query to do geometry check
countyBoundary.queryFeatures(queryParameters);
} else {
invalidGeometryAlertBox.text = qsTr("Invalid geometry. Continue?");
invalidGeometryAlertBox.informativeText = qsTr("You can always save as draft and edit later.")+"\n";
invalidGeometryAlertBox.visible = true;
}
}