<?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: beginner: changing map extent on click in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173554#M16075</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for posting the complete code from the other post.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I caught that case sensitivity after I published my original post.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I fixed my function name problem I still got an error that myZoom was not defined. I see from your example that while I placed my function in the head section I did not tie it together with dojo.connect. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found that it in the dojo.connect that you can use either&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dojo.byId('button2') or just button2 in the dojo.connect statement. Is this a matter of preference or is there a reason why you were more specific?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason why I coded the way I did was because I had looked at this &lt;/SPAN&gt;&lt;A href="http://serverapps.esri.com/javascript_examples/PopulateDropdownList.html"&gt;example &lt;/A&gt;&lt;SPAN&gt; and I saw that there was an onChange event in the combobox. It calls a function which changes the map based on a layer definition. So I thought it would be okay to do something similar with an onClick event. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why does this example not use a dojo.connect statement to tie it together as you showed in my original example?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Nov 2011 17:23:04 GMT</pubDate>
    <dc:creator>MikeOnzay</dc:creator>
    <dc:date>2011-11-03T17:23:04Z</dc:date>
    <item>
      <title>beginner: changing map extent on click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173552#M16073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want the map extent to change by clicking on some text. I'm using the example &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Add Dynamic Map&lt;/A&gt;&lt;SPAN&gt; and I have added the following code&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function myzoom() {
&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 axtent = new esri.geometry.Extent(55.6153456, 5.7191691, 105.6673614, 37.0016790, map.SpatialReference);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.setExtent(axtent);
&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;I have tried placing it both outside of the init function and inside the init function. In both cases I get an error when I call it &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;lt;p id="test" onClick="myZoom();"&amp;gt;click for zoom&amp;lt;/p&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I add an alert function outside of the init function&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp; function nTest(){
&amp;nbsp;&amp;nbsp; alert("test2");
&amp;nbsp; }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and call it from here&amp;nbsp; &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;lt;p id="test2" onClick="nTest();"&amp;gt;click for alert&amp;lt;/p&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:58:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173552#M16073</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2021-12-11T08:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: beginner: changing map extent on click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173553#M16074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;JavaScript is case-sensitive. Your function name is "myzoom" but your onClick says "myZoom".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I probably should have posted a more complete code sample in the &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/42827" rel="nofollow noopener noreferrer" target="_blank"&gt;other thread&lt;/A&gt;&lt;SPAN&gt; where this was recently discussed. Here's a simple page demoing this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;Zoom to Extent Test&amp;lt;/title&amp;gt;
&amp;lt;script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css"&amp;gt;
&amp;nbsp; &amp;lt;script type="text/javascript"&amp;gt;djConfig = { parseOnLoad: true }&amp;lt;/script&amp;gt;
&amp;nbsp; &amp;lt;script type="text/javascript"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("esri.map");
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; var map, layer;
&amp;nbsp;&amp;nbsp;&amp;nbsp; function Init() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map = new esri.Map("mapDiv");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer"); 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayer(layer);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(dojo.byId('button2'), 'onclick', myzoom);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; function myzoom() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log('my zoom fired');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var axtent = new esri.geometry.Extent(55.6153456, 5.7191691, 105.6673614, 37.0016790, map.SpatialReference);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // var axtent = new esri.geometry.Extent(105.6673614, 37.0016790, 55.6153456, 5.7191691, map.SpatialReference);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log('xmin: ', axtent.xmin, '; ymin: ', axtent.ymin);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.setExtent(axtent);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.ready(Init);
&amp;nbsp; &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body class="tundra"&amp;gt;
&amp;nbsp; &amp;lt;div id = "mapDiv" style="width:800px; height:300px"&amp;gt; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;lt;input id="button2" type="button" value="Zoom To India" /&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:58:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173553#M16074</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2021-12-11T08:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: beginner: changing map extent on click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173554#M16075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for posting the complete code from the other post.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I caught that case sensitivity after I published my original post.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I fixed my function name problem I still got an error that myZoom was not defined. I see from your example that while I placed my function in the head section I did not tie it together with dojo.connect. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found that it in the dojo.connect that you can use either&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dojo.byId('button2') or just button2 in the dojo.connect statement. Is this a matter of preference or is there a reason why you were more specific?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason why I coded the way I did was because I had looked at this &lt;/SPAN&gt;&lt;A href="http://serverapps.esri.com/javascript_examples/PopulateDropdownList.html"&gt;example &lt;/A&gt;&lt;SPAN&gt; and I saw that there was an onChange event in the combobox. It calls a function which changes the map based on a layer definition. So I thought it would be okay to do something similar with an onClick event. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why does this example not use a dojo.connect statement to tie it together as you showed in my original example?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 17:23:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173554#M16075</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2011-11-03T17:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: beginner: changing map extent on click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173555#M16076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I prefer to use dojo.connect() to wire up events as it keeps JavaScript separate from HTML. I do not like to embed JS in my markup. Separation of concerns and all that...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the first argument to dojo.connect, I prefer using dojo.byId() because it's explicit what is happening. It's perfectly reasonable to just use a string that corresponds to a DOM node's ID.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 17:30:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173555#M16076</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2011-11-03T17:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: beginner: changing map extent on click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173556#M16077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your help and clear explanations.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 17:33:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/beginner-changing-map-extent-on-click/m-p/173556#M16077</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2011-11-03T17:33:48Z</dc:date>
    </item>
  </channel>
</rss>

