AnsweredAssumed Answered

Toggle freehand in sketchViewModel-class

Question asked by tobors on Dec 4, 2017
Latest reply on Dec 8, 2017 by tobors

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 

Outcomes