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.
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.
They are part of a feature layer. Is that the issue? If so, how do I target a feature layer?
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
});
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?