queryFeaturesResults undefined

463
3
02-11-2022 11:16 AM
Marie-ClaudeBouchard
New Contributor II

Hello,

We are customizing the AppStudio Offline Geocoding and Routing app with our own data. We would like to add the option of selecting the POIs from a combo box so people can select a POI by name if they don't know its location.

The app is build on a mmpk file which includes a locator and a POI layer. The POI layer is the same used to build the locator. We have tried this, but it seems that it doesn't go through the if so the const result in the loop is not defined. How can I fix the problems?

MobileMapPackage {
    id: mmpk
    path: AppFramework.resolvedPathUrl(copyLocalData(inputdata, outputdata))

    // load the mobile map package
    Component.onCompleted: {
    mmpk.load();
    }
    // wait for the mobile map package to load
     onLoadStatusChanged: {
      if (loadStatus === Enums.LoadStatusLoaded) {
            // set the map view's map to the first map in the mobile map package
            mapView.map = mmpk.maps[0];

    // get POITest feature layer and feature table
    const poiLyr = mapView.map.operationalLayers.get(3);
    const poiTable = poiLyr.featureTable

    // create query parameters object
    let parameters = ArcGISRuntimeEnvironment.createObject("QueryParameters");
    parameters.whereClause = "1-1";

    // query table with parameters
    let query = poiTable.queryFeatures(parameters);

    // get results
    if (query.queryFeaturesStatus === Enums.TaskStatusCompleted){;
        console.log("going through if");
        const result = queryFeaturesResults[query];
    }

    // iterate on results and fill combo box
    const poiList = [];

    while (result.iterator.hasNext()) {
        var feature = iterator.next();
         poiList.push(feature.attributes.attributeValue("Titre"));
    }  

    comboBoxDestination.model = poiList.sort();

     }
   }
}

 

Thanks!

0 Kudos
3 Replies
TrevorFrame
Esri Contributor

Hi @Marie-ClaudeBouchard ,

It seems you might be getting undefined because the parameters.whereClause is "1-1" and should be "1=1".

Hope this helps!

Trevor

0 Kudos
Marie-ClaudeBouchard
New Contributor II

Hello @TrevorFrame,

I corrected my code as suggested. Unfortunately, I still get this error message : ReferenceError: result is not defined  pointing at the line where the While starts. Also, I don't get a return on this console.log("going through if") so it seems the if is skipped.

Other suggestions? Thanks for your help!

MC

0 Kudos
TrevorFrame
Esri Contributor

@Marie-ClaudeBouchard sorry I didn't catch your reply sooner. Another thing I noticed is you're declaring the result in the if statement and then trying to access it outside of the if statement, which would cause the ReferenceError: result is not defined. 

As for the if statement being skipped, that's probably due to the query status not being completed yet when being checked. When creating the table on the fly like you did, you should use Connections to setup signal handlers so when the queryFeatureStatus changes, that's when you can iterate through the if statement. Check out this YouTube video to see an example of using Connections. 

0 Kudos