Select to view content in your preferred language

Selecting a group of features

5502
23
09-18-2015 08:34 AM
DaveSouthern
Deactivated User

I'm looking for a way to use the mouse to select a group of features on a map by dragging a rectangle around them.  I can select a single feature on the map by simply clicking on that feature - that much I have working.  But now I want to be able to drag a rectangle around a group of features and select all of them so I can do something with all of them.  So far I haven't found any code examples out there that discuss this.

0 Kudos
23 Replies
thejuskambi
Frequent Contributor

I am wondering if you are targeting the correct layer. Please ensure the Graphics you intend to select are part of the map.graphics layer and not some other FeatureLayer/GraphicsLayer.

0 Kudos
DaveSouthern
Deactivated User

They are part of a feature layer.  Is that the issue?  If so, how do I target a feature layer?

0 Kudos
thejuskambi
Frequent Contributor

If they are part of Featurelayer then you cannot use map.graphics.graphics. You would have to query or select feature with the methods in FeatureLayer

  var query = new Query();
  query
.geometry = evt.geomtry;
  query
.outFields = [ "*" ];
 
// Query for the features with the given object ID
  featureLayer
.queryFeatures(query, function(featureSet) {

     //TODO: use the features

  });

0 Kudos
DaveSouthern
Deactivated User

OK. So I tried the following:

       var featureLayer = map.getLayer(layerId);
  
        require(["esri/tasks/query"], function (Query) {
            var query = new Query();
            query.geometry = evt.geomtry;
            query.outFields = ["*"];
            // Query for the features with the given object ID
            featureLayer.queryFeatures(query, function (featureSet) {
                //TODO: use the features
            });
        });

But I get the error "Object doesn't support property or method 'queryFeatures'"  So... maybe I don't have a feature layer after all.  What else is there?

0 Kudos