Hi,
We configure multiple webmaps in portal, and we want to merge them into a new webmap that is the union of the individual maps. Customer have different teams managing the content of the different maps, which is why we are not working with a single large webmap.
We've had multiple issues related to merging the maps into one.
We've tried different solutions to merge:
Is it possible that Clone clones some references to the original CoreArcGISMapImageLayer referencing the original Map that is no longer alive?
I've tried implementing my own Clone method to do similar things to the runtime Clone, but in some situations I need to Load the source layer, which gives me the No access to this resource (or something to that effect).
Any suggestion for the best way to merge multiple maps into one?
This appears to be a bug with clone of Map.Clone() and GroupLayer.Clone().
The map contains two ArcGisMapImageLayer that holds two sublayers. Both sublayers are visible, while the imagelayer is not.
One imagelayer is within a GroupLayer that is visible, and the other layer is on the root of the map.
If I use Map.Clone(), I'm not able to change the visibility of the imagelayer within a grouplayer until i toggle the visibility of the grouplayer, and then change the visibility of the imagelayer
I addressed it with the following snippet:
private Esri.ArcGISRuntime.Mapping.Map CloneMap(Esri.ArcGISRuntime.Mapping.Map sourceMap)
{
var targetMap = new Esri.ArcGISRuntime.Mapping.Map(sourceMap.SpatialReference)
{
InitialViewpoint = sourceMap.InitialViewpoint,
MaxScale = sourceMap.MaxScale,
MinScale = sourceMap.MinScale,
Basemap = new Basemap()
};
foreach (var layer in sourceMap.OperationalLayers)
{
targetMap.OperationalLayers.Add(layer.CloneLayer());
}
if (sourceMap.Basemap != null)
{
foreach (var layer in sourceMap.Basemap.BaseLayers)
{
targetMap.Basemap.BaseLayers.Add(layer.CloneLayer());
}
foreach (var layer in sourceMap.Basemap.ReferenceLayers)
{
targetMap.Basemap.ReferenceLayers.Add(layer.CloneLayer());
}
}
return targetMap;
}
And the CloneLayer Extension method
/// <summary>
/// Helper class for cloning of layers. There is an issue with clone of <see cref="GroupLayer"/> where the children are <see cref="ArcGISMapImageLayer"/>
/// with visibility as hidden in the original map.
/// </summary>
public static class MapCloneExtensions
{
public static Layer CloneLayer(this Esri.ArcGISRuntime.Mapping.Layer layer)
{
if(layer is GroupLayer groupLayer)
{
return CloneInternal(groupLayer);
}
return layer.Clone();
}
/// <summary>
/// Clone a group layer, and it's children
/// </summary>
/// <param name="sourceGroupLayer"></param>
/// <returns></returns>
private static Layer CloneInternal(GroupLayer sourceGroupLayer)
{
// GroupLayer.Clone() does not work with visibility, so we need to do it manually
var groupLayer = new GroupLayer
{
Id = sourceGroupLayer.Id,
Name = sourceGroupLayer.Name,
IsVisible = sourceGroupLayer.IsVisible,
Opacity = sourceGroupLayer.Opacity,
MaxScale = sourceGroupLayer.MaxScale,
MinScale = sourceGroupLayer.MinScale,
};
foreach(var layer in sourceGroupLayer.Layers)
{
groupLayer.Layers.Add(CloneLayer(layer));
}
return groupLayer;
}
}