Skip to main content

applyStyleItem

汇总

LegendItem 提供对 LegendElement 中的图例项级别信息的访问权限。

讨论

LegendElement 类上的 items 属性将返回 LegendItem 对象列表。 对于每个图例项,您可以更改属性,例如 arrangementpatchHeight 及其 visible 状态。 典型的工作流是遍历元素列表,根据其 name 属性确定感兴趣项目,然后进行适当更改。

注:

对 LegendItem 类显示的属性不适用于所有渲染器类型。 需要在必要时捕获这些例外。

语法

applyStyleItem()

属性

名称 说明 数据类型

arrangement

(读取和写入)

确定图例项排列的字符串。以下是有效值列表:

  • PatchLabelDescription—图面、标注、描述

  • PatchDescriptionLabel—图面、描述、标注

  • LabelPatchDescription—标注、图面、描述

  • LabelDescriptionPatch—标注、描述、图面

  • DescriptionPatchLabel—描述、图面、标注

  • DescriptionLabelPatch—描述、标注、图面

String

column

(读取和写入)

图例项的列位置。列属性仅适用于使用 ManualColumns 自适应策略的图例。

Long

name

(只读)

返回图例项名称。可通过修改图层名称设置图例项名称。

String

patchHeight

(读取和写入)

图例项图面的高度。单位为磅。

Double

patchWidth

(读取和写入)

图例项图面的宽度。单位为磅。

Double

showFeatureCount

(读取和写入)

一个布尔值,用于控制是否将要素计数放置在图例项文本的旁边。显示的值取决于 showVisibleFeatures 设置。

Boolean

showVisibleFeatures

(读取和写入)

一个布尔值,用于控制图例项显示所有值还是仅显示可见范围内的值。

Boolean

type

(只读)

返回 LEGEND_ITEM 的值。

String

visible

(读取和写入)

如果图例项在图例中可见,则返回 True

Boolean

方法

applyStyleItem(style_item)

StyleItem 应用于 LegendItem

名称 说明 数据类型

style_item

A reference to a StyleItem in a project.

StyleItem

代码示例

LegendItem 示例

以下脚本将遍历图例中的所有图例项。 该脚本将为所有图例项设置 patchHeightpatchWidth ,然后为特定图例项设置 showVisibleFeatures

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]
leg = lyt.listElements('LEGEND_ELEMENT')[0]

#Change the patch size for all legend items
#only display features in the visible map frame extent
for itm in leg.items:
  itm.patchHeight = 15
  itm.patchWidth = 30
  if itm.name == 'Geological Types':
    itm.showVisibleFeatures = True