Drawtoolbar Default Shape Size

859
5
Jump to solution
06-10-2014 02:59 PM
JamieSimko
New Contributor III
When you click to draw predefined shapes such as Triangles, Circles, Arrows, and Ellipses (As shown by this example) there is a default size that they get created at.

Is there any way to customize this?

We allow the user to perform a selection by clicking like this and do not show the select geometry on the map. In cases where they are on one of these tools the returned results are very misleading.

In other words if the user just clicks expecting to select with a point they will actually be selecting with a polygon generated with a much larger extent but have no way to see this.

Thanks,
- Jamie
0 Kudos
1 Solution

Accepted Solutions
JamieSimko
New Contributor III
I'm assuming there isn't a proper way to do this yet.

As a workaround I added some listeners to see if the user moves the mouse at all. If they don't then I just take the centroid of the geometry that is drawn. Here is the code:

Local variables:
                var mouseMovedAfterDown = false;                 var mouseDownHandler = null;                 var map = null //this is setup elsewhere.



Function to determine if the mouse has moved:
        // some geometries will automatically draw at a set size relative to the current map scale if the mouse isn't moved.         // We don't want this to happen though, to avoid it we add these listeners and get the drawn geometry's center when that occurs.         var watchMouseMoveAfterDown = function () {             var mouseLocation = null;              function mouseDown(event) {                 mouseMovedAfterDown = false;                 console.log("mouseMovedAfterDown = false");                  mouseLocation = { x: event.clientX, y: event.clientY };                 jQuery(document).on("mousemove", mouseMove);                 console.log("mousemove added");                 dojo.disconnect(mouseDownHandler);                 if (!rootScope.$$phase) rootScope.$apply();             }              function mouseMove(event) {                 if (event.clientX !== mouseLocation.x || event.clientY !== mouseLocation.y) {                     mouseMovedAfterDown = true;                     console.log("mouseMovedAfterDown = true");                     jQuery(document).off("mousemove", mouseMove);                     console.log("mousemove removed");                     if (!rootScope.$$phase) rootScope.$apply();                 }             }              if (mouseDownHandler) dojo.disconnect(mouseDownHandler);             mouseDownHandler = dojo.connect(map, "onMouseDown", mouseDown);         };


Before activating the draw tool:
                watchMouseMoveAfterDown();


in the "onDrawEnd" handler:
                    if (!mouseMovedAfterDown && geometry.type !== "point") {                         geometry = geometry.getCentroid();                     }

View solution in original post

0 Kudos
5 Replies
TimWitt
Frequent Contributor
Jamie,

In my application I have added a number value the user can put in to make the point larger or smaller. Is this what you mean?

Tim
0 Kudos
JamieSimko
New Contributor III
Thanks for the sample Tim.

I don't think that is it; from what I can tell you are making changes to the graphic's symbol after the geometry has been drawn. If this was a visual issue then I think it would solve my problem but I need to change the geometry being sent in the query.

- Jamie
0 Kudos
TimWitt
Frequent Contributor
Jamie,

In my example, the user can decide the size and color of the graphic before they draw it.

Tim
0 Kudos
JamieSimko
New Contributor III
Yes but your code modifies the symbol of the graphic. The geometry I draw doesn't even get a symbol; I need some way of modifying the draw tool directly to set a default geometry size for shapes you can just click the map to draw (listed & shown in my initial question).
0 Kudos
JamieSimko
New Contributor III
I'm assuming there isn't a proper way to do this yet.

As a workaround I added some listeners to see if the user moves the mouse at all. If they don't then I just take the centroid of the geometry that is drawn. Here is the code:

Local variables:
                var mouseMovedAfterDown = false;                 var mouseDownHandler = null;                 var map = null //this is setup elsewhere.



Function to determine if the mouse has moved:
        // some geometries will automatically draw at a set size relative to the current map scale if the mouse isn't moved.         // We don't want this to happen though, to avoid it we add these listeners and get the drawn geometry's center when that occurs.         var watchMouseMoveAfterDown = function () {             var mouseLocation = null;              function mouseDown(event) {                 mouseMovedAfterDown = false;                 console.log("mouseMovedAfterDown = false");                  mouseLocation = { x: event.clientX, y: event.clientY };                 jQuery(document).on("mousemove", mouseMove);                 console.log("mousemove added");                 dojo.disconnect(mouseDownHandler);                 if (!rootScope.$$phase) rootScope.$apply();             }              function mouseMove(event) {                 if (event.clientX !== mouseLocation.x || event.clientY !== mouseLocation.y) {                     mouseMovedAfterDown = true;                     console.log("mouseMovedAfterDown = true");                     jQuery(document).off("mousemove", mouseMove);                     console.log("mousemove removed");                     if (!rootScope.$$phase) rootScope.$apply();                 }             }              if (mouseDownHandler) dojo.disconnect(mouseDownHandler);             mouseDownHandler = dojo.connect(map, "onMouseDown", mouseDown);         };


Before activating the draw tool:
                watchMouseMoveAfterDown();


in the "onDrawEnd" handler:
                    if (!mouseMovedAfterDown && geometry.type !== "point") {                         geometry = geometry.getCentroid();                     }
0 Kudos