<?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 Re: ArcGISVectorTiledLayer not showing when assigned to Map in async method in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/arcgisvectortiledlayer-not-showing-when-assigned/m-p/1217612#M11376</link>
    <description>&lt;P&gt;One thing you are not doing is calling .LoadAsync().&amp;nbsp; Personally I don't like directly calling a async method from a constructor.&amp;nbsp; The way I do something similar.&amp;nbsp; Create a simple event&amp;nbsp;LoadMapEvent&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public MainWindowViewModel(IEventAggregator eventAggregator)
{
	//Allow async for loading map
	eventAggregator.GetEvent&amp;lt;LoadMapEvent&amp;gt;().Subscribe(OnLoadMap);

	eventAggregator.GetEvent&amp;lt;LoadMapEvent&amp;gt;().Publish();
}

private async void OnLoadMap()
{
	try
	{
		//add layers
		await Map.LoadAsync();
	}
	catch (Exception e)
	{
		_log?.Error(e, e.Message);
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Sep 2022 20:38:49 GMT</pubDate>
    <dc:creator>JoeHershman</dc:creator>
    <dc:date>2022-09-29T20:38:49Z</dc:date>
    <item>
      <title>ArcGISVectorTiledLayer not showing when assigned to Map in async method</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/arcgisvectortiledlayer-not-showing-when-assigned/m-p/1217291#M11369</link>
      <description>&lt;P&gt;I have a WPF app using MVVM/Prism and .NET Runtime SDK.&lt;/P&gt;&lt;P&gt;Simple VM with a Map property which is bound to a MapView.Map in the control. I am adding 2 layers to the Map's base layers collection. I am adding a `ArcGISMapImageLayer` and a `ArcGISVectorTiledLayer`.&lt;/P&gt;&lt;P&gt;When I assign the layers in the VM constructor, everything works fine. When I assign the layers in an async method called from the constructor (via fire and forget), only the&amp;nbsp;`ArcGISMapImageLayer` gets shown in the MapView when the UI lods, not the `ArcGISVectorTiledLayer`. I've played with it a lot, changing order of addition, explicitly calling it on the UI thread, but it all behaves the same when the layers are added in an async method.&lt;/P&gt;&lt;P&gt;The reason for an async method is that I want to load the layers but have removed the extra code for clarity. The SetupLayers() method is commented out on purpose in the given snippet. When the constructor calls it, the problem occurs.&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;&lt;LI-CODE lang="csharp"&gt;namespace NFS_POC.Views
{
    internal class MainMapVM : BindableBase
    {
        public MainMapVM()
        {

            Map = new Map
            {
                InitialViewpoint = new Viewpoint(59, 6, 1000000)
            };

    
            // SetupLayers();

 

            // this works fine
            var imageLayer = new ArcGISMapImageLayer(new Uri("https://services.server.tld/arcgis/rest/services/something/something2/MapServer"));
            Map.Basemap.BaseLayers.Add(imageLayer);

 

            // this works fine
            var vectorTiledLayer = new ArcGISVectorTiledLayer(new Uri("https://services.server.tld/arcgis/rest/services/foo/bar/VectorTileServer"));
            Map.Basemap.BaseLayers.Add(vectorTiledLayer);        
        }

        private async Task SetupLayers()
        {
            // this works fine
            var imageLayer = new ArcGISMapImageLayer(new Uri("https://services.server.tld/arcgis/rest/services/something/something2/MapServer"));
            Map.Basemap.BaseLayers.Add(imageLayer);

 

            // this does not work???
            var vectorTiledLayer = new ArcGISVectorTiledLayer(new Uri("https://services.server.tld/arcgis/rest/services/foo/bar/VectorTileServer"));
            Map.Basemap.BaseLayers.Add(vectorTiledLayer);
        }
 

        private Map _map;
        public Map Map
        {
            get { return _map; }
            set { SetProperty(ref _map, value); }
        }        
    }
}&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;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 29 Sep 2022 09:51:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/arcgisvectortiledlayer-not-showing-when-assigned/m-p/1217291#M11369</guid>
      <dc:creator>ViktorSafar</dc:creator>
      <dc:date>2022-09-29T09:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGISVectorTiledLayer not showing when assigned to Map in async method</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/arcgisvectortiledlayer-not-showing-when-assigned/m-p/1217612#M11376</link>
      <description>&lt;P&gt;One thing you are not doing is calling .LoadAsync().&amp;nbsp; Personally I don't like directly calling a async method from a constructor.&amp;nbsp; The way I do something similar.&amp;nbsp; Create a simple event&amp;nbsp;LoadMapEvent&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public MainWindowViewModel(IEventAggregator eventAggregator)
{
	//Allow async for loading map
	eventAggregator.GetEvent&amp;lt;LoadMapEvent&amp;gt;().Subscribe(OnLoadMap);

	eventAggregator.GetEvent&amp;lt;LoadMapEvent&amp;gt;().Publish();
}

private async void OnLoadMap()
{
	try
	{
		//add layers
		await Map.LoadAsync();
	}
	catch (Exception e)
	{
		_log?.Error(e, e.Message);
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 20:38:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/arcgisvectortiledlayer-not-showing-when-assigned/m-p/1217612#M11376</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2022-09-29T20:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGISVectorTiledLayer not showing when assigned to Map in async method</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/arcgisvectortiledlayer-not-showing-when-assigned/m-p/1218105#M11383</link>
      <description>&lt;P&gt;Yeah, agreed that calling an async method from a constructor is not a good design. I am in a recon/play mode trying to see what the framework can do.&lt;/P&gt;&lt;P&gt;However, I would argue that you're basically doing the same. &lt;A href="https://github.com/PrismLibrary/Prism/issues/832#issuecomment-257886188" target="_self"&gt;The event aggregator is fire and forget&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2022 18:24:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/arcgisvectortiledlayer-not-showing-when-assigned/m-p/1218105#M11383</guid>
      <dc:creator>ViktorSafar</dc:creator>
      <dc:date>2022-10-01T18:24:41Z</dc:date>
    </item>
  </channel>
</rss>

