I have a map and an overview map, and I'd like to have same graphics on both maps, but when trying to assign a GraphicsOverlay to the GraphicOverlays of both maps, it returns an exception that object is already owned, because both maps have same graphics.
How can this be done? Can I clone or copy graphics o GraphicOverlays?
This can be done. Each map will need to have its own GraphicsOverlay object and its own renderer object. You can however use the same maker symbol for both renderers.
MapView:GraphicsOverlays is a GraphicsOverlayCollection which has a CopyTo method. This would be similiar to a Clone. You create a new array and then copy into that array and then you can assign the new GraphicsOverlayCollection to the overview MapView
LayerCollection operationalLayers = new LayerCollection();
Layer tempLayers = new Layer[map.OperationalLayers.Count];
foreach (var operationalLayer in tempLayers)
The above is done to replace the OperationalLayers in a map, but the general idea is the same, just using GraphicOverlays. Instead of the .Remove, .Add like above use the temp array and add them to you other MapView
Your approach ends into the same result:
Esri.ArcGISRuntime.ArcGISRuntimeException: 'Object already owned.: Graphic cannot be added - it is already in an owning collection.'
I think you'll have to copy each graphic and add it to the other graphics overlay.
Here's how I did it:
private void CopyGraphicsButton_Click(object sender, RoutedEventArgs e)
GraphicsOverlay go1 = MapView1.GraphicsOverlays.FirstOrDefault();
GraphicsOverlay go2 = MapView2.GraphicsOverlays.FirstOrDefault();
foreach(Graphic g in go1.Graphics)
Graphic newGraphic = CopyGraphic(g);
private Graphic CopyGraphic(Graphic inGraphic)
Graphic copyGraphic = new Graphic(inGraphic.Geometry, inGraphic.Attributes, inGraphic.Symbol);
I hope that helps! Thad