I just need to add all my layers from a webmap to a map then add a graphics layer, is this possible?
I keep getting this error "cannot modify layers collection directly when managed by webmapviewmodel"
I found a work around
// Loads the given webmap
private async Task LoadWebMapAsync(string wmId)
_portal = await ArcGISPortal.CreateAsync();
var item = await ArcGISPortalItem.CreateAsync(_portal, wmId);
var webmap = await WebMap.FromPortalItemAsync(item);
var vm = await WebMapViewModel.LoadAsync(webmap, _portal);
foreach (var layer in vm.Map.Layers)
//Add each layer individually
catch (Exception ex)
var vmr = new ErrorMessagesClass();
My work around doesnt work, it crash the next time i to any kind of async after loading the web map. Does anyone have any ideas how to mix webmap layers with graphic layers?
I struggled with the same issue. The map on the WebMapViewModel is readonly. I think the proper approach is to add graphic overlays to the map view control itself. The nicest part is this can be done with xaml.
You'll need to create a renderer for each graphic which also can be done with xaml.
You can add and remove individual graphics in code behind by accessing the graphic overlays collection.
Hope that helped.
Matt is correct that graphics overlays are the way to overlay graphics on a webmap. The webmap spec in fact does not contain a definition for graphics, instead these are handled as feature collections. In order to persist client-side graphics in a webmap they need to be push in as a featurecollection (ArcGIS web map JSON format).
On the roadmap for the .NET API is full support for reading and writing webmaps (in the runtime they are the 'map') at which time we plan to have a featurecollection type which is effectively an in-memory feature layer and will be persisted in any maps you save.
Retrieving data ...