0

My attempted on using the UndoManager has been unsuccessful for a couple days and I'm stuck.

I did not setup a proxy.

I create a FeatureLayer object in memory with

var drawingPointLayer = new esri.layers.FeatureLayer(featureCollection, {
    id: "drawPointLayer",
    mode: esri.layers.FeatureLayer.MODE_ONDEMAND
});
mapApp.map.addLayer(drawingPointLayer);

created UndoManager and button to perfom undo redo actions

undoManager = new esri.UndoManager({maxOperations:50});

var undoButton = new dijit.form.ToggleButton({
    id: "undoButton",
    showLabel: false,
    iconClass: "dijitEditorIcon dijitEditorIconUndo",
    onClick: function(){ 
        undoManager.undo(); 
        checkUndoRedoState(); 

        mapApp.map.graphics.graphics.splice(mapApp.map.graphics.graphics.length-1, 1);
        mapApp.map.graphics.redraw();
        alert(undoManager.length + " | " + mapApp.map.graphics.graphics.length);
    }
}, "undoButton");
var redoButton = new dijit.form.Button({
    id: "redoButton",
    showLabel: false,
    iconClass: "dijitEditorIcon dijitEditorIconRedo",
    onClick: function(){ 
        undoManager.redo(); 
        checkUndoRedoState(); 
    }
}, "redoButton");

and add operation to UndoManager

function addToUndoManager(graphic, task){
    var operation;
    var featureLayer = mapApp.map.getLayer("drawPointLayer");
    //var featureLayer = mapApp.map.getLayer("landuseLayer");

    if(task=="add"){
        featureLayer.applyEdits([graphic], null, null, function() {
            operation = new esri.dijit.editing.Add({
                featureLayer: featureLayer,
                addedGraphic: graphic
            });
        });

    }

    if(operation)
        undoManager.add(operation);

    checkUndoRedoState();

    alert(undoManager.canUndo + " | " + undoManager.canRedo + " | " + operation.label + " | " + operation.type + " | " + undoManager.length + " | " + mapApp.map.graphics.graphics.length);
}

New point markers would be added to the map via mouse click. Undomananger would register. But when I press the undo button, the graphics on the map would not disappear.

I'm clueless on what to do next to solve this problem.

Please Help

1 Answer 1

1

I figure it out.. finally

what I should have done is use the addedGraphics parameter instead of addedGraphic

if(task=="add"){
    featureLayer.applyEdits([graphic], null, null, function() {
        operation = new esri.dijit.editing.Add({
            featureLayer: featureLayer,
            addedGraphics: [graphic]
        });
    });

}

I think this is a bug because when I read into the performUndo() code

alert(undoManager.peekUndo().performUndo) //not performUndo().. This will execute the function and won't display the inline code in alert

the alert shows

function(){ this._featureLayer.applyEdit(null, null, this._addedGraphics); }

when use addedGraphic: graphic

alert(undoManager.peekUndo()._addedGraphic);

returns undefined, which means that addedGraphic did not get pushed into _addedGraphics.

Your Answer

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

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