Force snapping on draw/edit tool

2700
4
10-13-2011 06:50 AM
LukeEvans
New Contributor
Hi,

We have been requested by our client to always have snapping enabled when using the draw and edit tools.  Basically, they want to be able to have snapping enabled without the need to press the control key.

I've tried extending the DrawTool and adding this:

   if (event.type == MouseEvent.MOUSE_DOWN)
   {
    ViewerContainer.getInstance().dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, Keyboard.CONTROL, Keyboard.CONTROL));
   }
   else if (event.type == MouseEvent.MOUSE_UP)
   {
    ViewerContainer.getInstance().dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_UP, true, false, Keyboard.CONTROL, Keyboard.CONTROL));
   }


I've tried changing the dispatcher from ViewerContainer, "this", the map, FlexGlobals.topLevelApplication but it seems to be having no effect.  Is there a simpler way to do this?

Thanks

Luke
Tags (2)
0 Kudos
4 Replies
LukeEvans
New Contributor
Sorry to bump but we really need a solution for this.  'Faking' the keyboard control button press doesn't seem to work to enable snapping on the tools.  Does anyone have any ideas to solve this?

Edit:

After looking further, I believe what we want to ensure that the ctrlKey field is always set to true on the map MouseEvent click event.  The problem being that the handler for this is a private method in the Draw/Edit tool.  I can't figure out any way to block the mouse click event, change the ctrlKey to true and redispatch the event
0 Kudos
LukeEvans
New Contributor
I've also tried extending the EditTool and setting the esri_internal snapping boolean to true but it does not allow a ChangeWatcher, so I can't monitor any changes and force it to remain as true

The DrawTool only allows you to override the removeGraphic internal function
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Luke,

   Having snapping enabled all the time is a horrible Idea. Think about what snapping is doing is is running some code every pixel that the mouse is moved and checking if it is in proximity of a vertex of a feature. This process is costly hence esri Flex API team choosing only to enable it with the holding of the control button. This is one of those situations that when I worked in the consulting world I would explain to the client that the overhead that this would cause is not worth degrading the responsiveness and functionality of the application so that they can have one less step. Clients do not understand the inner working of the application so it is up to you are the programmer to enlighten them as to what is a good or a horrible idea.
0 Kudos
TimothyBaldwin
New Contributor II
What if the tool you are developing is for a tablet?  If you are adding or moving a feature, you still need some way to fake the control button if snapping is requested.
0 Kudos