<?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 Problem adding a layer twice in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-adding-a-layer-twice/m-p/718404#M19139</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm creating a map in ArcObject 10, .Net from a SOE in order to export it in different formats.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to add a layer twice (with different renderers) and the second time I add it, it removes the first one (or it replaces the renderer I don't know).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any idea of how I could do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a sample of my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;//Gets the layer from the mapservice where the SOE is published
IMapServer3 mapServer = this.serverObjectHelper.ServerObject as IMapServer3;
IMapServerObjects mapObj = (IMapServerObjects)mapServer;
IMap map = mapObj.get_Map(mapServer.DefaultMapName);
IGeoFeatureLayer featureLayer = map.get_Layer(myLayerId) as IGeoFeatureLayer;
featureLayer.Name="Layer1";
featureLayer.Renderer = Renderer1;

IGeoFeatureLayer featureLayer2 = map.get_Layer(myLayerId) as IGeoFeatureLayer;
featureLayer2.Name="Layer2";
featureLayer2.Renderer = Renderer2;

//Adds the layer to the newly created map
myMapToExport.addLayer(featureLayer,0);
myMapToExport.addLayer(featureLayer2,0);
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code works correctly if the 2 layers retrieved don't have the same id in the instruction map.get_Layer(). Otherwise, only the second is displayed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any Idea?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 21 Nov 2011 14:07:57 GMT</pubDate>
    <dc:creator>DavidBeni</dc:creator>
    <dc:date>2011-11-21T14:07:57Z</dc:date>
    <item>
      <title>Problem adding a layer twice</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/problem-adding-a-layer-twice/m-p/718404#M19139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm creating a map in ArcObject 10, .Net from a SOE in order to export it in different formats.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to add a layer twice (with different renderers) and the second time I add it, it removes the first one (or it replaces the renderer I don't know).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any idea of how I could do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a sample of my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;//Gets the layer from the mapservice where the SOE is published
IMapServer3 mapServer = this.serverObjectHelper.ServerObject as IMapServer3;
IMapServerObjects mapObj = (IMapServerObjects)mapServer;
IMap map = mapObj.get_Map(mapServer.DefaultMapName);
IGeoFeatureLayer featureLayer = map.get_Layer(myLayerId) as IGeoFeatureLayer;
featureLayer.Name="Layer1";
featureLayer.Renderer = Renderer1;

IGeoFeatureLayer featureLayer2 = map.get_Layer(myLayerId) as IGeoFeatureLayer;
featureLayer2.Name="Layer2";
featureLayer2.Renderer = Renderer2;

//Adds the layer to the newly created map
myMapToExport.addLayer(featureLayer,0);
myMapToExport.addLayer(featureLayer2,0);
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code works correctly if the 2 layers retrieved don't have the same id in the instruction map.get_Layer(). Otherwise, only the second is displayed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any Idea?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Nov 2011 14:07:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/problem-adding-a-layer-twice/m-p/718404#M19139</guid>
      <dc:creator>DavidBeni</dc:creator>
      <dc:date>2011-11-21T14:07:57Z</dc:date>
    </item>
  </channel>
</rss>

