AnsweredAssumed Answered

Select features by draw tool with where clause in query?

Question asked by MollyKFoley on May 18, 2018
Latest reply on May 18, 2018 by MollyKFoley

I'm not sure this is possible, but what I'd like to do is allow users to draw a bounding polygon around a bunch of features, and then of those features, only select the ones where an attribute equals a particular value. When you select the patches using the draw tool, you create a query and set the geometry to whatever the drawn polygon encompasses, but it doesn't appear any attributes of the features are returned on draw-complete so I'm not sure using a where clause with that query will work? This is what I have tried.

 

//Create selection by drawing on map
function selectPatches(selectionType) {
    var selectTool = new Draw(map);
    selectTool.activate(Draw.POLYGON);
    attrTableSpinner.show();
    //Deactivate popups when drawing
    map.setInfoWindowOnClick(false);
    var selectQuery = new Query();

    on(selectTool, "draw-complete", function (Geom) {
        selectTool.deactivate();
        selectQuery.geometry = Geom.geometry;
        //Select all patches within the bounding polygon
        if (selectionType == "selectAll") {
            patchesFL.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW);
        }
        //Select only patches that are designated as quail habitat in the bounding polygon
        else {
            selectQuery.where = "OfficalQH = 1";
            patchesFL.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW);
        }
        //Reactivate popups when done drawing
        map.setInfoWindowOnClick(true);
    });
};

Outcomes