1

I'm writing a feature layer editor demo and I'm using the esri.dijit.editing.Editor class.

According to documentation (https://developers.arcgis.com/javascript/jsapi/editor-amd.html), both attribute edits and geometry edits are saved automatically.

  • Attribute edits are saved automatically when you change selection, change the focus field, or press enter.
  • Geometry edits are saved automatically.

The editor is working fine but I wanna add a save button to applyEdits only after click it.


Follow my source code and my attempts:

var params = {
    settings: {
        map: map,
        geometryService: geometryService,
        templatePicker: templatePicker,
        layerInfos: [
            { 
                featureLayer: featureLayer 
            }
        ],
        toolbarVisible: true,
        enableUndoRedo: true,
        maxUndoRedoOperations: 15,
        createOptions: {
            polylineDrawTools: [
                Editor.CREATE_TOOL_FREEHAND_POLYLINE,
                Editor.CREATE_TOOL_POLYLINE 
            ],
            polygonDrawTools: [
                Editor.CREATE_TOOL_FREEHAND_POLYGON,
                Editor.CREATE_TOOL_POLYGON,
                Editor.CREATE_TOOL_RECTANGLE 
            ]
        },
        toolbarOptions: {
            cutVisible: true,
            mergeVisible: true,
            reshapeVisible: true
        },
        layerInfo: {
            disableGeometryUpdate: true
        }
    }
};

var editorWidget = new Editor(params, "<editor-div-id>");
editorWidget.startup();

I've tried to stop event propagation using dojo/_base/event but the argument passed in before-apply-edits (FeatureLayer) is not a "valid event".

featureLayer.on('before-apply-edits', function(e) {
    // ...
    event.stop(e); // will trow error
});

Tried to clear the edits array too but continue saving:

featureLayer.on('before-apply-edits', function(e) {
    // ...
    e.adds = [];
    e.updates = [];
    e.deletes = [];
});

Someone know how to prevent this behavior?

1 Answer 1

2

I fix this creating a workaround that override the default applyEdits method with a dummy method and calling the real applyEdits after.

// saving the default method for later use
featureLayer.myApplyEdits = featureLayer.applyEdits;

// override with dummy function
featureLayer.applyEdits = function(adds, updates, deletes, callback, errback) {
    // store the arguments in local variable
    // ...

    // create and returns dojo.Deferred to Editor still working
    var deferred = new dojo.Deferred();

    // simulate async execution (.then() callback)
    setTimeout(function() {
        deferred.resolve(true);
    }, 100);

    return deferred;
};

And then on button click:

featureLayer.myApplyEdits(adds, updates, deletes);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.