How can I get click event Of esri.toolbars.Draw

1386
2
Jump to solution
08-06-2014 07:33 PM
xiaoyunnsongb
New Contributor III

1111.jpgHello every superiors:

      Now I have a question to   consult.

code A :

        var measureLengthToolbar = new esri.toolbars.Draw(map);

         measureLengthToolbar.activate(esri.toolbars.Draw.POLYLINE);

I know the end of  the event is

      code B:

                  dojo.connect(measureLengthToolbar, "onDrawEnd", function(geometry) {

                 .....

             }

            this  is the double click event .

when I  draw  the line  of  center ,I need single click, because  I need  to deal songthing when single click ,how can I draw the code like  code B,thanks very much.

0 Kudos
1 Solution

Accepted Solutions
OwenEarley
Occasional Contributor III

You could create a variable to check if the draw toolbar is active:

var isDrawing = false;

When you activate the draw toolbar update this variable to true:

tb.activate(tool);

isDrawing = true;

When you deactivate the draw toolbar update this variable to false:

tb.deactivate();

isDrawing = false;

Now you can use the map click event:

map.on("click", function(evt){

    // Check if user is drawing

    if (isDrawing) {

        // Add your code here...

    }

});

I have created a working example on JS Bin: Draw Toolbar - map click event

The example prints information to the console log:

console.png

Hope this helps,

Owen

Spatial XP

View solution in original post

2 Replies
OwenEarley
Occasional Contributor III

You could create a variable to check if the draw toolbar is active:

var isDrawing = false;

When you activate the draw toolbar update this variable to true:

tb.activate(tool);

isDrawing = true;

When you deactivate the draw toolbar update this variable to false:

tb.deactivate();

isDrawing = false;

Now you can use the map click event:

map.on("click", function(evt){

    // Check if user is drawing

    if (isDrawing) {

        // Add your code here...

    }

});

I have created a working example on JS Bin: Draw Toolbar - map click event

The example prints information to the console log:

console.png

Hope this helps,

Owen

Spatial XP

xiaoyunnsongb
New Contributor III

Dear oearley

     Thanks very much, wish you happy every day.

0 Kudos