Select to view content in your preferred language

Overriding layer information when creating legend

571
3
10-18-2023 04:52 AM
TorbjørnDalløkken2
Occasional Contributor

Hi.

I'm creating a add-in for standardizing the layout of the maps created by the ArcGIS Pro users, and one of the functions is to create a legend element. I'm able to create the legend and add it to the layout, but there are some criteria I've not been able to figure out. 

One of the criteria for the layout is that the items of polyline-layers is symbolized with a zigzag-line. Is it possible to symbolize the polyline-layers with a zigzag-symbol while still having the TOC-symbol horizontal (legend patch)?

There is also one criteria that the layername shown in the legend is based on a property in the add-in. Is it possible to do this while not having to change the layer name in the TOC?

I can't see that it's possible to set the symbol or labelname in the CIMLegendItem class.

0 Kudos
3 Replies
ViktorSafar
Occasional Contributor II

I did something similar regarding the layer symbology. I do not believe there is a way to change the symbol only for the layout as the layout is directly dependent on the map. And so I change the layer's renderer to  a layout-specific one, and then reset the renderer when the user is done working with the layout.

0 Kudos
ViktorSafar
Occasional Contributor II

As for the layer name, the `CIMLegendItem.Name` property gets the layer name so you can just change that?

0 Kudos
CharlesMacleod
Esri Regular Contributor

looks like the patch comes from the layer renderer and not from the legend item, meaning:

u have to change the (patch in the) layer renderer. Also, I could not see a way to change the "Name" of the legend item. That looks like it is always set from the layer name and so wld mean changing the layer name. Changing the name property on the underlying CIMLegendItem had no effect.

The code below assumes the renderer is a simple value...u will need to adjust it accordingly depending on what the renderer is in your case...

QueuedTask.Run(()=> {
  var legend = LayoutView.Active.Layout.GetElementsAsFlattenedList()
    .OfType<Legend>().FirstOrDefault();

  var fl =
    legend.MapFrame.Map.GetLayersAsFlattenedList().
    OfType<FeatureLayer>().Where(
      lyr => lyr.ShapeType == esriGeometryType.esriGeometryPolyline).FirstOrDefault();
  if (fl == null)
    return;
  
  //change the patch symbol...cast the renderer to the
  //correct type - simple, UVR, Class break, etc.
  var svr = fl.GetRenderer() as CIMSimpleRenderer;
  if (svr.Patch == PatchShape.LineZigZag)
    svr.Patch = PatchShape.Default;
  else
    svr.Patch = PatchShape.LineZigZag;
  fl.SetRenderer(svr);

 

 

 

0 Kudos