Can the results of a query be placed in a FeatureLayer instead of a GraphicsLayer?

2202
21
Jump to solution
10-12-2018 12:35 PM
JohnRichardson
New Contributor III

I currently have a featurelayer being queried, and the results placed in a graphicslayer ... I am hoping that the results can be placed in a new featurelayer instead?

Here is current code:

$("#radio-4").click(function() {                       //shows only January crimes
      var sr = new SpatialReference(102100);

      janResults = new GraphicsLayer();
      janResults.title = "January";
      map.add(janResults);
      var janQuery = featurelayer.createQuery(); 
                                                                                    
      janQuery.where = "Month = 'January'";
      janQuery.outFields = ["Offense" , "Location"];
      janQuery.returnGeometry = true;
      janQuery.outSpatialReference = sr;

      featurelayer.queryFeatures(janQuery).then(displayGraphics);
      
      function displayGraphics(results) {

            janResults.removeAll();

            for (feature of results.features) {
                  var janGraphic = new Graphic ({
                        geometry: feature.geometry,
                        symbol: {
                              type: "simple-marker",
                              color: "blue",
                              size: "20px",
                              outline: {
                                    color:"black",
                                    width: 2,
                              },
                        },
                  });
                  janResults.add(janGraphic);
            }

      }
     
});  //end of January query
0 Kudos
21 Replies
RobertScheitlin__GISP
MVP Emeritus

Ahh. I did not think about that since you had it in your original code.

0 Kudos
JohnRichardson
New Contributor III

Thanks again!

0 Kudos