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

2219
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

John,

 Change the renderer to this:

      var sRenderer = {
        type: "simple", // autocasts as new SimpleRenderer()
        symbol: {
          type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
          size: "20px",
          color: "blue",
          style: "circle",
          outline: {
            width: 2,
            color: "black"
          }
        }
      };
0 Kudos
JohnRichardson
New Contributor III

Still no go

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

still no errors?

0 Kudos
JohnRichardson
New Contributor III

nope

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   David over in this thread just used the graphics directly from the query.

https://community.esri.com/thread/222737-can-the-results-of-a-query-be-placed-in-a-featurelayer-inst... 

0 Kudos
JohnRichardson
New Contributor III

How do you mean?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

look at that thread.

0 Kudos
JohnRichardson
New Contributor III

I tried, but the link took me to another version of my own thread

0 Kudos
JohnRichardson
New Contributor III

Robert ... after all of that, it was the spatial reference ... I had omitted the line at the top of my function that set the output spatial reference to 102100!

0 Kudos