selectFeatures only returning "top" feature of overlapping features

1175
10
Jump to solution
03-19-2012 08:22 AM
ChadWilcomb
New Contributor III
I am using the selectFeatures function to launch a popup when clicking on a feature. Because of the nature of my data, many of the features (street segments) have coincident geometry (they are stacked on top of each other). When I click on one of these segments that I know has multiple coincident features, the selectFeatures function only returns one feature (assuming the "top" one). If the features are adjacent (within my 10 pixel click buffer) but not coincident, it returns multiple features.

How can I have the selectFeatures return all features at that location, not just the one?

dojo.connect(map, "onClick", function (evt) {     var query = new esri.tasks.Query();     query.geometry = pointToExtent(map, evt.mapPoint, 10); //buffers click point by number of pixels(10)      var deferred = featureLayerSeg.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);     deferred.addCallback(function (features) {          console.log(features.length); //this returns 1 if the features are stacked on top of each other     }); }


PS- I don't want to use IdentifyTask to a map service because these feature layers have already been filtered by the user based on search parameters.
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
0 Kudos
10 Replies
JeffPace
MVP Alum
Are you using on_demand mode for your feature layer? if so auto-generalize is true by default.  I wonder if this is interfering with your selection.  Try setting auto-generalize to false.


I am using the selectFeatures function to launch a popup when clicking on a feature. Because of the nature of my data, many of the features (street segments) have coincident geometry (they are stacked on top of each other). When I click on one of these segments that I know has multiple coincident features, the selectFeatures function only returns one feature (assuming the "top" one). If the features are adjacent (within my 10 pixel click buffer) but not coincident, it returns multiple features.

How can I have the selectFeatures return all features at that location, not just the one?

dojo.connect(map, "onClick", function (evt) {
    var query = new esri.tasks.Query();
    query.geometry = pointToExtent(map, evt.mapPoint, 10); //buffers click point by number of pixels(10)

    var deferred = featureLayerSeg.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
    deferred.addCallback(function (features) {
         console.log(features.length); //this returns 1 if the features are stacked on top of each other
    });
}


PS- I don't want to use IdentifyTask to a map service because these feature layers have already been filtered by the user based on search parameters.
0 Kudos
ChadWilcomb
New Contributor III
Hi Jeff, thanks for your response. That seems like it would cause the same result I am seeing. However, I am using SNAPSHOT mode. I tried using .setAutoGeneralize(false) on my FeatureLayer before applying the setDefinitionExpression but it didn't make any difference.
0 Kudos
JeffPace
MVP Alum
Hi Jeff, thanks for your response. That seems like it would cause the same result I am seeing. However, I am using SNAPSHOT mode. I tried using .setAutoGeneralize(false) on my FeatureLayer before applying the setDefinitionExpression but it didn't make any difference.


Yes snapshot mode kinda rules that out. Can you try two things?

1. Identify in the mxd.  Make sure its really there.
2. Run a geometry query on the rest service . 

If both of those return the multiple overlapping results, you may have found a bug in the feature layer.  You could also try switching to on_demand mode and disabling autogeneralize also just for troubleshooting.
0 Kudos
ChadWilcomb
New Contributor III
Jeff, those were good suggestions. I have confirmed that the features are there in the MXD. A query on the REST service using the same extents from my mouse click returns the 10 features that I expect to get from selectFeatures. I can see the JSON returned from the original feature request with the 10 features as well.

When I look at the one feature that is returned from the following code in the Console, I see it has a _count property that is always the number of features I expect to get +1. I can't really explain why it has the +1, but other than that it is correct (ie- if I click on a segment that should have 10 features, _count = 11, if it should have 1 feature, _count = 2) I have attached a screenshot of Firebug Console showing the feature object returned by the following code:

            var deferred = featureLayerSeg.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
            deferred.addCallback(function (features) {
                console.log(features.length);
                for(var i=0; i < features.length; i++) {
                    console.log(features); //returns only one feature to Console- see attached screenshot
                }

            });


Thanks again for your suggestions, much appreciated.

[ATTACH=CONFIG]12825[/ATTACH]
0 Kudos
ChadWilcomb
New Contributor III
Oh, I also tried MODE_ONDEMAND with setAutoGeneralize(false) but that gave the same results.

Also, this property gives me the correct number of features: _graphicsLayer._counter.value but I still don't see the attributes of all 6 features anywhere in the object.
0 Kudos
derekswingley1
Frequent Contributor
I'm able to get this to work. More info:  http://gis.stackexchange.com/a/22098/124
0 Kudos
ConstanceDavisson
New Contributor
I'm able to get this to work. More info:  http://gis.stackexchange.com/a/22098/124


Useful?
0 Kudos
derekswingley1
Frequent Contributor
Useful?


Care you to elaborate? I don't follow...
0 Kudos
ChadWilcomb
New Contributor III
I'm able to get this to work. More info:  http://gis.stackexchange.com/a/22098/124


Thanks again Derek! The OBJECTID field in my map service was not unique. Once I fixed that issue, the selectFeatures is behaving as expected (returning multiple features).
0 Kudos