<?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 Get scale for a box in JS 4 in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-scale-for-a-box-in-js-4/m-p/1314843#M81846</link>
    <description>&lt;P&gt;In JS API 3.x we could get easily the scale for a box drawn on the map after you define its 4 corners.&lt;/P&gt;&lt;P&gt;In the matrix for the migration from 3.x to 4.x, it states that there are no plans for the scaleUtils to be migrated.&lt;/P&gt;&lt;P&gt;So, what's the best option to get the scale in 4.x?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var scale = esri.geometry.scaleUtils.getScaleForBox(
  box,
  map.getSpatialReference()
); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2023 22:14:40 GMT</pubDate>
    <dc:creator>LefterisKoumis</dc:creator>
    <dc:date>2023-08-02T22:14:40Z</dc:date>
    <item>
      <title>Get scale for a box in JS 4</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-scale-for-a-box-in-js-4/m-p/1314843#M81846</link>
      <description>&lt;P&gt;In JS API 3.x we could get easily the scale for a box drawn on the map after you define its 4 corners.&lt;/P&gt;&lt;P&gt;In the matrix for the migration from 3.x to 4.x, it states that there are no plans for the scaleUtils to be migrated.&lt;/P&gt;&lt;P&gt;So, what's the best option to get the scale in 4.x?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var scale = esri.geometry.scaleUtils.getScaleForBox(
  box,
  map.getSpatialReference()
); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 22:14:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-scale-for-a-box-in-js-4/m-p/1314843#M81846</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2023-08-02T22:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get scale for a box in JS 4</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-scale-for-a-box-in-js-4/m-p/1315772#M81867</link>
      <description>&lt;P&gt;I haven't found any "getScaleForBox" function in the implementation of scaleUtils, however you can achieve the same result in 3.x via scaleUtils.getScale(map, extent, spatialReference), although the 2nd and 3rd parameters &lt;A href="https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.scaleutils-amd.html#getscale" target="_self"&gt;aren't documented&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;As for 4.x, the implementation of the 3.x scaleUtils is fairly simple.&amp;nbsp; Migrating the relevant part to 4.x yields something like the following:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const screenDPI = 96;

function _getUnitValue(spatialReference) {
	if (spatialReference) {
		var wkid, wkt;

		if (typeof spatialReference == "object") {
			wkid = spatialReference.wkid;
			wkt = spatialReference.wkt;
		} else if (typeof spatialReference == "number")
			wkid = spatialReference;
		else if (typeof spatialReference == "string")
			wkt = spatialReference;

		if ((typeof wkid == "number") &amp;amp;&amp;amp; (wkid &amp;gt;= 0))
			return WKIDUnitConversion.values[WKIDUnitConversion[wkid]];
		else if ((typeof wkt == "string") &amp;amp;&amp;amp; (wkt.search(/^PROJCS/i) !== -1)) {
			var a = /UNIT\[([^\]]+)\]\]$/i.exec(wkt);

			if ((a) &amp;amp;&amp;amp; (a[1]))
				return parseFloat(a[1].split(",")[1]);
		}
	}

	return 0;
}

function getScale(mapView, extent, spatialReference) {
	if ((mapView) &amp;amp;&amp;amp; (mapView.width)) {
		var scaleExtent = extent || mapView.extent;

		if (scaleExtent) {
			var srUnitValue = _getUnitValue(spatialReference || scaleExtent.spatialReference);
			var unitValue = ((srUnitValue) ? srUnitValue : 6370997 * Math.PI / 180);

			return scaleExtent.width / mapView.width * unitValue * 39.37 * screenDPI;
		}
	}

	return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As with 3.x, the 2nd and 3rd parameters are optional.&amp;nbsp; Note that "WKIDUnitConversion" is&amp;nbsp;esri/geometry/support/WKIDUnitConversion, which you'll need to include.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Aug 2023 00:53:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-scale-for-a-box-in-js-4/m-p/1315772#M81867</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-08-05T00:53:28Z</dc:date>
    </item>
  </channel>
</rss>

