Push Attribute Values of FS/MS in ComboBox

508
3
11-15-2017 06:24 AM
KrishV
by
Occasional Contributor III

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

Tags (2)
0 Kudos
3 Replies
LoayehJumbam
New Contributor II

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.

KrishV
by
Occasional Contributor III

Hello Loayeh, 

Thanks for your response!

 

I want to know how to push attributes in combo box from Map service. Please suggest.

Thanks, 

Krish

0 Kudos
LoayehJumbam
New Contributor II

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
        }
    }
}

0 Kudos