<?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: Create a button to meaure an area in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/create-a-button-to-meaure-an-area/m-p/341425#M31590</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for your clear explanation.&amp;nbsp; I just start learning and&amp;nbsp; working on this JavaScript API. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Jul 2014 13:23:58 GMT</pubDate>
    <dc:creator>MayJeff</dc:creator>
    <dc:date>2014-07-30T13:23:58Z</dc:date>
    <item>
      <title>Create a button to meaure an area</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/create-a-button-to-meaure-an-area/m-p/341423#M31588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I try to modify a sample by creating a button and see here: &lt;A href="http://jsfiddle.net/LRpzg/6/" title="http://jsfiddle.net/LRpzg/6/"&gt;Edit fiddle - JSFiddle&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Not sure how to create a button to call the following code:&lt;/P&gt;&lt;P&gt;Original one:&lt;/P&gt;&lt;P&gt;map.on("load", function() {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var tb = new Draw(map);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tb.on("draw-end", lang.hitch(map, getAreaAndLength));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tb.activate(Draw.FREEHAND_POLYGON);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help.&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 20:32:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/create-a-button-to-meaure-an-area/m-p/341423#M31588</guid>
      <dc:creator>MayJeff</dc:creator>
      <dc:date>2014-07-29T20:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a button to meaure an area</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/create-a-button-to-meaure-an-area/m-p/341424#M31589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Couple Things.&lt;/P&gt;&lt;P&gt;&amp;nbsp; You may want to read up on a AMD tutorial for Dojo or for Esri.&amp;nbsp; When you put a function inside another function(aka your beginmeasure function inside the callback for require) it is not available globally.&amp;nbsp; So that is why the code is throwing an error. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another thing is how to attach events in dojo.&amp;nbsp; I recommend looking up how to use the dojo/on module (&lt;A href="http://livedocs.dojotoolkit.org/dojo/on" title="http://livedocs.dojotoolkit.org/dojo/on"&gt;dojo/on view /dojo/on&lt;/A&gt;).&amp;nbsp; It is perfect for attaching events.&amp;nbsp; The way it works is you import the module via the require function, and then in your code you will call something like&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14066679524922239 jive_text_macro" jivemacro_uid="_14066679524922239" modifiedtitle="true"&gt;
&lt;P&gt;on(document.getElementById("measurearea"), "click", function () {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; // Run your code here&lt;/P&gt;
&lt;P&gt;});&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what that is doing is saying on, the measurearea button click event, call my function.&amp;nbsp; This will allow you to listen to the button click event.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly you will want to look up the draw tools.&amp;nbsp; They created the Draw toolbar, and attached the event for you and you don't want to change that part.&amp;nbsp; What you want to do is on click, activate the toolbar, and then on draw end, run the getAreaAndLength function and deactivate the toolbar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14066679851351991 jive_text_macro" jivemacro_uid="_14066679851351991" modifiedtitle="true"&gt;
&lt;P&gt;on(document.getElementById("measurearea"), "click", function () {&lt;/P&gt;
&lt;P&gt; tb.activate(Draw.FREEHAND_POLYGON);&lt;/P&gt;
&lt;P&gt;});&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then in the getAreasAndLength function you will need to call tb.deactivate();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way, map.on('load') the Draw toolbar is created, the function to get the areasAndLengths is attached to draw-end and ready to go.&amp;nbsp; And then when the button is clicked, you can activate the toolbar.&amp;nbsp; When they finish drawing, it will trigger the getAreasAndLength function and then you can deactivate the toolbar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your going to need to get familiar with the AMD style of JavaScript programming to work with most of the samples.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 21:10:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/create-a-button-to-meaure-an-area/m-p/341424#M31589</guid>
      <dc:creator>RobertWinterbottom</dc:creator>
      <dc:date>2014-07-29T21:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create a button to meaure an area</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/create-a-button-to-meaure-an-area/m-p/341425#M31590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for your clear explanation.&amp;nbsp; I just start learning and&amp;nbsp; working on this JavaScript API. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 13:23:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/create-a-button-to-meaure-an-area/m-p/341425#M31590</guid>
      <dc:creator>MayJeff</dc:creator>
      <dc:date>2014-07-30T13:23:58Z</dc:date>
    </item>
  </channel>
</rss>

