<?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: map.setExtent() bug in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181493#M16843</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Derek,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That does indeed fix it.&amp;nbsp; I had overlooked that parameter in the API reference.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Apr 2012 18:08:33 GMT</pubDate>
    <dc:creator>JasonKnisley</dc:creator>
    <dc:date>2012-04-06T18:08:33Z</dc:date>
    <item>
      <title>map.setExtent() bug</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181490#M16840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Several months ago I made a post similar to this on the forums for the ArcGIS API for Android.&amp;nbsp; I'm now exploring mobile web apps using Javascript instead, and discovered what appears to be a bug in the setExtent() method.&amp;nbsp; I'm using this method to zoom the map into an extent which includes the user's location and a selected destination including a small buffer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you specify the boundaries for the extent, a logical assumption is that a rectangle will be created which contains, at a minimum, the points xmin,ymin and xmax,ymax.&amp;nbsp; Obviously the parameters given may need to be adjusted to accommodate the current map dimensions, but this does not happen correctly in some cases.&amp;nbsp; In its current implementation setExtent() creates an extent which encompasses the x-boundaries, but not necessarily the y-boundaries.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the following examples I'll refer to dx (xmax-xmin) and dy (ymax-ymin).&amp;nbsp; If dx is large relative to dy (for example, the user selects a point that is west or east of their current location), then then ymax and ymin are adjusted as needed and the map zooms appropriately.&amp;nbsp; On the other hand, if dx is very small relative to dy (for example, the user selects a point that is north or south of their current location), then the map zooms in much too close.&amp;nbsp; It sets the x borders at xmin and xmax, but ymin and ymax are placed off of the screen.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is code that I currently use as a workaround.&amp;nbsp; It assumes the device is in portrait mode, but could easily be modified to handle screens of various dimensions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;function zoomToPoints(point1, point2) {
 var xmin, ymin, xmax, ymax;
 
 if (point1.x &amp;lt; point2.x) {
&amp;nbsp; xmin = point1.x;
&amp;nbsp; xmax = point2.x;
 } else {
&amp;nbsp; xmin = point2.x;
&amp;nbsp; xmax = point1.x;
 }
 if (point1.y &amp;lt; point2.y) {
&amp;nbsp; ymin = point1.y;
&amp;nbsp; ymax = point2.y;
 } else {
&amp;nbsp; ymin = point2.y;
&amp;nbsp; ymax = point1.y;
 }
 
 // add buffer to envelope so that points aren't on the edge of the screen
 var xBuffer = (xmax - xmin) * 0.2;
 var yBuffer = (ymax - ymin) * 0.4;
 xmax += xBuffer;
 xmin -= xBuffer;
 ymax += yBuffer;
 ymin -= yBuffer;
 
 // to zoom appropriately under the current API, dY/dX should be approximately 127/80 based on emulator experiments in portrait mode
 // if dX is small then it needs to be adjusted based on dY before calling setExtent()
 if ((ymax-ymin) / (xmax-xmin) &amp;gt; 127.0/80.0) {
&amp;nbsp; var dX = 80.0 * (ymax-ymin) / 127.0; 
&amp;nbsp; xmax = ((xmax+xmin)/2.0) + (dX / 2.0);
&amp;nbsp; xmin = ((xmax+xmin)/2.0) - (dX / 2.0);
 }
 
 // set the map's new extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; map.setExtent(new esri.geometry.Extent({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "xmin": xmin,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ymin": ymin,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "xmax": xmax,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ymax": ymax,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "spatialReference": {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "wkid": 102100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }));
}&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 16:52:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181490#M16840</guid>
      <dc:creator>JasonKnisley</dc:creator>
      <dc:date>2012-03-28T16:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: map.setExtent() bug</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181491#M16841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Any thoughts from a dev?&amp;nbsp; Is that a bug or intended behavior?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 19:35:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181491#M16841</guid>
      <dc:creator>JasonKnisley</dc:creator>
      <dc:date>2012-03-30T19:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: map.setExtent() bug</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181492#M16842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/map.htm#setExtent"&gt;setExtent&lt;/A&gt;&lt;SPAN&gt; takes an optional, boolean parameter that can be used to specify that the map should fit the entire extent. Does using setExtent(extent, true) fix this for you?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Mar 2012 22:00:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181492#M16842</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2012-03-31T22:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: map.setExtent() bug</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181493#M16843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Derek,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That does indeed fix it.&amp;nbsp; I had overlooked that parameter in the API reference.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 18:08:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181493#M16843</guid>
      <dc:creator>JasonKnisley</dc:creator>
      <dc:date>2012-04-06T18:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: map.setExtent() bug</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181494#M16844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My pleasure! Can you mark my post as an answer?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 23:54:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-setextent-bug/m-p/181494#M16844</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2012-04-06T23:54:52Z</dc:date>
    </item>
  </channel>
</rss>

