We use online basemaps for a mobile application. It is possible, however, that a user may not have connection at some locations. What happens in this situation is that the Layer:LoadAsync() for the ArcGISVectorTiledLayer simply hangs up. It never times out and shows a failure to load.
<SPAN class="keyword token">var</SPAN> layerUri <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> tiledLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ArcGISVectorTiledLayer</SPAN><SPAN class="punctuation token">(</SPAN>layerUri<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//hanges up at this line of code. LoadStatus goes into Loading but never changes</SPAN>
<SPAN class="keyword token">await</SPAN> tiledLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">LoadAsync</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>
Instead I am having to add code to determine if it times out. I used an HttpClient to see if I can hit the endpoint.
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//will timeout if unable to connect</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN>HttpClient client <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">HttpClient</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>Timeout <SPAN class="operator token">=</SPAN> TimeSpan<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FromSeconds</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">await</SPAN> client<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetStringAsync</SPAN><SPAN class="punctuation token">(</SPAN>layerUri<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">await</SPAN> tiledLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">LoadAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
map<SPAN class="punctuation token">.</SPAN>Basemap<SPAN class="punctuation token">.</SPAN>BaseLayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>tiledLayer<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="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> e<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
Log<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Error</SPAN><SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">.</SPAN>Message<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">await</SPAN> DialogService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">DisplayAlertAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Not Connected"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"No connection exists so basemap will not be loaded"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Ok"</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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>It seems to me the API should provide a way to know that a layer timed out trying to load. Am I just missing something?
Thanks
-Joe