Select to view content in your preferred language

SketchViewModel and ctrl

484
1
11-29-2020 09:13 PM
PhilBastian
Occasional Contributor

I have a requirement to draw a rectangle for selecting features. I am doing this using a sketchviewmodel and its create method. A secondary requirement is to change the selection behaviour when the ctrl key is pressed, however the sketchviewmodel has inbuilt functionality to lock the aspect ratio when ctrl is pressed, drawing a square instead of a rectangle. Is there a way to disable this functionality?

0 Kudos
1 Reply
SebastianFrey1
Occasional Contributor

@PhilBastian I am almost 5 years late to the party, but I had the same problem recently. After doing some obfuscated JS archaeology, I came up with following solution:

// import sketchKeys variable from keybindings
import { sketchKeys } from '@arcgis/core/views/interactive/keybindings';

// assign some arbitrary string to constraint
sheetKeys.constraint = '__NOT_A_KEY__'

// now you can create, without preserving aspect ratio while holding Shift
sketch.create('rectangle');

 

If you want the original behavior back, you will have to reset sheetKeys.constraint:

// reset preserv aspect ratio behavior
sheetKeys.constraint = 'Shift';

 

But be aware: This solution may break at any time, because it relies  an internal undocumented API.

(Tested with 4.33.x)

0 Kudos