<?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 Custom popup: how to wait for all promises after changing selectedFeatureIndex? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-how-to-wait-for-all-promises-after/m-p/1002367#M70842</link>
    <description>&lt;P&gt;Without posting a lengthy amount of code, I hope this will be sufficient for my question. I'm creating a custom popup that allows for multiple sublayers from a&amp;nbsp;MapImageLayer to be identified.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Popup_illustration.png" style="width: 200px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/376i60329F868DC69ACD/image-size/small?v=v2&amp;amp;px=200" role="button" title="Popup_illustration.png" alt="Popup_illustration.png" /&gt;&lt;/span&gt;&amp;nbsp;There is a &amp;lt;select&amp;gt; element that contains the layer names, and then some forward/backward navigation buttons if there are multiple features for any given sublayer.&lt;/P&gt;&lt;P&gt;My problem is that once I have the array of identified features, I need to be able to click on the layer dropdown and then choose the first feature belonging to that layer's array. After changing the selectedFeatureIndex, I cannot find a way to wait until it's finished with everything, because the dropdown gets reset when my popup gets reset. I need to detect when the popup update has completely finished.&amp;nbsp;&lt;/P&gt;&lt;P&gt;No matter what I watch – whether it's&amp;nbsp;&lt;FONT color="#0000FF"&gt;watchUtils.when(app.mapView.popup, "selectedFeature"&amp;nbsp;&lt;/FONT&gt;or&amp;nbsp;&lt;FONT color="#0000FF"&gt;watchUtils.whenNot(app.mapView.popup.viewModel, "pendingPromisesCount"&lt;/FONT&gt;&amp;nbsp;or anything else – the watch property methods are all too early. The only way it works is if I add a minimal timer delay (even 100 milliseconds is enough). So while it is a solution, it's not really a proper or ideal solution. Is there a certain promise or property to watch? How can I can know exactly when the popup has finished updating?&lt;/P&gt;&lt;P&gt;The "multi_feature_content" function simply builds the custom html for the popup:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; app.mapImgLyrUtilMap.allSublayers.map(function (sublayer) {
 
            sublayer.popupTemplate = new PopupTemplate({
             content: multi_feature_content,
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Setting the feature index:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;app.mapView.popup.selectedFeatureIndex = app.curAbsoluteFeatIdx;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to update my Select element (named with variable idSelectListId) to the currently selected layer name, but watchUtils.when (popup, "selectedFeature") runs too soon for my need.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; watchUtils.when(app.mapView.popup, "selectedFeature", function (selectedFeatureIndex) {
            console.log("app.mapView.popup selectedFeatureIndex: ", selectedFeatureIndex);
            setTimeout(function () {
                console.log("setSelectToCurrentLayer()...");
                // - Set to the already selected layer
                app.idSelectedLayer = document.getElementById(app.idSelectListId);
                console.log("app.idSelectedLayerCurSel: ", app.idSelectedLayerCurSel);
                console.log("app.idSelectedLayer: ", app.idSelectedLayer);

                if (app.idSelectedLayer &amp;amp;&amp;amp; app.idSelectedLayer.options) {
                    if (app.arrIdentifyAllSelectedLayers.indexOf(app.idSelectedLayerCurSel) &amp;gt; -1) {
                        for (var i = 0, j = app.idSelectedLayer.options.length; i &amp;lt; j; ++i) {
                            if (app.idSelectedLayer.options[i].innerHTML === app.idSelectedLayerCurSel) {
                                app.idSelectedLayer.selectedIndex = i;
                                break;
                            }
                        }
                    }
                }
            }, 100);
        });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2020 16:46:05 GMT</pubDate>
    <dc:creator>Andy_Morgan</dc:creator>
    <dc:date>2020-11-18T16:46:05Z</dc:date>
    <item>
      <title>Custom popup: how to wait for all promises after changing selectedFeatureIndex?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-how-to-wait-for-all-promises-after/m-p/1002367#M70842</link>
      <description>&lt;P&gt;Without posting a lengthy amount of code, I hope this will be sufficient for my question. I'm creating a custom popup that allows for multiple sublayers from a&amp;nbsp;MapImageLayer to be identified.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Popup_illustration.png" style="width: 200px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/376i60329F868DC69ACD/image-size/small?v=v2&amp;amp;px=200" role="button" title="Popup_illustration.png" alt="Popup_illustration.png" /&gt;&lt;/span&gt;&amp;nbsp;There is a &amp;lt;select&amp;gt; element that contains the layer names, and then some forward/backward navigation buttons if there are multiple features for any given sublayer.&lt;/P&gt;&lt;P&gt;My problem is that once I have the array of identified features, I need to be able to click on the layer dropdown and then choose the first feature belonging to that layer's array. After changing the selectedFeatureIndex, I cannot find a way to wait until it's finished with everything, because the dropdown gets reset when my popup gets reset. I need to detect when the popup update has completely finished.&amp;nbsp;&lt;/P&gt;&lt;P&gt;No matter what I watch – whether it's&amp;nbsp;&lt;FONT color="#0000FF"&gt;watchUtils.when(app.mapView.popup, "selectedFeature"&amp;nbsp;&lt;/FONT&gt;or&amp;nbsp;&lt;FONT color="#0000FF"&gt;watchUtils.whenNot(app.mapView.popup.viewModel, "pendingPromisesCount"&lt;/FONT&gt;&amp;nbsp;or anything else – the watch property methods are all too early. The only way it works is if I add a minimal timer delay (even 100 milliseconds is enough). So while it is a solution, it's not really a proper or ideal solution. Is there a certain promise or property to watch? How can I can know exactly when the popup has finished updating?&lt;/P&gt;&lt;P&gt;The "multi_feature_content" function simply builds the custom html for the popup:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; app.mapImgLyrUtilMap.allSublayers.map(function (sublayer) {
 
            sublayer.popupTemplate = new PopupTemplate({
             content: multi_feature_content,
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Setting the feature index:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;app.mapView.popup.selectedFeatureIndex = app.curAbsoluteFeatIdx;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to update my Select element (named with variable idSelectListId) to the currently selected layer name, but watchUtils.when (popup, "selectedFeature") runs too soon for my need.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; watchUtils.when(app.mapView.popup, "selectedFeature", function (selectedFeatureIndex) {
            console.log("app.mapView.popup selectedFeatureIndex: ", selectedFeatureIndex);
            setTimeout(function () {
                console.log("setSelectToCurrentLayer()...");
                // - Set to the already selected layer
                app.idSelectedLayer = document.getElementById(app.idSelectListId);
                console.log("app.idSelectedLayerCurSel: ", app.idSelectedLayerCurSel);
                console.log("app.idSelectedLayer: ", app.idSelectedLayer);

                if (app.idSelectedLayer &amp;amp;&amp;amp; app.idSelectedLayer.options) {
                    if (app.arrIdentifyAllSelectedLayers.indexOf(app.idSelectedLayerCurSel) &amp;gt; -1) {
                        for (var i = 0, j = app.idSelectedLayer.options.length; i &amp;lt; j; ++i) {
                            if (app.idSelectedLayer.options[i].innerHTML === app.idSelectedLayerCurSel) {
                                app.idSelectedLayer.selectedIndex = i;
                                break;
                            }
                        }
                    }
                }
            }, 100);
        });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 16:46:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-how-to-wait-for-all-promises-after/m-p/1002367#M70842</guid>
      <dc:creator>Andy_Morgan</dc:creator>
      <dc:date>2020-11-18T16:46:05Z</dc:date>
    </item>
  </channel>
</rss>

