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.
Lefteris,
Instead of using LayerInfos.getInstance use LayerInfos.getInstanceSync
var layerInfos = LayerInfos.getInstanceSync();
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();
l
ayerInfos(this.map, ....
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){
....
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.