1

When my app changes context (user clicks on a tab) I want to programmatically "Select" the first of 6 points in my Feature Layer so I get the blue box around the point and activate the info window.

I looked around the API Docs and found the FeatureLayer's selectFeatures method. This method takes a Query object, and a selection method (I'm creating a new selection so I'll use SELECTION_NEW). The function returns a promise, but do I really need any kind of callback? I'm just trying to select a feature.

Here is the definition of my feature layer:

var projectsAGOL = new esri.layers.FeatureLayer("http://services.arcgis.com/QVENGdaPbd4LUkLV/arcgis/rest/services/rioLocoSites/FeatureServer/0",{ 
    infoTemplate: infoTemplate,
    visible: true,
    outFields: ["*"]
});

Click handler for the Tab:

jQuery("#prjMap").click(function(){
    var query = new esri.tasks.Query(); // Create a Query Object
    query.where = "OBJECTID = 0"; // Select the first point from the Feature Layer
    projectsAGOL.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW); // Apply selection
});

This code does not produce the desired outcome nor does it produce an error. Nothing happens. Am I even using the correct method to make a selection? I'm more familiar with the Leafletjs mapping library.

Update: Provided jsFiddle

2

Try this:

jQuery("#prjMap").click(function(){
    var projectsAGOL = new esri.layers.FeatureLayer("http://services.arcgis.com/.../FeatureServer/0",{ 
        infoTemplate: infoTemplate,
        visible: true,
        outFields: ["*"]
    });

    var query = new esri.tasks.Query(); // Create a Query Object
    query.where = "FID= 0"; // Select the first point from the Feature Layer
    query.returnGeometry = true;
    query.outFields = ["*"]; // Return all attributes in the FeatureSet

    var selectionSymbol = new SimpleFillSymbol().setColor(new Color([255,255,0,0.5]));
    featureLayer.setSelectionSymbol(selectionSymbol); 
    projectsAGOL.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
}
  • Would you be able to expand upon this Answer, please? Normally "about a paragraph" is considered as the minimum length for Answers (and Questions). – PolyGeo Apr 25 '14 at 0:17
  • @Matej In the QueryTask constructor are you passing in the url of the feature service? – Roy May 2 '14 at 16:42
  • @Roy: Yes, feature service or dynamic map service url – Matej May 2 '14 at 16:44
  • @Matej I'm still not able to make the selection. Perhaps you could take a look at this jsfiddle? – Roy May 5 '14 at 12:22
  • @Roy: Sorry, I might have confused you: featureSet = queryTask.execute(query); returns a deferred object. To get the feature itself, use: when(featureSet , function (result) { console.log(result); }); The "result" object represents a returned feature set from the query . – Matej May 5 '14 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.