Select to view content in your preferred language

Populate new feature attribute table, sequential numbering

596
6
Jump to solution
04-30-2014 03:59 AM
williamcarr
Frequent Contributor
I am attempting to add sequential numbering to newly added graphics, but I'm a little lost on logic. Would this be possible with an i = i + 1 loop? Basically I need to populate an attribute field of a feature layer with a prefix and a number (J1, J2, J3 ect.)
0 Kudos
1 Solution

Accepted Solutions
LoriGonzalez
Deactivated User
How about this
 var i = 0;        function addGraphic(pt) {            console.log("addingGraphic");            i++;            var symbol = new SimpleMarkerSymbol( SimpleMarkerSymbol.STYLE_CIRCLE,12);             var template = new InfoTemplate("results", "${*}");                           var attr = {};            attr["asdf"] = "J" + i;             var graphic = new Graphic(pt, symbol, attr,template);            map.graphics.add(graphic);                                 //featureLayer.applyEdits([graphic], null, null);            //console.log(" Fire on everything!");        }

View solution in original post

0 Kudos
6 Replies
LoriGonzalez
Deactivated User
That should work. Increment i for every graphic you create using i++; or i=i+1; and then set your attribute to 'J' + i;
0 Kudos
williamcarr
Frequent Contributor
              var i= i + 1;
  var attr = {"cycle":"J"+ i};
           
           
featureLayer.applyEdits([graphic], null, attr);
          console.log(" Fire on everything!");


I've been playing around with this, but it's not inputting the value. Is that even set up right? It will add the point, but no attributes.
0 Kudos
LoriGonzalez
Deactivated User
I'm not familiar with the the applyEdit's method of the FeatureLayer but i have used something like this to add attributes to a new graphic. 


var attr= {"cycle": "J" + 1};

var graphic= new Graphic(geometry, symbol, attr, infoTemplate);
0 Kudos
williamcarr
Frequent Contributor
I got it to add the variable (when I changed it to a stationary number), but it's not adding the sequence.

  var geometry;
       function addGraphic(pt){
          var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CIRCLE, 
            12);
          graphic = new Graphic(pt, symbol,attr);
          map.graphics.add(graphic);
          
             var i ;
              var attr = {};
          attr["asdf"] ="J"+ i + 1;
             
             
          
          new esri.geometry.Point(pt, map.spatialReference);
          
          var newFeature = new esri.Graphic(geometry, null,null);
           
           graphic.setAttributes(attr);
   
           
           
featureLayer.applyEdits([graphic], null, null);
          console.log(" Fire on everything!");


Any thoughts?
0 Kudos
LoriGonzalez
Deactivated User
How about this
 var i = 0;        function addGraphic(pt) {            console.log("addingGraphic");            i++;            var symbol = new SimpleMarkerSymbol( SimpleMarkerSymbol.STYLE_CIRCLE,12);             var template = new InfoTemplate("results", "${*}");                           var attr = {};            attr["asdf"] = "J" + i;             var graphic = new Graphic(pt, symbol, attr,template);            map.graphics.add(graphic);                                 //featureLayer.applyEdits([graphic], null, null);            //console.log(" Fire on everything!");        }
0 Kudos
williamcarr
Frequent Contributor
That got it!!!

Thanks for all your help!

 var i = 0;
        var geometry;
       function addGraphic(pt){
          var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CIRCLE, 
            12);
            i++;
          graphic = new Graphic(pt, symbol,attr);
          map.graphics.add(graphic);
          
             
              var attr = {};
          attr["asdf"] = i;
             
             
          
          new esri.geometry.Point(pt, map.spatialReference);
          
          var newFeature = new esri.Graphic(geometry, null,null);
           
           graphic.setAttributes(attr);
   
           
           
featureLayer.applyEdits([graphic], null, null);
          console.log(" Fire on everything!");
          
0 Kudos