update entries on form select based on layer list

688
4
03-21-2017 08:55 PM
LefterisKoumis
Occasional Contributor III

I have a widget A that adds layers on the map.

Then, it calls widget B which opens with:

 getallLAyers:function(){
          LayerInfos.getInstance(this.map, this.map.itemInfo).then(lang.hitch(this, function (layerInfosObject) {  
               layerInfosObject.getLayerInfoArray().forEach(lang.hitch(this, function(layerInfo,index){
                    if (layerInfo.getUrl() != null){
                    option = {
                         value: index,
                         label: layerInfo.title,
                         myurl: layerInfo.getUrl()
                    };
                    console.log(option.myurl);
                    this.resultLayers.push(option); 
                    }
               }));
          }));      
          
     },

and the resultLayers array populates a  select dropdown.

If  widget A adds another layer on the map, even if widget A closes and reopens widget B, the widget B does not update the entries of the select with the new layers. Ideas?  Thank you.

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  Instead of using LayerInfos.getInstance use LayerInfos.getInstanceSync

var layerInfos = LayerInfos.getInstanceSync();
0 Kudos
LefterisKoumis
Occasional Contributor III

Are there any info on the LayerInfos.getInstanceSync for its use? ESRI documentation is very vague. I tried as you suggested but I get layerInfos(...).then is not a function

var layerInfos = LayerInfos.getInstanceSync();

layerInfos(this.map, ....

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   I have no idea what you are doing here:

layerInfos(this.map, ....

layerInfos is an object

So something like your code would look like:

var layerInfos = LayerInfos.getInstanceSync();
layerInfos.getLayerInfoArray().forEach(lang.hitch(this, function(layerInfo,index){....
0 Kudos
LefterisKoumis
Occasional Contributor III

Thanks. Yes you are right, I was clearly confused. I tried your latest recommendation and still didn't work. However, I found this response by you to another question. https://community.esri.com/thread/175677 

 In widget B, I placed the map event listener for layers additions/removals and refresh the array for the select dropdown. It does work. Thank you. 

0 Kudos