AnsweredAssumed Answered

Select Map Feature from Grid

Question asked by jay.kapalczynski on Mar 31, 2017
Latest reply on Apr 1, 2017 by rscheitlin

I have a query Task that is running and creating a NEW graphics layer and displaying that in the map along with all the records from the query being displayed in a grid.

 

I now want to select the Feature in the map based on an ID select in the table.  My example is a bit different than the ESRI example in that I don't have a Feature Layer Defined.  I am querying the data and creating a Graphics Layer.  I am trying the below and cant seem to get it working...

 

Thoughts?

 

queryTask.on("complete", function(event) {
   var highlightSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
   new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
   new Color([255, 0, 0]), 3), new Color([125, 125, 125, 0.35]));

   var symbol = new SimpleMarkerSymbol({
      // SNIP  Remove code for this example
   });
   var features = event.featureSet.features;
   var countiesGraphicsLayer = new GraphicsLayer();
   var featureCount = features.length;
   map.graphics.clear();
   for (var i = 0; i < featureCount; i++) {
      var graphic = features[i]; //Feature is a graphic
      graphic.setSymbol(symbol);
      graphic.setInfoTemplate(infoTemplate);
      map.graphics.add(graphic);
   }
});


// fires when a row in the dgrid is clicked
   function selectState(e) {
     var fl = map.getLayer("countiesGraphicsLayer");
        fl.setSelectionSymbol(new SimpleFillSymbol().setOutline(null).setColor("#AEC7E3"));
        var query = new Query();
        query.objectIds = [parseInt(e.target.innerHTML, 10)];
            fl.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(result) {
              if ( result.length ) {
                // re-center the map to the selected feature
                window.map.centerAt(result[0].geometry.getExtent().getCenter());
              } else {
                console.log("Feature Layer query returned no features... ", result);
              }
            });
    }

Outcomes