<?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: Getting back value of a variable within a function in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401407#M84134</link>
    <description>&lt;P&gt;Thank you very much for your reply, but in that case, it`s not the solution.&lt;/P&gt;&lt;P&gt;In my case I use an adress-search with an own REST-Service. After searching for an adress I have a code like...&lt;/P&gt;&lt;P&gt;getResults: (params) =&amp;gt; {...&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;I get results there and later on in the code&lt;/P&gt;&lt;P&gt;I successfully get them by:&lt;/P&gt;&lt;P&gt;return searchResult;&lt;/P&gt;&lt;P&gt;But: In the "gettingResults-area" I have to reproject some coordinates.&lt;/P&gt;&lt;P&gt;As far as I can see the only possibility in using the "projection.project"-function is within an:&lt;/P&gt;&lt;P&gt;projection.load().then(function() {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;punkt2=projection.project(punkt1, cs2);&lt;BR /&gt;alert ("1:"+punkt2.x);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;....so far so good. But I have to do some other things with the result outside of that function, like:&lt;/P&gt;&lt;P&gt;alert ("2:"+punkt2.x);&lt;/P&gt;&lt;P&gt;var x_koordinate=punkt2.x;&lt;BR /&gt;var y_koordinate=punkt2.y;&lt;/P&gt;&lt;P&gt;const graphic = new Graphic({&lt;BR /&gt;geometry: new Point({&lt;BR /&gt;x: x_koordinate,&lt;BR /&gt;y: y_koordinate&lt;BR /&gt;})&lt;BR /&gt;,attributes: feature.attributes&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;const buffer = geometryEngine.geodesicBuffer(&lt;BR /&gt;graphic.geometry,&lt;BR /&gt;100,&lt;BR /&gt;"meters"&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;....but I don`t get the value out of the projection.load().then(function() { }. That is the problem.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2024 13:29:55 GMT</pubDate>
    <dc:creator>KaiBehncke</dc:creator>
    <dc:date>2024-03-27T13:29:55Z</dc:date>
    <item>
      <title>Getting back value of a variable within a function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401378#M84132</link>
      <description>&lt;P&gt;Dear users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use in ArcGIS Maps SDK 4.29 "projection" to reproject coordinates:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; require([&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "esri/geometry/projection"&lt;BR /&gt;], function(projection) { ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do it in that way:&lt;/P&gt;&lt;P&gt;projection.load().then(function() {&lt;BR /&gt;var punkt2=projection.project(punkt1, cs2);&lt;BR /&gt;alert ("In Function: "+punkt2.x);&lt;BR /&gt;});&lt;BR /&gt;&lt;BR /&gt;alert ("Ausserhalb Function: "+punkt2.x);&lt;/P&gt;&lt;P&gt;Within the function it works fine. "alert ("In Function: "+punkt2.x);"&lt;/P&gt;&lt;P&gt;shows the correct coordinate value I want to have.&lt;/P&gt;&lt;P&gt;But outside the function: How can I get the value then? I `m looking for a way to get the value back to use it outside the function.&lt;/P&gt;&lt;P&gt;Could anybody help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 12:16:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401378#M84132</guid>
      <dc:creator>KaiBehncke</dc:creator>
      <dc:date>2024-03-27T12:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Getting back value of a variable within a function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401389#M84133</link>
      <description>&lt;P&gt;In your case, I think the easiest thing to do would be to define the variable outside the function and then set the value inside the function. Like this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var punkt2 = null

projection.load().then(function() {
punkt2=projection.project(punkt1, cs2);
alert ("In Function: "+punkt2.x);
});

//As writen, punkt2.x will likely be undefined, but would eventually be correct.
alert ("Ausserhalb Function: "+punkt2.x);&lt;/LI-CODE&gt;&lt;P&gt;Be aware that Javascript executes synchronously, so it will attempt to run every line of code without waiting for earlier lines to complete. The .then() function causes the code inside the parenthesis to wait for the projection.load() function to complete before executing. As the code block above is written,&amp;nbsp;&lt;SPAN&gt;punkt2.x will likely be undefined because the alert() function will likely execute faster than the load() function will complete. Given more time to execute, the&amp;nbsp;punkt2.x would eventually become correct.&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 12:46:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401389#M84133</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-03-27T12:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Getting back value of a variable within a function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401407#M84134</link>
      <description>&lt;P&gt;Thank you very much for your reply, but in that case, it`s not the solution.&lt;/P&gt;&lt;P&gt;In my case I use an adress-search with an own REST-Service. After searching for an adress I have a code like...&lt;/P&gt;&lt;P&gt;getResults: (params) =&amp;gt; {...&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;I get results there and later on in the code&lt;/P&gt;&lt;P&gt;I successfully get them by:&lt;/P&gt;&lt;P&gt;return searchResult;&lt;/P&gt;&lt;P&gt;But: In the "gettingResults-area" I have to reproject some coordinates.&lt;/P&gt;&lt;P&gt;As far as I can see the only possibility in using the "projection.project"-function is within an:&lt;/P&gt;&lt;P&gt;projection.load().then(function() {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;punkt2=projection.project(punkt1, cs2);&lt;BR /&gt;alert ("1:"+punkt2.x);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;....so far so good. But I have to do some other things with the result outside of that function, like:&lt;/P&gt;&lt;P&gt;alert ("2:"+punkt2.x);&lt;/P&gt;&lt;P&gt;var x_koordinate=punkt2.x;&lt;BR /&gt;var y_koordinate=punkt2.y;&lt;/P&gt;&lt;P&gt;const graphic = new Graphic({&lt;BR /&gt;geometry: new Point({&lt;BR /&gt;x: x_koordinate,&lt;BR /&gt;y: y_koordinate&lt;BR /&gt;})&lt;BR /&gt;,attributes: feature.attributes&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;const buffer = geometryEngine.geodesicBuffer(&lt;BR /&gt;graphic.geometry,&lt;BR /&gt;100,&lt;BR /&gt;"meters"&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;....but I don`t get the value out of the projection.load().then(function() { }. That is the problem.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 13:29:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401407#M84134</guid>
      <dc:creator>KaiBehncke</dc:creator>
      <dc:date>2024-03-27T13:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Getting back value of a variable within a function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401410#M84135</link>
      <description>&lt;P&gt;You should move your additional logic to within the .then() function or to functions that are called from within the .then() function.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 13:35:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-back-value-of-a-variable-within-a-function/m-p/1401410#M84135</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-03-27T13:35:50Z</dc:date>
    </item>
  </channel>
</rss>

