Parameters
- item
- An ArcGIS.Desktop.Core.Item
Return Value
A boolean indicates that a layer can be created from the item.
{
UriBuilder searchURL = new UriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri)
{
Path = "sharing/rest/search"
};
string layers = "(type:\"Map Service\" OR type:\"Image Service\" OR type:\"Feature Service\" OR type:\"WMS\" OR type:\"KML\")";
//any public layer content
searchURL.Query = string.Format("q={0}&f=json", layers);
EsriHttpClient httpClient = new EsriHttpClient();
var searchResponse = httpClient.Get(searchURL.Uri.ToString());
dynamic resultItems = JObject.Parse(await searchResponse.Content.ReadAsStringAsync());
long numberOfTotalItems = resultItems.total.Value;
if (numberOfTotalItems == 0)
{
return;
}
List<dynamic> resultItemList = new List<dynamic>();
resultItemList.AddRange(resultItems.results);
//get the first result
dynamic item = resultItemList[0];
string itemID = item.id;
Item currentItem = ItemFactory.Instance.Create(itemID, ItemFactory.ItemType.PortalItem);
var mapView = MapView.Active;
if (mapView == null)
return;
await QueuedTask.Run(() =>
{
//Create a LayerCreationParam
var layerParam = new LayerCreationParams(currentItem);
// if we have an item that can be turned into a layer
// add it to the map
if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
{
LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParam, mapView.Map);
}
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)