<?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: show numeric scale for ArcGISDynamicMapServiceLayer? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/show-numeric-scale-for/m-p/108697#M10062</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I calculate my scale on an onExtentChange event using the XY dimensions of the map object (returned by the onExtentChange event) and the size of the mapDiv.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
dojo.connect(map, "onExtentChange", updateExtent);
dojo.connect(window, 'resize', mapResize); 

pixelPerMeter = 96/.0254; // Define pixel per meter value (96 pixels per inch)

function mapResize(){
 var resizeTimer;
 clearTimeout(resizeTimer);
 resizeTimer = setTimeout(function(){
&amp;nbsp; sizeMap();
&amp;nbsp; map.resize();
&amp;nbsp; map.reposition();
&amp;nbsp; }, 500);
}

function sizeMap(){
 mapWidthPx = window.innerWidth;
 // Using 57 pixels for control/information bars
 mapHeightPx = window.innerHeight - 57;
 // Set calculated height for mapDiv
 $("#map").css({"height" : (mapHeightPx + "px")});
}

function updateExtent(evt){
 mapScale = calcScale(evt.xmax, evt.xmin, evt.ymax, evt.ymin);
 displayMapScale(mapScale); // Write map scale out to 
}

function calcScale(maxX, minX, maxY, minY) {
 var meterX = Math.abs(maxX - minX);
 var meterY = Math.abs(maxY - minY);
 var scaleX = meterX / mapWidthPx * pixelPerMeter;
 var scaleY = meterY / mapHeightPx * pixelPerMeter;
 var scaleMin = Math.round((scaleY&amp;gt;scaleX)?scaleX:scaleY);
&amp;nbsp; return scaleMin;
}&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:33:17 GMT</pubDate>
    <dc:creator>JeffMitzelfelt</dc:creator>
    <dc:date>2021-12-11T06:33:17Z</dc:date>
    <item>
      <title>show numeric scale for ArcGISDynamicMapServiceLayer?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/show-numeric-scale-for/m-p/108695#M10060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd like to display a numeric scale value while using a ArcGISDynamicMapServiceLayer but the only code examples I've been able to find so far relate to using an ArcGISTiledMapServiceLayer in which the LOD has a scale property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can this be done with ArcGISDynamicMapServiceLayers and does anyone have an example they can share?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Nov 2011 19:58:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/show-numeric-scale-for/m-p/108695#M10060</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2011-11-21T19:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: show numeric scale for ArcGISDynamicMapServiceLayer?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/show-numeric-scale-for/m-p/108696#M10061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Steve,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It depends on the spatial reference, DPI and other factors. The easiest way probably is to add a scalebar on your map and exact the scale value from it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var scalebarLengthInPixel = scalebar.domNode.style.width; // For example, you may get "112px" as returned value
var scalebarLengthInReality = dojo.query(".esriScalebarSecondNumber", scalebar.domNode)[0].innerHTML; //you may get "300mi" as returned value
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, parse both values to numbers and calculate the scale value. For example, scalevalue = 300*1609*39.3700787*96/112&amp;nbsp; (1 mi = 1609 meters, 1 meter = 39.3700787 inches, and assuming the client DPI is 96)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you don't like a visible scalebar, you can always call&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;esri.hide(scalebar.domNode); to hide it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:33:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/show-numeric-scale-for/m-p/108696#M10061</guid>
      <dc:creator>JianHuang</dc:creator>
      <dc:date>2021-12-11T06:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: show numeric scale for ArcGISDynamicMapServiceLayer?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/show-numeric-scale-for/m-p/108697#M10062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I calculate my scale on an onExtentChange event using the XY dimensions of the map object (returned by the onExtentChange event) and the size of the mapDiv.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
dojo.connect(map, "onExtentChange", updateExtent);
dojo.connect(window, 'resize', mapResize); 

pixelPerMeter = 96/.0254; // Define pixel per meter value (96 pixels per inch)

function mapResize(){
 var resizeTimer;
 clearTimeout(resizeTimer);
 resizeTimer = setTimeout(function(){
&amp;nbsp; sizeMap();
&amp;nbsp; map.resize();
&amp;nbsp; map.reposition();
&amp;nbsp; }, 500);
}

function sizeMap(){
 mapWidthPx = window.innerWidth;
 // Using 57 pixels for control/information bars
 mapHeightPx = window.innerHeight - 57;
 // Set calculated height for mapDiv
 $("#map").css({"height" : (mapHeightPx + "px")});
}

function updateExtent(evt){
 mapScale = calcScale(evt.xmax, evt.xmin, evt.ymax, evt.ymin);
 displayMapScale(mapScale); // Write map scale out to 
}

function calcScale(maxX, minX, maxY, minY) {
 var meterX = Math.abs(maxX - minX);
 var meterY = Math.abs(maxY - minY);
 var scaleX = meterX / mapWidthPx * pixelPerMeter;
 var scaleY = meterY / mapHeightPx * pixelPerMeter;
 var scaleMin = Math.round((scaleY&amp;gt;scaleX)?scaleX:scaleY);
&amp;nbsp; return scaleMin;
}&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:33:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/show-numeric-scale-for/m-p/108697#M10062</guid>
      <dc:creator>JeffMitzelfelt</dc:creator>
      <dc:date>2021-12-11T06:33:17Z</dc:date>
    </item>
  </channel>
</rss>

