Home > Back-end >  Display field attributes from a layer included in a mmpk
Display field attributes from a layer included in a mmpk

Time:02-12

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 tried many things, but whatever we do to access the POI name contained in the field "Titre" from the table "POITest" of the mmpk, it seems that the table is undefined. Since it is an offline with the mmpk build in in the app, we are not sure how to "define" the data. The file in attachment shows the issues. Would it be easier to get the same info from the locator and how? Any ideas/suggestions to help us?

Thanks for your help,

Marie-Claude

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];

        var poiLyr = mapView.map.operationalLayers.get(3)
        var poiLyrName = poiLyr.name
        var poiTable = poiLyr.featureTable
        var poiTableName = poiTable.displayName
        console.log("1:", poiLyr, "2:",poiLyrName, "3:",poiTable, "4:",poiTableName)

        var poiField = poiTable.fields["Titre"]
        console.log("5:", poiField)
    }
}

}

console.log() qml: 1: QmlFeatureLayer(0x2270237a2b0) 2: POITest 3: QmlGeodatabaseFeatureTable(0x22702603760) 4: POITest qml: 5: undefined

CodePudding user response:

If you are trying to access the field definition of "Titre", which will provide you with limited information as: the type of the field, if it is nullable, etc.., then instead of this line

var poiField = poiTable.fields["Titre"]

you can use the .field("Titre") to access it, which returns a Field type.

Otherwise, if your aim is to to display all of the values of the "Titre" field in your table, you would first need to query the table. This sample gives some example of querying feature data: https://github.com/Esri/arcgis-runtime-samples-qt/blob/main/ArcGISRuntimeSDKQt_QMLSamples/Features/FeatureLayer_Query/FeatureLayer_Query.qml

Basically, you would need to:

  • Create a QueryParameters object that defines the features you want. In your case, you could set the whereClause to "1=1" because you want to fetch all features.
  • Pass the QueryParameters to the queryFeatures method of your feature table.
  • Grab the queryFeaturesResult once that operation completes.
  • Iterate over the features in your result and add the value for the "Titre" attribute to your combo-box.

CodePudding user response:

I have very little experience with qml. Here is what I have tried. When it gets to this line : while (result.iterator.hasNext()), an error message is returned saying ReferenceError: result is not defined. It looks like it doesn't go through the if. Any idea of the problem?

const poiLyr = mapView.map.operationalLayers.get(3);
const poiTable = poiLyr.featureTable

let parameters = ArcGISRuntimeEnvironment.createObject("QueryParameters");
parameters.whereClause = "1-1"

let query = poiTable.queryFeatures(parameters);

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

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