Select to view content in your preferred language

Edit geometry, single feature

1062
5
Jump to solution
05-01-2014 05:02 AM
williamcarr
Frequent Contributor
I have a single feature that represents a piece of machinery that needs to have it's geometry updated. I would like it to be able to be place by an input lat/lon via input text box. I was wondering what the best logic for this would entail.

How would I select a single feature for geometry update? An array?

Any help/guidance would be appreciated.
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Deactivated User
no worries.

1. make sure to take advantage of either the selectFeatures() callback or the corresponding event listener ("selection-complete") when you'd like to get a reference to a specific feature to update.
2. don't bother instantiating a new Graphic object.  just use the mapClick to set graphic.geometry on what's already been selected.  (because you don't want to overwrite or blow away the existing attributes.)
map.on("click", function(evt) {   featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results) {     //use the method callback to dig into the results and update its geometry                             results[0].geometry = evt.mapPoint;                 //pass the entire array (in this case one feature) back to the server     featureLayer.applyEdits(null, results, null);                 //refresh the layer to make sure the edit was successful     featureLayer.refresh();               });         });

here's a working fiddle
http://jsfiddle.net/jagravois/Cp9yz/

View solution in original post

0 Kudos
5 Replies
JohnGravois
Deactivated User
hi william,

you'll need to use featureLayer.selectFeatures() to query for the graphic of interest.

the 'selection-complete' event (or deferred callback for the method) will give you a reference to the selected features.

at that point you'll need to construct a new geometry object with the points from the input textbox and set that as the geometry property for your feature before making a call to featureLayer.applyEdits() to update it in the service itself.

if you get stuck, please feel free to post a fiddle.  i'd be happy to take a look.
0 Kudos
williamcarr
Frequent Contributor
     
          
         
          graphic = new Graphic(pt, null,null);
          map.graphics.add(graphic);
          
             
        query.geometry = feature.geometry;
  
             
             
          featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){ 
          new esri.geometry.Point(pt, map.spatialReference);
          
      
           graphic.setGeometry(pt);
           
   
           
        
featureLayer.applyEdits( null,[graphic], null);
          console.log(" Fire on everything!");
          }


Bogged down in the select feature portion. Any ideas?
0 Kudos
williamcarr
Frequent Contributor
John,

Do you think you could take a second look at this?

    query.where = "cycle = 12";
             
       graphic = new Graphic(pt, symbol,attr);
          map.graphics.add(graphic);

     
          featureLayer.selectFeatures(query,FeatureLayer.SELECTION_NEW);
          new esri.geometry.Point(pt, map.spatialReference);
    
          
         
           graphic.setGeometry(pt);
           
   
           
           
featureLayer.applyEdits( null,[graphic], null);
          console.log(" Fire on everything!");



It is placing the graphic but not applying any edits. I'm very much new to java script, and very vexed at the moment. Did I set the query and selection up properly?
Thanks.
0 Kudos
JohnGravois
Deactivated User
no worries.

1. make sure to take advantage of either the selectFeatures() callback or the corresponding event listener ("selection-complete") when you'd like to get a reference to a specific feature to update.
2. don't bother instantiating a new Graphic object.  just use the mapClick to set graphic.geometry on what's already been selected.  (because you don't want to overwrite or blow away the existing attributes.)
map.on("click", function(evt) {   featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results) {     //use the method callback to dig into the results and update its geometry                             results[0].geometry = evt.mapPoint;                 //pass the entire array (in this case one feature) back to the server     featureLayer.applyEdits(null, results, null);                 //refresh the layer to make sure the edit was successful     featureLayer.refresh();               });         });

here's a working fiddle
http://jsfiddle.net/jagravois/Cp9yz/
0 Kudos
williamcarr
Frequent Contributor
Just what I was looking for. Thanks a million John!
0 Kudos