var queryString = string.Format("{0} type:\"layer\" NOT \"web mapping application\"", searchString); var searchParameters = new SearchParameters() { QueryString = queryString, SortField = "avgrating", SortOrder = QuerySortOrder.Descending, Limit = 20 }; _ArcGISPortal.SearchItemsAsync(searchParameters, (results, exception) => { /* do something */ });
// Create webmap from portal item WebMap.FromPortalItemAsync(portalItem, (webMap, exception) => { if (exception == null) // <- Exception reads "Invalid Item" { Document webMapDocument = new Document(); webMapDocument.GetMapCompleted += (obj, args) => { if (args.Map != null) { LayerCollection newLayers = new LayerCollection(); foreach (var layer in args.Map.Layers) { newLayers.Add(layer); } args.Map.Layers.Clear(); MyMap.Layers = newLayers; } }; webMapDocument.GetMapAsync(webMap); } else { tbSearchItemResults.Text = exception.Message; } });
That's really interesting, I didn't know you could do that. What I want to do is take the ArcGISPortalItem and create an actual layer from it. Is there a way to do this without using the WebMap API?
I've tried adding a FeatureLayer from a feature service ArcGISPortalItem object like so:// Fetch portal items via search. Grab one portalItem ... FeatureLayer featureLayer = new FeatureLayer(); featureLayer.Url = portalItem.Url; featureLayer.Initialized += featureLayer_Initialized; featureLayer.InitializationFailed += featureLayer_InitializationFailed; featureLayer.Initialize(); MyMap.Layers.Add(featureLayer); [\CODE] But nothing happens. The map is not updated with the FeatureLayer. Is there a way to map ArcGISPortalItems to the ArcGISTiledMapServiceLayer, ArcGISDynamicMapServiceLayer, etc.... ? It looks like you should be able to do something like this, right? Thanks, - Aaron
If the URL of your portal item is a feature layer URL (i.e with a layerId at the end such as ....../MapServer/4), your code should work.
The risk is that your URL is the URL of a map service or a tiled service. Is this case you have to create the right layer type (i.e ArcGISMapServiceLayer or ArcGISTiledMapService layer).
Note: It's one of the advantages of using the webmap model. Under the cover, the service metadata are analyzed and the right layer type is created.
OK - I think I get the concept now. Based on your answer to another question I asked it looks like this is the basic process to do what I want to do:
1. Search for layer type portal items.
2. Take portal item of choice and plug it into a web map that you've created programmatically
3. Take that web map and use Document to get the map from it.
Does that sound about right?