Hello Everyone,
I have seen a sample Feature Layer Query, where I can type state name and find that State name. I want to do the same thing using ComboBox. When I select anything from drop down, it should select the feature. Can anyone have this sample. Appreciate your support.
Regards,
Krish
Hi Krish,
You can replace the text field that is used for searching with a combo box.
In the Feature Layer sample, go to the file Samples/FeatureLayerQuery.qml, and replace the search text field (the one with id findText) with the combo box:
ComboBox {
z: 10
model: ["California", "New York", "Minnesota", "Colorado", "Michigan"]
onCurrentIndexChanged: {
queryFeatureTable()
}
function queryFeatureTable () {
params.whereClause = "STATE_NAME LIKE '" + model[currentIndex] + "%'";
featureTable.queryFeatures(params);
}
}
When you run the sample this time, you would see a combo box that you can interact with.
Hello Loayeh,
Thanks for your response!
I want to know how to push attributes in combo box from Map service. Please suggest.
Thanks,
Krish
Hi Krish,
Please try this:
1) Once the ServiceFeatureTable is loaded, run a query to get all the features. Add the following code to the ServiceFeatureTable.
onLoadStatusChanged: {
if (loadStatus === Enums.LoadStatusLoaded) {
params.whereClause = "1=1"
featureTable.queryFeatures(params)
}
}
2) The ServiceFeatureTable has a signal handler called onQueryFeatureStatusChanged. In that, once the task is completed, you'll need to check if the completed task is as a result of the code from step 1 above, and then push the results to your combo box. The code to do this will look like this.
onQueryFeaturesStatusChanged: {
if (queryFeaturesStatus === Enums.TaskStatusCompleted) {
if (params.whereClause === "1=1") {
var arr = []
while (queryFeaturesResult.iterator.hasNext) {
arr.push(queryFeaturesResult.iterator.next().attributes.attributeValue('state_name'))
}
comboBox.model = arr
} else {
// Here you will put the code to handle results for when a comboBox item is selected.
// You can paste the existing code from the sample. i.e. the code within the// onQueryFeaturesStatusChanged of the sample
}
}
}