Select to view content in your preferred language

Using undomanager

1323
4
Jump to solution
09-12-2014 07:38 AM
TimWitt2
MVP Alum

Hey everybody,

I was thinking about implementing the undomanager in my map to remove or re-add graphics.

When looking at the example page I found this:

Graphics with undo redo | ArcGIS API for JavaScript

I am able to get it to work, but I don't want to load an outside module, like they use the customoperation Does anyone have an example where all the code is within the application?

Thanks,

Tim

0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

While this is possible (see attached) is there a particular reason why you wanted everything in a single file? This thread from a stack overflow user asks a similar question and there are some good replies.

javascript - Questions about Dojo modules from Dojo newb? - Stack Overflow

There's also some good info in the JSAPI help on creating modules: Tutorials | ArcGIS API for JavaScript

View solution in original post

0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Tim,

If you download the sample, the code for the module is included with it.

define([

  "dojo/_base/declare", "esri/OperationBase", "esri/toolbars/navigation"

  ], function(declare, OperationBase, Navigation) {

    var customOp = {};

    customOp.Add = declare(OperationBase, {

      label: "Add Graphic",

      constructor: function ( /*graphicsLayer, addedGraphic*/ params) {

        params = params || {};

        if (!params.graphicsLayer) {

          console.error("graphicsLayer is not provided");

          return;

        }

        this.graphicsLayer = params.graphicsLayer;

        if (!params.addedGraphic) {

          console.error("no graphics provided");

          return;

        }

        this._addedGraphic = params.addedGraphic;

      },

      performUndo: function () {

        this.graphicsLayer.remove(this._addedGraphic);

      },

      performRedo: function () {

        this.graphicsLayer.add(this._addedGraphic);

      }

  });

  return customOp;

});

TimWitt2
MVP Alum

Thanks Jake, would I be able to just include that in my application or is there another step I would have to do?

0 Kudos
KellyHutchins
Esri Frequent Contributor

While this is possible (see attached) is there a particular reason why you wanted everything in a single file? This thread from a stack overflow user asks a similar question and there are some good replies.

javascript - Questions about Dojo modules from Dojo newb? - Stack Overflow

There's also some good info in the JSAPI help on creating modules: Tutorials | ArcGIS API for JavaScript

0 Kudos
TimWitt2
MVP Alum

Hey Kelly,

thanks for the quick reply and thanks for the zip file and the helpful links.

At the moment I am working on an Advanced Draw Widget and wanted to include the redo/undo function. Instead of explaining the user how to install modules, I wanted a one-stop shop That is why I wanted to include everything in one file.

Btw. let me know what you think of the widget

Tim

0 Kudos