How to parse only Operational Layers from Web Map

2743
3
05-21-2013 11:33 AM
AaronConnolly
Occasional Contributor
In the Document's GetMapCompleted event is it possible to get a list of the operational layers from the base map, rather than have to parse the DocumentValues property? The DocumentValues property seems to really only be a CLR object representation of the JSON that makes up the WebMap. I don't think it is.

What I want to do is this:


void _webMap_GetMapCompleted(object sender, GetMapCompletedEventArgs e)
{
    List<Layer> operationalLayers = e.OperationalLayers;

    // Do something with those layers ... 
}



Our objective is to parse the web map for everything EXCEPT the basemap and add that to an existing map. Unfortunately I'm not sure that it's reliable to do that because there could be web maps whose basemap is pertinent.

Using the map like this is not reliable either because you only know what type of layer you have, not it's intended purpose (base or operational):


foreach(Layer layer in e.Map.Layers)
{
    // Is layer operational or base map?
    // No way to know?
}



As a last resort we could parse the DocumentValues property for a list of layer IDs for those in the operationalLayers List, then parse those out of the e.Map.Layers list. Again, this might not be reliable.

Thanks,
- Aaron
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
For such scenario, I recommend to use the WebMap model.

You can instantiate a webmap from a portal item using http://resources.arcgis.com/en/help/silverlight-api/apiref/api_start.htm?ESRI.ArcGIS.Client.Portal~E....
Then you can modify it using the webmap API and finally create the map from the webmap using Document.GetMapAsync(webMap)
0 Kudos
AaronConnolly
Occasional Contributor
Dominique,

Can you instantiate web map from a portal item whose type is "feature service"? I'm trying to create a web map asynchronously from an ArcGISPortalItem that is simply a layer of type "feature service" and when I call WebMap.FromPortalItemAsync(...); I get an exception that reads "Invalid Item".

Is it expected that this constructor may only be called successfully with an ArcGISPortalItem object whose type is "web map" ?

If so, how can I get JUST a layer object from an ArcGISPortalItem whose type is one of the various web/desktop layer types?

Thanks,
- Aaron
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Can you instantiate web map from a portal item whose type is "feature service"? I'm trying to create a web map asynchronously from an ArcGISPortalItem that is simply a layer of type "feature service" and when I call WebMap.FromPortalItemAsync(...);


No, unfortunately, for now, the creation of a webmap from a portal item works only if the item is of type WebMap.

To create a webmap from a portal item of type 'feature service', you have to instantiate the webmap by code (sample), instantiate a webmaplayer, set the Url, Id and ItemId properties of the webmaplayer, add the webmaplayer to the webmap.OperationalLayers and create the map from the webmap using Document.GetMapAsync(webMap)
0 Kudos