Select to view content in your preferred language

Default Editing Widget - Capture Point

1215
4
Jump to solution
04-22-2013 09:40 AM
JamesTrier
Occasional Contributor
Apologies if a similar question was asked before...

When using the default editing widget (using code from this sample), how can I capture the the geometry of the user-added feature?  Using Firebug I can see this data in the JSON payload sent to the server during the ApplyEdits operation (i.e. XY coordinates of a new point).  Is there an event I can connect to in order to capture that data? 

I tried:

//Try #1, didn't fire or give an error  dojo.connect(editorWidget, 'onDrawEnd', function(evt){      console.log(evt); });   //Try #2, nothing  dojo.connect(map.getLayer(featureLayer.id), 'onclick', function(evt){      console.log(evt); });   


Thanks for your help!

Jim
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Esri Frequent Contributor
The 'onEditsComplete' event returns 3 arrays as it's arguments
addResults, updateResults, deleteResults
http://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#onEditsComplete

dojo.connect(editorWidget, 'onEditsComplete', function(addResults, updateResults, deleteResults){      console.log('addResults: ', addResults);      console.log('updateResults: ', updateResults);      console.log('deleteResults: ', deleteResults); });


Similarly, you can capture the results before they are sent to the server, by listening for 'onBeforeApplyEdits'
http://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#onBeforeApplyEdits
I think you can modify the edits, but cannot cancel them if something doesn't meet your criteria.

View solution in original post

0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Jim,

You can do this using the "onEditsComplete" event along with the "onDrawEnd" event.  Here is an example:

dojo.connect(operationsPointLayer, "onEditsComplete", function(){
        var tb = new esri.toolbars.Draw(map);
        tb.activate(esri.toolbars.Draw.POINT);
        dojo.connect(tb, "onDrawEnd", function(geometry){
            console.log("X: " + geometry.x + ", Y: " + geometry.y);
            });
        tb.deactivate();
        } 
0 Kudos
JamesTrier
Occasional Contributor
Hi Jim,

You can do this using the "onEditsComplete" event along with the "onDrawEnd" event.  Here is an example:

dojo.connect(operationsPointLayer, "onEditsComplete", function(){
        var tb = new esri.toolbars.Draw(map);
        tb.activate(esri.toolbars.Draw.POINT);
        dojo.connect(tb, "onDrawEnd", function(geometry){
            console.log("X: " + geometry.x + ", Y: " + geometry.y);
            });
        tb.deactivate();
        } 


Thanks again for your help Jake... I tried 'onDrawEnd' the way you suggested, but no dice.  When I logged the 'onEditsComplete' event, I got a result, but not the one I expected:

//Event object
{
declaredClass : "esri.layers.FeatureEditResult", 
objectId : "208281", 
success : "true"
}


Since I get the ObjectId from onEditsComplete, maybe I can search the map for that object and get the XY that way?  I'm not sure if there's a more efficient or better way to do it...

Also, a question on the draw functions:  Doesn't picking a selection in the Editor widget turn on the draw toolbar just for that selection?  When I tested it, I had to select an editor to drop a point, and then select again to drop another point.

Is there a way to look at the data from the edit pre-flight, like a 'beforeEdits' event?  My Google-Fu didn't find anything like that.

Thanks again for taking a look!
0 Kudos
ReneRubalcava
Esri Frequent Contributor
The 'onEditsComplete' event returns 3 arrays as it's arguments
addResults, updateResults, deleteResults
http://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#onEditsComplete

dojo.connect(editorWidget, 'onEditsComplete', function(addResults, updateResults, deleteResults){      console.log('addResults: ', addResults);      console.log('updateResults: ', updateResults);      console.log('deleteResults: ', deleteResults); });


Similarly, you can capture the results before they are sent to the server, by listening for 'onBeforeApplyEdits'
http://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#onBeforeApplyEdits
I think you can modify the edits, but cannot cancel them if something doesn't meet your criteria.
0 Kudos
JamesTrier
Occasional Contributor
The 'onEditsComplete' event returns 3 arrays as it's arguments
addResults, updateResults, deleteResults
http://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#onEditsComplete

dojo.connect(editorWidget, 'onEditsComplete', function(addResults, updateResults, deleteResults){
     console.log('addResults: ', addResults);
     console.log('updateResults: ', updateResults);
     console.log('deleteResults: ', deleteResults);
});


Similarly, you can capture the results before they are sent to the server, by listening for 'onBeforeApplyEdits'
http://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#onBeforeApplyEdits
I think you can modify the edits, but cannot cancel them if something doesn't meet your criteria.


Rene, that's precisely what I needed!  I connected to 'onBeforeApplyEdits' and got the data payload before sending to the server.  From there I found the XY I needed. 


            dojo.connect(featureLayer, "onBeforeApplyEdits", function(e){
                var newPointX = e[0].geometry.x, newPointY = e[0].geometry.y;
                //Go to town from here 
            });



Sincerely appreciate the help, thanks!
0 Kudos