<?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>idea Make layer refresh method return a promise in ArcGIS JavaScript Maps SDK Ideas</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idi-p/1163799</link>
    <description>&lt;P&gt;Up until the current API version (4.23), the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#refresh" target="_blank" rel="noopener"&gt;refresh method&lt;/A&gt; on refreshable layers returns void.&lt;/P&gt;&lt;P&gt;I think it would be useful if the method got converted to a promise so developers can react when the refresh is successful or has failed.&lt;/P&gt;&lt;P&gt;For the moment, I have implemented something that notifies me when the refresh is done regardless of the fact that it has succeeded or failed.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;new Promise&amp;lt;void&amp;gt;((resolve, reject) =&amp;gt; {
    layer.refresh();
    view.whenLayerView(layer)
        .then((layerView) =&amp;gt; whenFalseOnce(layerView, "updating", () =&amp;gt; resolve()))
        .catch((reason) =&amp;gt; reject(reason));
})&lt;/LI-CODE&gt;&lt;P&gt;The main goal would be to react when a refresh on a layer has failed.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Apr 2022 09:51:55 GMT</pubDate>
    <dc:creator>JonasDePelsmaeker</dc:creator>
    <dc:date>2022-04-13T09:51:55Z</dc:date>
    <item>
      <title>Make layer refresh method return a promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idi-p/1163799</link>
      <description>&lt;P&gt;Up until the current API version (4.23), the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#refresh" target="_blank" rel="noopener"&gt;refresh method&lt;/A&gt; on refreshable layers returns void.&lt;/P&gt;&lt;P&gt;I think it would be useful if the method got converted to a promise so developers can react when the refresh is successful or has failed.&lt;/P&gt;&lt;P&gt;For the moment, I have implemented something that notifies me when the refresh is done regardless of the fact that it has succeeded or failed.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;new Promise&amp;lt;void&amp;gt;((resolve, reject) =&amp;gt; {
    layer.refresh();
    view.whenLayerView(layer)
        .then((layerView) =&amp;gt; whenFalseOnce(layerView, "updating", () =&amp;gt; resolve()))
        .catch((reason) =&amp;gt; reject(reason));
})&lt;/LI-CODE&gt;&lt;P&gt;The main goal would be to react when a refresh on a layer has failed.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 09:51:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idi-p/1163799</guid>
      <dc:creator>JonasDePelsmaeker</dc:creator>
      <dc:date>2022-04-13T09:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Make layer refresh method return a promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1163991#M139</link>
      <description>&lt;P&gt;Hi Jonas,&lt;/P&gt;&lt;P&gt;Your function is the way to go. This is not possible to change RefreshableLayer.refresh() for a couple of reasons.&lt;/P&gt;&lt;P&gt;- Layers are not aware of the views and layerviews. Multiple MapViews can display a same map and layers. So that function can only be done from the application code that knows about both the view and the layer.&lt;/P&gt;&lt;P&gt;- There is no way to detect when a refresh is actually finished. While the layerview is refreshing, the user can still pan and zoom, and "updating" will remain true until the data is fully updated.&lt;/P&gt;&lt;P&gt;Here's another version of your function that ensure the layerview is updating then not updating:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;async function refreshLayer(layer, view) {
  layer.refresh();
  const layerView = view.allLayerViews.find((layerView) =&amp;gt; layerView.layer === layer);
  await reactiveUtils.once(() =&amp;gt; layerView.updating);
  await reactiveUtils.once(() =&amp;gt; !layerView.updating);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Your goal is to detect when a refresh has failed. It can mean a lot of things. In the case of a tile layer for example, we can't consider that the refresh has failed because one tile failed to refresh. For feature layers, data is fetched using different strategies depending on the server capabilities.&lt;/P&gt;&lt;P&gt;It would be helpful to get more information about the information you would need, and how it would translate in the UX.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The only way to detect that some data failed to be fetched at the moment is to create a log interceptor&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#log" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#log&lt;/A&gt;&amp;nbsp;to intercept the messages in the console.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 16:25:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1163991#M139</guid>
      <dc:creator>YannCabon</dc:creator>
      <dc:date>2022-04-13T16:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Make layer refresh method return a promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1164311#M140</link>
      <description>&lt;P&gt;Hi Yann,&lt;/P&gt;&lt;P&gt;Thank you for your response and your explanation! It is indeed difficult to define when a refresh was actually failed.&lt;/P&gt;&lt;P&gt;The client wants to have a&amp;nbsp; general 'refresh map' button. When clicking on that button, all the layers of the map should be refreshed. After completing the refresh (either a failed or succeeded refresh), a snackbar is shown to the user with the message the refresh is successful or not.&lt;/P&gt;&lt;P&gt;I have implemented your proposed solution by using the log interceptor. This works perfectly for my client's purpose.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 08:40:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1164311#M140</guid>
      <dc:creator>JonasDePelsmaeker</dc:creator>
      <dc:date>2022-04-14T08:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Make layer refresh method return a promise - Status changed to: Closed</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1210624#M171</link>
      <description />
      <pubDate>Thu, 08 Sep 2022 01:01:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1210624#M171</guid>
      <dc:creator>BjornSvensson</dc:creator>
      <dc:date>2022-09-08T01:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Make layer refresh method return a promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1364706#M304</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/881"&gt;@BjornSvensson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read your explanation, also have similiar requirement but some diffrent way.&lt;/P&gt;&lt;P&gt;I am using JS API 4.28, in that i have total 7 layers(Feature Layers &amp;amp; Map Image Layers) using definitionexpression to filter the data and generate dynamic renderer for each layers and set the rendered to each layers.&lt;/P&gt;&lt;P&gt;Now the issue is, layers attribute values are changed on button click, and rendrer generated on the updated values sometimes renderer not generated correctly.. and colors are not displayed correctly.&lt;/P&gt;&lt;P&gt;When i reload the page it is shown correctly, but my requirement is to refresh the layers and display the updated layers on map.&lt;/P&gt;&lt;P&gt;I have tried layer.refresh() but it is not working correctly.&lt;/P&gt;&lt;P&gt;My intrest is to refresh the map/view only bcoz after reloading it is displaying correctly, so now my req is to suggest some workaround to reload/refresh the map/view of all added layers.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 11:44:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-ideas/make-layer-refresh-method-return-a-promise/idc-p/1364706#M304</guid>
      <dc:creator>SaurabhUpadhyaya</dc:creator>
      <dc:date>2023-12-28T11:44:29Z</dc:date>
    </item>
  </channel>
</rss>

