Select to view content in your preferred language

Get Layers from WebMap (PortalItem)

534
2
Jump to solution
10-17-2022 03:33 PM
TimothySmith6
New Contributor III

Is there a way to search the current portal for all WebMaps that contain a certain feaureservice layer?

I can use the myPortal.SearchForContentAsync(query) to get my webmap portal items. But don't see how to get a list of layers for the webmap.   The GetItems() method returns nothing.

Looks like the ArcGIS API can do it, but I need to use the SDK.  Any ideas?

 

Thanks,

tim

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

There is a lower level API called EsriHttpClient. You can use it to issue HTTP formatted GET requests (as well as POST, etc.) against the portal. In this way u can use the ArcGIS API as u mention, just parse the returned JSON using Newtonsoft.JSON as needed.

Take a look at all the examples here: https://prodev.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9050.html which is part of the API Reference. They show various usages based off the ArcGIS REST API and will show u the pattern to use.

There are also a couple of samples that use EsriHttpClient as well. Here's one you can look at for additional context: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Content/PortalInfoListAllFedSer... 

 

 

 

View solution in original post

0 Kudos
2 Replies
CharlesMacleod
Esri Regular Contributor

There is a lower level API called EsriHttpClient. You can use it to issue HTTP formatted GET requests (as well as POST, etc.) against the portal. In this way u can use the ArcGIS API as u mention, just parse the returned JSON using Newtonsoft.JSON as needed.

Take a look at all the examples here: https://prodev.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9050.html which is part of the API Reference. They show various usages based off the ArcGIS REST API and will show u the pattern to use.

There are also a couple of samples that use EsriHttpClient as well. Here's one you can look at for additional context: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Content/PortalInfoListAllFedSer... 

 

 

 

0 Kudos
TimothySmith6
New Contributor III

Thanks Charles,

I think that put us on the right track.

So using the SDK's myPortal.SearchForContentAsync(query) gives us the WebMap PortalItems, with IDs.  We can then use those IDs and EsriHttpClient to get the webmap's JSON to find the operational layers (urls).

Something along these lines:

string sID = "45427f94cfef46b3bd117eb9b9a9fe8a"; 
UriBuilder searchURL = new UriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri)
{
    Path = $"sharing/rest/content/items/{sID}/data",
    Query = "f=json"
};

EsriHttpResponseMessage response2 = new EsriHttpClient().Get(searchURL.Uri.ToString());
dynamic operLayers = JObject.Parse(await response2.Content.ReadAsStringAsync());

List<dynamic> operLayerList = new List<dynamic>();
operLayerList.AddRange(operLayers.operationalLayers);

for (int x = 0; x < operLayerList.Count; x++)
{
    string myURL = operLayerList[x].url;
    MessageBox.Show(myURL);
}

 

Thanks again,

tim

0 Kudos