<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Draw Toolbar onDrawEnd firing twice in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-toolbar-ondrawend-firing-twice/m-p/354202#M32806</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Move below statement out of startEditing function. I don't know what will trigger to call startEditing. But every time it's invoked, onDrawEnd event handler will be defined one more time, which makes createFeature invoked one more time. &lt;BR /&gt;&lt;BR /&gt;I would recommend to define the onDrawEnd event handler in the same function where drawingToolbar instance is created so to ensure it's been defined once only.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you Jason.&amp;nbsp; I also just realized that I was creating the onDrawEnd handler multiple times.&amp;nbsp; The startEditing function is called each time a selection is made in the templatePicker.&amp;nbsp; That means that if the user selects another template, I get a duplicate handler.&amp;nbsp; In my case, when I was testing I was selecting a template and adding a new feature.&amp;nbsp; Then I unselected the template which calls the stopEditing function.&amp;nbsp; My stopEditing function simply deactivates the drawingToolbar.&amp;nbsp; I have added code to save the onDrawEnd handler to a variable and then the stopEditing function can remove that handler when it is called.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Sep 2013 17:02:20 GMT</pubDate>
    <dc:creator>BrianBeck</dc:creator>
    <dc:date>2013-09-16T17:02:20Z</dc:date>
    <item>
      <title>Draw Toolbar onDrawEnd firing twice</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-toolbar-ondrawend-firing-twice/m-p/354200#M32804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a simple editing application with the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;startEditing : function(template) {&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; var drawingTool = template.template.drawingTool;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; switch(drawingTool) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case FeatureTemplate.TOOL_POINT: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drawingTool = Draw.POINT; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.drawingToolbar.activate(drawingTool); }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;createFeature : function(template, evt) {&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; var featureLayer = template.featureLayer; &amp;nbsp;&amp;nbsp;&amp;nbsp; template = template.template;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; var prototype = template.prototype;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; var geometry = evt.geometry;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; var graphic = new Graphic(prototype.toJson()); &amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.setGeometry(geometry);&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.initAttributes(graphic, featureLayer).then(function() {&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var features = [graphic];&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer.applyEdits(features).then(function(addResults) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var objectIds = array.map(addResults, function(addResult) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return addResult.objectId; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var q = new Query(); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q.objectIds = objectIds;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer.selectFeatures(q).then(function(features) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; main.openForm(features); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; });&amp;nbsp; }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using a point tool with the drawing toolbar, I am finding that when I click a point on the map, the createFeature function is called twice resulting in 2 features being created with the same geometry.&amp;nbsp; How can I stop the draw toolbar from creating 2 features?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Sep 2013 16:37:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-toolbar-ondrawend-firing-twice/m-p/354200#M32804</guid>
      <dc:creator>BrianBeck</dc:creator>
      <dc:date>2013-09-16T16:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: Draw Toolbar onDrawEnd firing twice</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-toolbar-ondrawend-firing-twice/m-p/354201#M32805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Move below statement out of startEditing function. I don't know what will trigger to call startEditing. But every time it's invoked, onDrawEnd event handler will be defined one more time, which makes createFeature invoked one more time. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would recommend to define the onDrawEnd event handler in the same function where drawingToolbar instance is created so to ensure it's been defined once only.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Sep 2013 16:51:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-toolbar-ondrawend-firing-twice/m-p/354201#M32805</guid>
      <dc:creator>JasonZou</dc:creator>
      <dc:date>2013-09-16T16:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Draw Toolbar onDrawEnd firing twice</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-toolbar-ondrawend-firing-twice/m-p/354202#M32806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Move below statement out of startEditing function. I don't know what will trigger to call startEditing. But every time it's invoked, onDrawEnd event handler will be defined one more time, which makes createFeature invoked one more time. &lt;BR /&gt;&lt;BR /&gt;I would recommend to define the onDrawEnd event handler in the same function where drawingToolbar instance is created so to ensure it's been defined once only.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you Jason.&amp;nbsp; I also just realized that I was creating the onDrawEnd handler multiple times.&amp;nbsp; The startEditing function is called each time a selection is made in the templatePicker.&amp;nbsp; That means that if the user selects another template, I get a duplicate handler.&amp;nbsp; In my case, when I was testing I was selecting a template and adding a new feature.&amp;nbsp; Then I unselected the template which calls the stopEditing function.&amp;nbsp; My stopEditing function simply deactivates the drawingToolbar.&amp;nbsp; I have added code to save the onDrawEnd handler to a variable and then the stopEditing function can remove that handler when it is called.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Sep 2013 17:02:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-toolbar-ondrawend-firing-twice/m-p/354202#M32806</guid>
      <dc:creator>BrianBeck</dc:creator>
      <dc:date>2013-09-16T17:02:20Z</dc:date>
    </item>
  </channel>
</rss>

