Editor Widget: how to handle a new feature before it is added to its feature layer?

3099
1
06-19-2015 07:35 AM
xiannianchen
New Contributor II

Hi everyone, the background is:

I have asked the similar question before. I think it might be confusing. Instead re-post in that thread, I think it is better to create a new thread.

I use the Template Picker Widget and the Editor Widget for online editing. While those two widgets are powerful and convenient, they give me some headaches in using them. My major headache is on attribute editing before the attribute inspector popup.

By investigating the objects/property/methods of the Editor object, I learned that the Editor widget has a built-in Draw toolbar, which can be referred as follows, I can add an event handler to the "draw-end" event.

myEditor = new Editor(editor_params, 'myEditorDiv');

myEditor.startup();

myEditor.drawingToolbar.drawToolbar.on("draw-end", myDrawEnd_func);

drawingToolbar is an object of myEditor, and drawToolbar is an object of drawingToolbarobject.

I thought I can update the attribute information in the onDrawEnd event listener - myDrawEnd_func - before the feature is inserted into the feature layer. But I am wrong. I can't trap the newly created geometry in my event listener as the sample code at this link (Edit without Editor Widget).

This is my code which I use to trap the new geometry and assign attribute information to the new geometry. This is the way to manipulate the new feature before it is added to the feature layer as the sample code: Edit without Editor Widget.

But the problem is: there are two features added to the feature layer. One is with my customized attribute information. The other is without any customized information. I guess I do not really trap the feature before it is added to the feature layer in the "draw-end" event listener. Instead, I am re-creating the same feature and change the attribute information.

myEditor = new Editor(editor_params, 'myEditorDiv');

myEditor.startup();

myEditor.drawingToolbar.drawToolbar.on("draw-end", function(evt){

  var myPoint = new Graphic(evt.geometry, null, null, null);

  myPoint .attributes = some_attr;          // some_attr: from other function

  myFeatureLayer.applyEdits([myPoint ], null, null);

});

My question is: for the built-in toolbar, myEditor.drawingToolbar.drawToolbar, of the Editor Widget, can I trap the new feature in the "draw-end" event listener  before the feature is added to its feature layer?

Thanks.

0 Kudos
1 Reply
KellyHutchins
Esri Frequent Contributor

Take a look at the Feature Layer's before-apply-edits event. This event fires before features are added to the feature layer.