1

I'm trying to add edit(namely Edit.MOVE, Edit.SCALE, Edit.ROTATE, Edit.EDIT_VERTICES, and Edit.EDIT_TEXT) to the draw widget inside CMV. The steps I have taken thus far are:

1- I've defined the edit namespace: 'esri/toolbars/edit',

2- I've added "Edit" inside the function declaration.

3- Created an editTools variable: drawToolbar: null, editTools: null,

4- Added the following code inside the post create method to respond to different types of graphics: this.editTools = new Edit(this.map);

        this.pointGraphics.on('click', function(evt)
        {
            console.log("CLICKED ON POINT GRAPHIC");

            event.stop(evt);
            this.activateEditTools(evt.graphic);
        });

        this.polylineGraphics.on('click', function(evt)
        {
            console.log("CLICKED ON POLYLINE GRAPHIC");

            event.stop(evt);
            this.activateEditTools(evt.graphic);
        });

        this.polygonGraphics.on('click', function(evt)
        {
            console.log("CLICKED ON POLYGON GRAPHIC");

            event.stop(evt);
            this.activateEditTools(evt.graphic);
        });

        this.map.on('click', function(evt)
        {
            console.log("CLICKED ON MAP");

            this.editTools.deactivate();
        });

5- The activate edit tools method I'm calling above: activateEditTools: function(graphic) { alert("inside activate edit with graphic: " + graphic); this.editTools.activate(Edit.MOVE | Edit.SCALE | Edit.ROTATE | Edit.EDIT_VERTICES | Edit.EDIT_TEXT, graphic); },

Yet to no avail, any input would be helpful.

0

This is most likely a problem of scope. When calling this.activateEditTools, 'this' is not your widget so the activateEditTools method will not be found. Try using lang.hitch like this:

this.pointGraphics.on('click', lang.hitch(this, function(evt)
{
    console.log("CLICKED ON POINT GRAPHIC");

    event.stop(evt);
    this.activateEditTools(evt.graphic);
})); 
0

Full answer for those looking for a quick fix:

Inside postcreate: this.editTools = new Edit(this.map); this.pointGraphics.on('click', lang.hitch(this, 'activateEditTools')); this.polylineGraphics.on('click', lang.hitch(this, 'activateEditTools')); this.polygonGraphics.on('click', lang.hitch(this, 'activateEditTools')); this.map.on('click', lang.hitch(this, 'deactivateEdit'));

Outside postcreate: deactivateEdit: function() { this.editTools.deactivate(); }, activateEditTools: function(evt) { event.stop(evt); this.editTools.activate(esri.toolbars.Edit.MOVE | esri.toolbars.Edit.SCALE | esri.toolbars.Edit.ROTATE | esri.toolbars.Edit.EDIT_VERTICES | esri.toolbars.Edit.EDIT_TEXT, evt.graphic); },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy