AnsweredAssumed Answered

Help with Javascript basics?

Question asked by john_richardson_1969 on Oct 16, 2018
Latest reply on Oct 17, 2018 by john_richardson_1969



My question this time is more of a javascript issue, than it is an ArcGIS API issue ... if this post needs deleted or moved, please let me know.


I have the following segment of code, which creates a feature layer based on a query of crime points ... showing only crimes that happened in January ... suppose I wanted to do the same thing for the rest of the months of the year, but obviously don't want to replicate the code ... could someone steer me? Many thanks to Robert Scheitlin for helping with the original code!





$("#radio-4").click(function() {  //creates a feature layer of January only crimes
      var sr = new SpatialReference(102100);
      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"
          var graArr = [];
          var janQuery = featurelayer.createQuery();
          janQuery.where = "Month = 'January'";
          janQuery.outFields = ["Offense" , "Location"];
          janQuery.returnGeometry = true;
          janQuery.outSpatialReference = sr;
          function displayGraphics(results) {
            for (feature of results.features) {
              var janGraphic = new Graphic ({
                geometry: feature.geometry,
                attributes: {
                  Offense: feature.attributes.Offense,
                  Location: feature.attributes.Location
          function createLayer(graphics) {
            var fields = [{
              name: "ObjectID",
              alias: "ObjectID",
              type: "oid"
            }, {
              name: "Offense",
              alias: "Offense",
              type: "string"
            }, {
              name: "Location",
              alias: "Location",
              type: "string"
            layer = new FeatureLayer({
              geometryType: "point",
              title: "January",
              source: graphics,
              fields: fields,
              objectIdField: "ObjectID",
              renderer: sRenderer,
      }); //end of show January crimes only