<?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: Scope issue (maybe) in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259842#M83917</link>
    <description>&lt;P&gt;Thanks for taking the time to explain this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While I was unsure how to implement your suggestion, I had just added this to the constructor of the widget:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;constructor: function(args){
  				lang.mixin(this,args);
  				window.map = this.map;
				projection.load();
  			},&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know if pre-loading the projection in this manner is acceptable way to do it, it does work and allow a much simpler implementation of that&amp;nbsp;&lt;SPAN&gt;createGraphicFromGeometry() funtion and simply returns the graphic in the desired spatref.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Again -- the whole issue I'm dealing with is working with services published to an enterprise site that have a different spatial reference than the ESRI basemap that is loaded in the webmap source to this WAB app and just doesn't play well.&amp;nbsp; So simply forcing the same spatial reference on the geometry seems to work.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Feb 2023 14:56:06 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2023-02-20T14:56:06Z</dc:date>
    <item>
      <title>Scope issue (maybe)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259142#M83913</link>
      <description>&lt;P&gt;JS 3.x&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code running in a custom widget from WAB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We're just trying to determine how to work with geometry from a feature service that has a spatial reference of wkid 2881 but our existing code was failing trying to load a graphics layer with the geometry throwing the error,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Geometry (wkid: 2881) cannot be converted to spatial reference of the map (wkid: 102100)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So we identified where this was happening and thought to just try and do a reprojection but I keep&amp;nbsp;getting undefined geometry when I attempt to implement,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe it's a simple scope issue?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;getGraphicFromQueryResults: function(queryResults){
					if (queryResults &amp;amp;&amp;amp; queryResults.features.length &amp;gt; 0){
						var theGraphic = this.createGraphicFromGeometry(queryResults.features[0].geometry);
						//theGraphic always returns undefined
						console.log(theGraphic) 
						return theGraphic //this.createGraphicFromGeometry(queryResults.features[0].geometry);
					}
				},
				
				createGraphicFromGeometry: function(geometry){
					projection.load().then(lang.hitch(this, function () {
						
						const inSpatialReference = new SpatialReference({ wkid: 2881 });
						const spSpatialReference = new SpatialReference({ wkid: 4326 });
						const poly = new Polygon(geometry, inSpatialReference);
						var geoT = projection.getTransformation(inSpatialReference, spSpatialReference)
						const projectedPoly = projection.project(poly, spSpatialReference);
					
						var attributes = {};
						attributes[this.config.applicationIdField] = this.appId;						
					
						var graphic = new Graphic(projectedPoly,null,attributes);
						console.log(graphic)

					return graphic;
				 }).bind(this))
				}&lt;/LI-CODE&gt;&lt;P&gt;Or any comment on how to deal with with services with other spatial references than what ESRI basemaps seems to require?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 22:05:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259142#M83913</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2023-02-16T22:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Scope issue (maybe)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259252#M83914</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/8274"&gt;@JamesCrandall&lt;/a&gt;&amp;nbsp;The method "createGraphicFromGeometry" is an async function, so you need to use "await" or use the ".then()" to get the function return value.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 08:25:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259252#M83914</guid>
      <dc:creator>Junshan_Liu</dc:creator>
      <dc:date>2023-02-17T08:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Scope issue (maybe)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259275#M83915</link>
      <description>&lt;P&gt;thank you, do you have any suggestions where to place .then()&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 11:44:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259275#M83915</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2023-02-17T11:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Scope issue (maybe)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259744#M83916</link>
      <description>&lt;P&gt;It should be something like this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;this.createGraphicFromGeometry(queryResults.features[0].geometry).then(theGraphic =&amp;gt; {
  console.log(theGraphic)
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, function&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;createGraphicFromGeometry&lt;/EM&gt; must return the promise, like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;createGraphicFromGeometry: function () {
  return projection.load()
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Feb 2023 01:39:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259744#M83916</guid>
      <dc:creator>Junshan_Liu</dc:creator>
      <dc:date>2023-02-20T01:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Scope issue (maybe)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259842#M83917</link>
      <description>&lt;P&gt;Thanks for taking the time to explain this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While I was unsure how to implement your suggestion, I had just added this to the constructor of the widget:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;constructor: function(args){
  				lang.mixin(this,args);
  				window.map = this.map;
				projection.load();
  			},&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know if pre-loading the projection in this manner is acceptable way to do it, it does work and allow a much simpler implementation of that&amp;nbsp;&lt;SPAN&gt;createGraphicFromGeometry() funtion and simply returns the graphic in the desired spatref.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Again -- the whole issue I'm dealing with is working with services published to an enterprise site that have a different spatial reference than the ESRI basemap that is loaded in the webmap source to this WAB app and just doesn't play well.&amp;nbsp; So simply forcing the same spatial reference on the geometry seems to work.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 14:56:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/scope-issue-maybe/m-p/1259842#M83917</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2023-02-20T14:56:06Z</dc:date>
    </item>
  </channel>
</rss>

