Problem adding a layer twice

664
0
11-21-2011 06:07 AM
DavidBeni
New Contributor III
Hi all,

I'm creating a map in ArcObject 10, .Net from a SOE in order to export it in different formats.
The problem is:

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).

Do you have any idea of how I could do this?

Here is a sample of my code:

//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);


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.

Any Idea?
Thanks in advance.
0 Kudos
0 Replies