Toggle freehand in sketchViewModel-class

1270
4
Jump to solution
12-04-2017 05:02 AM
by Anonymous User
Not applicable

Hello,

I'm playing around with the SketchViewModel-class as a digitizing solution at work and have been using this sample to understand it's bits and pieces. 

But I am struggling a bit with the default freehand-on-drag setting that fires. This can be a pain if the user needs to pan the view to continue his digitizing, which isn't that rare.  

Has anyone figured out an solution for toggling this behaviour? It might be that this functionality is not available in this class, but I can't seem too find a solution for this in the Draw-class either. 

UPDATE: 

Had a look into the activeAction object that gets created when you use the sketchViewModel.create() method. Seems there is a attribute here thats called "_dragEnabled" and when you set this to false the freehand drawing gets disabled. 

However that doesn't stop the "vertex-add" event to fire on drag-end. So it's a step in a direction. I'm just not sure if its the right one. 

If you want to try this out yourself, replace the code from ln 142-151 in the sandbox-sample with the one below.

// ***************************************
 // activate the sketch to create a polygon
 // ***************************************
 var drawPolygonButton = document.getElementById("polygonButton");
 drawPolygonButton.onclick = function() {
 // set the sketch to create a polygon geometry
 sketchViewModel.create("polygon");
 //Disable freehand-drawing
 sketchViewModel.draw.activeAction._dragEnabled = false;
 setActiveButton(this);
 };‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

UPDATE II: 

I tried to catch the "vertex-add"-event on the draw activeAction-object, to prevent default if the vertex-add coordinates match the screenpoint of drag-start and drag-end.

However this only solves part of the problem given that vertex-add fires on mouse-up, and adds a vertex on each drag-end. This way there will always be a vertex-added on each drag-end which will be removed when you drag a second time. 

Code to catch the event. 

sketchViewModel.draw.activeAction.on("vertex-add", function (evt) {‍ 
                         //logic to compare vertex-add coordinates with 
                         //drag-end ‍‍‍coordinates
                            }‍‍‍‍


kind regards
Tor 

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi Undral,

I love the functionality of the Draw and SketchViewModels, and look forwards to seeing what you will be doing With it in the future.

I ended up using the functionality to toggle true false on dragEnabled, to at least get the ability to pan as long as you choose a interaction-point for the pan where you were going to digitize. Thus you can pan even though the drag-end will fire a vertex add. Not a optimal solution, but it will make do for now.


View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Tor,

   What about just using the arrow keys on the keyboard for navigation?

by Anonymous User
Not applicable

Hi Robert,

that certainly is the best solution for desktop.

However that would probably not work on a mobile device. As far as I know they rely solely on touch and touch-drag events. So a good solution would haveto solve both scenarios. 

Thanks for the tip tho. 

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi Tor, 

We will continue to improve usability of Draw and SketchViewModels in future releases. Thank you for your feedback and will definitely integrate it into draw and sketch. 

0 Kudos
by Anonymous User
Not applicable

Hi Undral,

I love the functionality of the Draw and SketchViewModels, and look forwards to seeing what you will be doing With it in the future.

I ended up using the functionality to toggle true false on dragEnabled, to at least get the ability to pan as long as you choose a interaction-point for the pan where you were going to digitize. Thus you can pan even though the drag-end will fire a vertex add. Not a optimal solution, but it will make do for now.


0 Kudos