TLDR:
I am using a BasemapGalleryWidget in my application, which is pointed at my Portal (so all the basemaps loaded in the basemap gallery are those configured as basemaps in my Portal).
I want to detect when not only the basemap gallery widget has populated all the basemaps, but also when the titles are populated on each basemap.
So far I have:
<SPAN class="keyword token">let</SPAN> gallery <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">BasemapGallery</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
container<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"basemapDiv"</SPAN><SPAN class="punctuation token">,</SPAN>
view<SPAN class="punctuation token">:</SPAN> sceneView
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//watch for basemaps to get populated</SPAN>
<SPAN class="keyword token">var</SPAN> handle <SPAN class="operator token">=</SPAN> watchUtils<SPAN class="punctuation token">.</SPAN><SPAN class="token function">when</SPAN><SPAN class="punctuation token">(</SPAN>gallery<SPAN class="punctuation token">.</SPAN>source<SPAN class="punctuation token">.</SPAN>basemaps<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"length"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//watch for names to get populated</SPAN>
watchUtils<SPAN class="punctuation token">.</SPAN><SPAN class="token function">watch</SPAN><SPAN class="punctuation token">(</SPAN>gallery<SPAN class="punctuation token">.</SPAN>source<SPAN class="punctuation token">.</SPAN>basemaps<SPAN class="punctuation token">.</SPAN>items<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"title"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>
gallery<SPAN class="punctuation token">.</SPAN>source<SPAN class="punctuation token">.</SPAN>basemaps<SPAN class="punctuation token">.</SPAN>items<SPAN class="punctuation token">.</SPAN><SPAN class="token function">forEach</SPAN><SPAN class="punctuation token">(</SPAN>bs<SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN>bs<SPAN class="punctuation token">.</SPAN>title<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>But since each item gets it's title individually, this doesn't really work - because I assume it's a different request for each basemap to get the thumbnail, title, etc. etc. I'm unclear how to detect on a widget when the whole thing has loaded.
Any tips?
The longer version of my problem is this:
I want my application to load the last basemap a user had selected for the app (I'm using local storage). Suppose they selected a basemap from my Portal called "Colored Pencil". So I load that string from local storage, but I can't really instantiate a Map when my app loads with
<SPAN class="keyword token">let</SPAN> esriMap <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">EsriMap</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
basemap<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Colored Pencil"</SPAN><SPAN class="punctuation token">,</SPAN>
ground<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"world-elevation"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The map constructor only accepts the 12 or so "satellite", 'dark-gray", "osm", etc. etc.
My (intended) solution to this is to wait for the BasemapGallery widget to complete loading, and programmatically select the correct basemap by the string.
const basemap = gallery.source.basemaps.items.filter(bm=>bm.title=="Colored Pencil")[0];
gallery.activeBasemap = basemap;<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
This would hopefully just change the basemap. Yet to be seen.
Yet I'm stuck on watchUtils or the BasemapGalleryViewModel to let me know once the widget has completed all it's requests and populated all it's properties.
Any tips here?