<?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 Re: Layer ordering not honoured in TOC in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1259257#M9430</link>
    <description>&lt;P&gt;After I wrote the initial post, I found that missing bit of code that you mentioned (MapMemberPosition.Index) and thought I'd cracked it! and you'd think that would fix it wouldn't you?&lt;/P&gt;&lt;P&gt;Well, I did try that and it made zero difference. I was so frustrated and I really couldn't think what else it would be.&amp;nbsp; It's only when I stumbled across an example piece of ESRI help code showing the non-constructor example of using LayerCreationParams, that it actually started working.&lt;/P&gt;&lt;P&gt;I have updated the post - so people, like yourself don't think "MapMemberPosition.Index is missing". I should have done that in the first place really.&lt;/P&gt;&lt;P&gt;I would be interested if you can confirm my findings though if you have chance.&amp;nbsp; I am using 3.x version of Pro.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2023 09:54:46 GMT</pubDate>
    <dc:creator>Vidar</dc:creator>
    <dc:date>2023-02-17T09:54:46Z</dc:date>
    <item>
      <title>Layer ordering not honoured in TOC</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1258020#M9415</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to add 3 layers to a group layer in a specific index order. I use the FeatureLayerCreationParams object with the LayerFactory.Instance.CreateLayer() function - but when I look at the results in the TOC - the layers have come in a random order and not the order I specified.&lt;/P&gt;&lt;P&gt;This was working fine in 2.x but since I have moved to 3.x this code does not seem to work - I'm not sure what I can do but I need to fix the problem urgently.&lt;/P&gt;&lt;P&gt;Here is the code I use (I pass in my object called "layer", which holds the index information to pass on):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;await QueuedTask.Run(() =&amp;gt;
{
	Item stagingLayer = ItemFactory.Instance.Create(AgolId, ItemFactory.ItemType.PortalItem);
	if (LayerFactory.Instance.CanCreateLayerFrom(stagingLayer))
	{
		var featureCreateParams = new FeatureLayerCreationParams(stagingLayer)
		{
			IsVisible = layer.Visible,
			MapMemberIndex = layer.LayerOrder,
			
			//Even this does NOT fix the issue
			MapMemberPosition = MapMemberPosition.Index,

			Name = layer.Name
		};

		LayerFactory.Instance.CreateLayer&amp;lt;FeatureLayer&amp;gt;(featureCreateParams, groupLayer);
	}
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 09:47:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1258020#M9415</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2023-02-17T09:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Layer ordering not honoured in TOC</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1258091#M9417</link>
      <description>&lt;P&gt;I'm suspecting that the constructor is at fault here - if ESRI could confirm this as a bug or not that would be good.&lt;/P&gt;&lt;P&gt;I have since changed the code to this, not using a constructor, and it works perfectly. Very strange and certainly a high chance that this will "can-trip" a lot of developers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code that now works:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Item currentItem = ItemFactory.Instance.Create(AgolId, ItemFactory.ItemType.PortalItem);
	await QueuedTask.Run(() =&amp;gt;
	{
		//Create a LayerCreationParam - constructor method does not honour indexes.
		var layerParam = new LayerCreationParams(currentItem);
		layerParam.Name = layer.Name;
		layer.Visible = layer.Visible;
		layerParam.MapMemberPosition = MapMemberPosition.Index;
		layerParam.MapMemberIndex = layer.LayerOrder;

		if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
		{
			LayerFactory.Instance.CreateLayer&amp;lt;FeatureLayer&amp;gt;(layerParam, groupLayer);
		}
	});&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 14 Feb 2023 17:31:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1258091#M9417</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2023-02-14T17:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Layer ordering not honoured in TOC</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1259190#M9429</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You seem to be missing setting the MapMemberPosition to MapMemberPosition.Index in the first code snippet (when you are using the FeatureLayerCreationParams).&amp;nbsp; &amp;nbsp; The default value for this property when it is not set is AutoArrange which means that the MapMemberIndex value is ignored.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Narelle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 01:00:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1259190#M9429</guid>
      <dc:creator>NarelleChedzey</dc:creator>
      <dc:date>2023-02-17T01:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Layer ordering not honoured in TOC</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1259257#M9430</link>
      <description>&lt;P&gt;After I wrote the initial post, I found that missing bit of code that you mentioned (MapMemberPosition.Index) and thought I'd cracked it! and you'd think that would fix it wouldn't you?&lt;/P&gt;&lt;P&gt;Well, I did try that and it made zero difference. I was so frustrated and I really couldn't think what else it would be.&amp;nbsp; It's only when I stumbled across an example piece of ESRI help code showing the non-constructor example of using LayerCreationParams, that it actually started working.&lt;/P&gt;&lt;P&gt;I have updated the post - so people, like yourself don't think "MapMemberPosition.Index is missing". I should have done that in the first place really.&lt;/P&gt;&lt;P&gt;I would be interested if you can confirm my findings though if you have chance.&amp;nbsp; I am using 3.x version of Pro.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 09:54:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1259257#M9430</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2023-02-17T09:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Layer ordering not honoured in TOC</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1259601#M9432</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sorry;&amp;nbsp; I'm not able to duplicate your problem with FeatureLayerCreationParams.&amp;nbsp; I have a group layer containing 3 layers (pointing to a file geodatabase).&amp;nbsp; Then I run the following code which inserts a hosted feature layer at index 2 in the group layer.&amp;nbsp; &amp;nbsp;The new layer is inserted at the correct location.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you run this code and see if it works as you expect?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Narelle&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override void OnClick()
{
  var groupLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;GroupLayer&amp;gt;().FirstOrDefault();
  if (groupLayer == null)
    return;

  // Airports_OPSNET45
  string agolId = "8c1854a8580543b0a4848a0b5fbb0791";
  int index = 2;

  DoIt(agolId, "My layer", index, groupLayer);
}

internal Task DoIt(string AgolId, string name, int index, GroupLayer groupLayer)
{
  return QueuedTask.Run(() =&amp;gt;
  {
    Item stagingLayer = ItemFactory.Instance.Create(AgolId, ItemFactory.ItemType.PortalItem);
    if (LayerFactory.Instance.CanCreateLayerFrom(stagingLayer))
    {
      var featureCreateParams = new FeatureLayerCreationParams(stagingLayer)
      {
        IsVisible = true, 
        MapMemberIndex = index,
        MapMemberPosition = MapMemberPosition.Index,
        Name = name
      };

      Lactory.Instance.CreateLayer&amp;lt;FeatureLayer&amp;gt;(featureCreateParams, groupLayer);
    }
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 23:38:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/layer-ordering-not-honoured-in-toc/m-p/1259601#M9432</guid>
      <dc:creator>NarelleChedzey</dc:creator>
      <dc:date>2023-02-17T23:38:41Z</dc:date>
    </item>
  </channel>
</rss>

