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.
<SPAN class="comment token">// ***************************************</SPAN>
<SPAN class="comment token">// activate the sketch to create a polygon</SPAN>
<SPAN class="comment token">// ***************************************</SPAN>
<SPAN class="keyword token">var</SPAN> drawPolygonButton <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getElementById</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"polygonButton"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
drawPolygonButton<SPAN class="punctuation token">.</SPAN>onclick <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// set the sketch to create a polygon geometry</SPAN>
sketchViewModel<SPAN class="punctuation token">.</SPAN><SPAN class="token function">create</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"polygon"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Disable freehand-drawing</SPAN>
sketchViewModel<SPAN class="punctuation token">.</SPAN>draw<SPAN class="punctuation token">.</SPAN>activeAction<SPAN class="punctuation token">.</SPAN>_dragEnabled <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="token function">setActiveButton</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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<SPAN class="punctuation token">.</SPAN>draw<SPAN class="punctuation token">.</SPAN>activeAction<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"vertex-add"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//logic to compare vertex-add coordinates with </SPAN>
<SPAN class="comment token">//drag-end coordinates</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
kind regards
Tor