Hi,
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); portalItems.AddRange(results.Results); 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);//UNCOMMENT FOR VECTOR}
}
}
});
}
PS - Is there any way to make the above look more like code layout.
Thanks for your reply - as you can see I have updated my code and modified the question slightly - I know how to add a single layer from a service but I still fail to add a raster based layer - it is always null and nothing appears in the map view - can you help with that?
Hi Simon
I am able to reproduce this behavior you are seeing. Will investigate and let you know.
Thanks
Uma
Hi Simon
You cannot add raster sublayers (that is, raster layers inside a map service) individually to Pro. This is by-design.
Thanks
Uma
Hi Uma,
That's interesting, I'm wondering if you can tell me why this is the case, what's the thinking behind designing the map service in such a way - bearing in mind you have this behaviour if you toggle WMS for the map service or if you work with a map service which has published featureclasses.
Kind regards
Simon.
Hi, Uma
I would really appreciate a more detailed response to this as it is critical to the project I am currently on with.
Kind regards.
Simon.
Hi Tanu, sorry for the late reply (I didn't recieve a notification or didn't notice one).
The workflow is to browse several hundred map services - inside each one there may just be Feature Layers published, or rasters, all in all there are tens of thousands of individual layers. The user is not aware of all these hundreds of map services - the UI in Pro hides this all away.
All they are presented with is a nice UI in Pro - which allows them to query layers spread accross all the map services - from there they can filter down and pick some (or just one) layers of interest (I mean that in a generic sense i.e. can be either raster or feature layer type) - then they ask those layers to be added to the Map in Pro.
The code behind does things like searching and caching what it has found amongst the map services - all via REST api calls - in the end the specific layers are found and then added to the Map view inside Pro.
The user is not anything fancy with the layers - it's a means to view and inspect some of the attribute data perhaps - but certainly no advanced geoprocessing tasks or anything like that. It's essentially a huge data repository stored in the cloud via Portal.
Thats the workflow - it's not complicated as you can see - it's just basically find me data and show it in Pro. Data stored centrally in the cloud/ArcGIS Enterprise.
I look forward to your thoughts.
Hi Simon
No worries.
When you see the layer type is 'raster', can you add that as a map service layer?
If you use 'dynamic layers' capability to remove all other sub-layers from the map service layer. This will allow you to see the layer on the map.
hope this helps.