AnsweredAssumed Answered

No returns from selectFeaturesByQuery

Question asked by Haldermir on Aug 17, 2016
Latest reply on Aug 18, 2016 by LDanzinger-esristaff

I'm working on a search function that selects features from a local runtime geodatabase on the device and am currently trying to call an error message when the function fails to return any features.

 

There was a section in a tutorial for querying features that i found which has a response in the GeodatabaseFeatureTable component of the queried table but this section of code never got called (I loaded in console.log() statements which were never displayed when I tested the code). This used an if statement that's similar to the one below:

if(queryFeaturesResult.iterator.hasNext===0){
    message1.visible=true
}

 

The other method that I've tried to call the error message from is the FeatureLayer component by checking the number of selected features when selection query is called however this only loads the message on the clearSelection() function or doesn't load at all.

 

Is there any other way to check for the number of returns?

 

I've copied in the related code below.

 

MainApp{

    GeodatabaseFeatureTable {
        id:tableAddress
        geodatabase: geodatabase.valid ? geodatabase: null
        featureServiceLayerId: 0
    }

    Map {
        id: map

    ...

        FeatureLayer{
            id:address
            featureTable: tableAddress
            visible:false

            function selectID(){
                var buffer = selectedFeatures[0].geometry.buffer(50, "Meters")
                var featureLength = selectedFeatures.length
                if(featureLength === 0){
                    message1.visible = true
                } else if (featureLength === 1){
                    map.zoomTo(buffer)
                } else {
                    message2.visible = true
                }
            }

            onSelectedFeaturesChanged: {
                selectID()
            }
        }
    }
}

SearchFunction {
    id: searchFunction
    anchors {
        left: parent.left
        right: parent.right
        top: headerRect.bottom
    }

    ...

    TextField {
        id:searchQuery
        anchors {
            left: parent.left
            bottom: parent.bottom
            margins: 8
        }
        width: 2*(parent.width/3)
        height: 50
        placeholderText: "2 Fryatt Quay, Wellington"
    }

    Button {
        id: searchFind
        text: "Find"
        enabled: searchQuery.length != 0
        anchors {
            bottom: parent.bottom
            right: searchClose.left
            margins: 8
        }

        Query{
            id:searchQAddress
            where: "\"ADDRESS\" = \'"+ searchQuery.text.toUpperCase()+"\'"
        }

        Query{
            id: searchQRoads
            where: "\"FULL_RD_NM\" = \'" + searchQuery.text + "\'"
        }

        FeatureResult {
            id: queryResult
        }

        onClicked: {
            if (searchTable.currentText === "Addresses"){
                address.clearSelection()
                address.selectFeaturesByQuery(searchQAddress,Enums.SelectionMethodNew)
                console.log(searchQAddress.where)
            } else if (searchTable.currentText === "Roads"){
                road.selectFeaturesByQuery(searchQRoads,Enums.SelectionMethodNew)
            }
        }
    }


    Button {
        id: searchClose
        text: "Close"
        anchors {
            bottom: parent.bottom
            right: parent.right
            margins: 8
        }

        onClicked: {
            closeSearch.running = true
            searchFunction.enabled = false
        }
    }
}

Outcomes