<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Map.Clone / GroupLayer.Clone bug in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/map-clone-grouplayer-clone-bug/m-p/1236359#M11503</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;We've had multiple issues related to merging the maps into one.&lt;/P&gt;&lt;P&gt;We've tried different solutions to merge:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ToJson() for each map, and perform a JSON merge to create the JSON for a new Map.FromJson()&lt;UL&gt;&lt;LI&gt;For some reason we didn't get PopupDefinitions and some other properties using this technique, even when having performed map.LoadAsync() or LoadAsync for individual layers&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;Iterate referenceLayers, OperationalLayers and BaseLayers and perform a Clone&lt;UL&gt;&lt;LI&gt;Most things work, but we frequently get error message similar to&lt;/LI&gt;&lt;LI&gt;ArcGisMapImageLayer within a GroupLayer fail to reflect IsVisible, so the user is not able to show/hide that layer.&lt;UL&gt;&lt;LI&gt;Moving them outside of a group works, but that's not particularly functional for the structure presented to the user.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Is it possible that Clone clones some references to the original CoreArcGISMapImageLayer referencing the original Map that is no longer alive?&lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion for the best way to merge multiple maps into one?&lt;/P&gt;</description>
    <pubDate>Wed, 07 Dec 2022 14:29:56 GMT</pubDate>
    <dc:creator>BjørnarSundsbø1</dc:creator>
    <dc:date>2022-12-07T14:29:56Z</dc:date>
    <item>
      <title>Map.Clone / GroupLayer.Clone bug</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/map-clone-grouplayer-clone-bug/m-p/1236359#M11503</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;We've had multiple issues related to merging the maps into one.&lt;/P&gt;&lt;P&gt;We've tried different solutions to merge:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ToJson() for each map, and perform a JSON merge to create the JSON for a new Map.FromJson()&lt;UL&gt;&lt;LI&gt;For some reason we didn't get PopupDefinitions and some other properties using this technique, even when having performed map.LoadAsync() or LoadAsync for individual layers&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;Iterate referenceLayers, OperationalLayers and BaseLayers and perform a Clone&lt;UL&gt;&lt;LI&gt;Most things work, but we frequently get error message similar to&lt;/LI&gt;&lt;LI&gt;ArcGisMapImageLayer within a GroupLayer fail to reflect IsVisible, so the user is not able to show/hide that layer.&lt;UL&gt;&lt;LI&gt;Moving them outside of a group works, but that's not particularly functional for the structure presented to the user.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Is it possible that Clone clones some references to the original CoreArcGISMapImageLayer referencing the original Map that is no longer alive?&lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion for the best way to merge multiple maps into one?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:29:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/map-clone-grouplayer-clone-bug/m-p/1236359#M11503</guid>
      <dc:creator>BjørnarSundsbø1</dc:creator>
      <dc:date>2022-12-07T14:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with merging multiple WebMap</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/map-clone-grouplayer-clone-bug/m-p/1238726#M11520</link>
      <description>&lt;P&gt;&lt;STRONG&gt;This appears to be a bug &lt;/STRONG&gt;with clone of Map.Clone() and GroupLayer.Clone().&amp;nbsp;&lt;/P&gt;&lt;P&gt;The map contains two ArcGisMapImageLayer that holds two sublayers. Both sublayers are visible, while the imagelayer is not.&lt;/P&gt;&lt;P&gt;One imagelayer is within a GroupLayer that is visible, and the other layer is on the root of the map.&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;I addressed it with the following snippet:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the CloneLayer Extension method&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
/// Helper class for cloning of layers. There is an issue with clone of &amp;lt;see cref="GroupLayer"/&amp;gt; where the children are &amp;lt;see cref="ArcGISMapImageLayer"/&amp;gt;
/// with visibility as hidden in the original map.
/// &amp;lt;/summary&amp;gt;
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();
    }

    /// &amp;lt;summary&amp;gt;
    /// Clone a group layer, and it's children
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="sourceGroupLayer"&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    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;
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:29:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/map-clone-grouplayer-clone-bug/m-p/1238726#M11520</guid>
      <dc:creator>BjørnarSundsbø1</dc:creator>
      <dc:date>2022-12-07T14:29:24Z</dc:date>
    </item>
  </channel>
</rss>

