How to complete draw action in ArcGIS Maps SDK for JavaScript?

365
1
Jump to solution
12-23-2023 01:20 AM
ekleiman22
New Contributor II

I use  version 4.28 of ArcGIS Maps SDK for JavaScript. I have a button that activate Draw object for drawing, for example, a polyline. But an user could change its mind after he/she pushed the button, so I added other button that should to interrupt (complete) the drawing action. So I added a code 

 

document.getElementById("btnDrop").onclick = () => {
        draw.complete();
    }

 

that should interrupt the drawing action. But it does not work. Here a sample that I did in CodePen:

Sample for drawing polyline and a button for cancelling of drawing 

So I need a help.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ekleiman22
New Contributor II

It seems I know how to solve my problem. I made changes in Sample for drawing polyline and a button for cancelling of drawing . 

var toDraw = true;
....
document.getElementById("btnDrop").onclick = () => {
        toDraw = false;
        draw.complete();
    }
....
action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo"          
        ],
        updateVertices
      );
      //action.on("draw-complete", special);
....
function updateVertices(event) {
        if (!toDraw)
            return;
....

View solution in original post

0 Kudos
1 Reply
ekleiman22
New Contributor II

It seems I know how to solve my problem. I made changes in Sample for drawing polyline and a button for cancelling of drawing . 

var toDraw = true;
....
document.getElementById("btnDrop").onclick = () => {
        toDraw = false;
        draw.complete();
    }
....
action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo"          
        ],
        updateVertices
      );
      //action.on("draw-complete", special);
....
function updateVertices(event) {
        if (!toDraw)
            return;
....
0 Kudos