AnsweredAssumed Answered

Adding a raster layer from a map service results in null layer

Question asked by earnshawgetech on Apr 17, 2019
Latest reply on Aug 15, 2019 by ahoque-esristaff



NOTE: I have updated this question from struggling to add a specific layer from a map service (as I have managed to work this out) to having a problem with adding raster layers (don't work) vs adding vector layers (which do work!).


I have a map service which has many layers of type "Raster Layer".  It is stored on Portal. I can locate the exact layer I want (it's a single layer) - but when I add it to the map - the result never shows in the map.  I just have an empty map.


However - if you change the code ever so slightly below to work against a Map Service with just vector/feature based layers - the layer loads ABSOLUTELY FINE!


So why is this not working for raster layers ?? This is beyond frustrating!!



Anyone have any ideas?


public static async void AddLayerToView()
   Uri portalUri = new Uri("https://fooserver.foocompany.local/portal");

    var portal = ArcGISPortalManager.Current.GetPortal(portalUri);
   var owner = portal.GetSignOnUsername();
   var portalInfo = await portal.GetPortalInfoAsync();

    // Get all web maps and map services - include user, organization
   // and "foo" in the title
   var query2 = PortalQueryParameters.CreateForItemsOfTypes(new List<PortalItemType>() {
   PortalItemType.WebMap, PortalItemType.MapService, PortalItemType.Layer}, owner, "", "Title:Foo");
   query2.OrganizationId = portalInfo.OrganizationId;

   //retrieve in batches of up to a 100 each time
   query2.Limit = 100;

   //Loop until done
   var portalItems = new List<PortalItem>();
   while (query2 != null)
      //run the search
      PortalQueryResultSet<PortalItem> results = await portal.SearchForContentAsync(query2);
      query2 = results.NextQueryParameters;

   RasterLayer rasterLayer = null;
    //Layer vectorLayer = null;  //UNCOMMENT FOR VECTOR

   //process results
   foreach (var pi in portalItems)
      string itemID = pi.ID;
      Item currentItem = ItemFactory.Instance.Create(itemID, ItemFactory.ItemType.PortalItem);

      await QueuedTask.Run(() =>
         var subItems = currentItem.GetItems();

         foreach (var item in subItems)
            if (item.Name == "MY_LAYER_NAME_TO_MATCH_ON")
               if (LayerFactory.Instance.CanCreateLayerFrom(item))
                  rasterLayer = (RasterLayer)LayerFactory.Instance.CreateLayer(item, MapView.Active.Map);
                   //vectorLayer = LayerFactory.Instance.CreateLayer(item, MapView.Active.Map);

PS - Is there any way to make the above look more like code layout.