Is it possible to calculate circle radius while drawing it?

3535
2
Jump to solution
10-09-2013 01:41 PM
AndreyLabodin
New Contributor III
Hi,
The main idea is to show some info somewhere about the current drawed radius before draw-end event (before I have actually released a mouse button). But it looks like there is no way to make it.
I was thinking about capturing mappoint right after the Draw toolbar is activated and then continuously capturing the second mappoint while dragging, and sending both mappoints to some tool to calculate distance.
But may be there is more simple way? (without "dancing around the drum")

Thanks 🙂
0 Kudos
1 Solution

Accepted Solutions
Imihiro
New Contributor II
Yes.

var centerPt=null; //description:get distance between ptB and centerPt //return: number function getDistance(ptB){  if(centerPt==null||centerPt.mapPoint==null){      console.log("unexpected para,function getDistance()");      return "";    }     var ptA=centerPt.mapPoint;    return Math.sqrt(Math.pow(ptA.x-ptB.x,2)+Math.pow(ptA.y-ptB.y,2));     }  //onDragStart, record the centerPt dojo.connect(mapAppObj.map,"onMouseDragStart",function(evt){               console.log("dragStart triggered");        centerPt=evt;         });      }        //onDrag, calculate distance between currentPoint and centerPt dojo.connect(mapAppObj.map,"onMouseDrag",function(evt){    var radius=getDistance(evt.mapPoint);    console.log("radius is:"+radius);   }

View solution in original post

2 Replies
Imihiro
New Contributor II
Yes.

var centerPt=null; //description:get distance between ptB and centerPt //return: number function getDistance(ptB){  if(centerPt==null||centerPt.mapPoint==null){      console.log("unexpected para,function getDistance()");      return "";    }     var ptA=centerPt.mapPoint;    return Math.sqrt(Math.pow(ptA.x-ptB.x,2)+Math.pow(ptA.y-ptB.y,2));     }  //onDragStart, record the centerPt dojo.connect(mapAppObj.map,"onMouseDragStart",function(evt){               console.log("dragStart triggered");        centerPt=evt;         });      }        //onDrag, calculate distance between currentPoint and centerPt dojo.connect(mapAppObj.map,"onMouseDrag",function(evt){    var radius=getDistance(evt.mapPoint);    console.log("radius is:"+radius);   }
AndreyLabodin
New Contributor III
Perfect 🙂 Thanks
0 Kudos