FeatureLayer.selectFeatures does not work when using a where clause

4928
5
07-25-2013 10:16 AM
RobertMetzger
New Contributor
Hello,

I am trying to select features from a feature layer using a query with a where clause. It returns the correct features, but does not draw them. When I do the same thing but use a query with the geometry property set to a polygon, the correct features are returned AND drawn on the map. How do I get this to draw the feature layer when using a where clause with the query?

Here is my code:

    var featureLayer = new esri.layers.FeatureLayer(arcGisServerUrl + "/" + serviceLayerId, {
        mode: esri.layers.FeatureLayer.MODE_SELECTION,
        outFields: ["*"],
        id: featureLayerName
    });

    var query = new esri.tasks.Query();
    query.outFields = ["*"];
    query.returnGeometry = true;
    query.where = "1=1";

    featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, HandleRouteSelectFeaturesResults);


Thanks!
Rob
0 Kudos
5 Replies
BenFousek
Occasional Contributor III
Rob,

It's strange where and geometry both return features but only geometry derived results draw. Seems like something might be up with your callback function. Try adding a an errback function to see if something is up. This will not only show errors from the server, but will also expose processing errors in the callback function which will otherwise not be logged in the console.

featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, HandleRouteSelectFeaturesResults, errorFunction);


function errorFunction(error) {
  console.log(error)
}


Also, here's a list of mix ins for esri.layers.FeatureLayer modes. Saves quite a bit of space. 😉
featureLayer.selectFeatures(query, 3, callback, errback);

//feature layer modes
//MODE_SNAPSHOT:0
//MODE_ONDEMAND:1
//MODE_SELECTION:2
//SELECTION_NEW:3
//SELECTION_ADD:4
//SELECTION_SUBTRACT:5
//POPUP_NONE:"esriServerHTMLPopupTypeNone"
//POPUP_HTML_TEXT:"esriServerHTMLPopupTypeAsHTMLText"
//POPUP_URL:"esriServerHTMLPopupTypeAsURL"
0 Kudos
KenMorefield
Occasional Contributor
Hmm...
This might be similar to the problem I've been having as outlined in this thread

Maybe it does have something to do with the where clause.  Any thoughts from the ESRI folks?

Ken
0 Kudos
RobertMetzger
New Contributor

Try adding a an errback function to see if something is up. This will not only show errors from the server, but will also expose processing errors in the callback function which will otherwise not be logged in the console.


Thanks for the suggestion. I added an error callback function but it never gets called.
0 Kudos
KellyHutchins
Esri Frequent Contributor
Hi Robert,

I ran a quick test and selecting features using a where clause worked for me. Here's a jsFiddle showing the code:

http://jsfiddle.net/7ukqS/
0 Kudos
RobertMetzger
New Contributor

I ran a quick test and selecting features using a where clause worked for me. Here's a jsFiddle showing the code:

http://jsfiddle.net/7ukqS/


I used the feature layer URL from your example and my code worked. There must be something wrong with my service when using a where clause. I'll have to check with the person who made the service to make sure it is returning the correct data. It always returns the correct features, but there might be something subtly wrong with the geometry. Thanks!
0 Kudos