Add case for symbol code only; draw line symbol colors

This commit is contained in:
Fuhrmann 2024-12-09 09:57:25 +01:00
parent cfcc9bdfd7
commit 18f5ca5aa5

View file

@ -378,7 +378,7 @@ class FeatureRenderer:
# Print message if symbol could not be found
if not symbol_found:
messages.AddMessage(
f"Could not find symbol {symbol_key} for {leg_id}"
f"Could not find symbol in gallery {symbol_key}"
)
# Add user defined labels
@ -393,9 +393,13 @@ class FeatureRenderer:
# Retrieve stroke symbol properties
stroke_symbol_props = {}
if layer_shape_type == "Polygon":
for group in cim_lyr.renderer.groups:
for unique_value_class in group.classes:
if unique_value_class.values[0].fieldValues[0] != "<Null>":
if (
unique_value_class.values[0].fieldValues[0]
!= "<Null>"
):
leg_id = str(
unique_value_class.values[0].fieldValues[0]
)
@ -418,9 +422,11 @@ class FeatureRenderer:
# Set user defined outline color
outline_code = outline_codes[leg_id]
color_value = get_symbol_color(outline_code)
color = arcpy.cim.CreateCIMObjectFromClassName(
color = (
arcpy.cim.CreateCIMObjectFromClassName(
"CIMCMYKColor", "V3"
)
)
color.values = color_value["CMYK"]
stroke_symbol_props[leg_id]["color"] = color
else:
@ -431,13 +437,13 @@ class FeatureRenderer:
] = symbol_layer.color
else:
# Set default color
color = (
arcpy.cim.CreateCIMObjectFromClassName(
color = arcpy.cim.CreateCIMObjectFromClassName(
"CIMCMYKColor", "V3"
)
)
color.values = [40, 40, 40, 10, 100]
stroke_symbol_props[leg_id]["color"] = color
stroke_symbol_props[leg_id][
"color"
] = color
if draw_outlines:
if symbol_layer.width:
@ -458,7 +464,6 @@ class FeatureRenderer:
# In case the layer did not have a stroke symbol layer or outline color
if not stroke_symbol_props[leg_id]["color"]:
if leg_id in outline_codes:
messages.AddMessage("Add color")
# Set user defined outline color
outline_code = outline_codes[leg_id]
color_value = get_symbol_color(outline_code)
@ -505,7 +510,7 @@ class FeatureRenderer:
color_value = code_components["color"]
symbol_color_value = code_components["symbol_color"]
has_color = False
has_background_color = False
for (
symbol_layer
) in unique_value_class.symbol.symbol.symbolLayers:
@ -516,14 +521,14 @@ class FeatureRenderer:
)
if color_value:
# Update colors
# Update background colors
if layer_shape_type == "Polygon":
if isinstance(
symbol_layer,
arcpy.cim.CIMSymbols.CIMSolidFill,
):
update_color(symbol_layer, color_value)
has_color = True
has_background_color = True
if isinstance(
symbol_layer,
@ -536,23 +541,8 @@ class FeatureRenderer:
stroke_symbol_props[leg_id]["color"]
)
elif layer_shape_type == "Polyline":
if isinstance(
symbol_layer,
arcpy.cim.CIMSymbols.CIMSolidStroke,
):
update_color(symbol_layer, color_value)
has_color = True
elif layer_shape_type == "Point":
if isinstance(
symbol_layer,
arcpy.cim.CIMSymbols.CIMMarker,
):
update_color(symbol_layer, color_value)
has_color = True
# Draw symbol background colors
if not has_color and color_value:
if not has_background_color and color_value:
if layer_shape_type == "Polygon":
# Add fill symbol layer
fill_symbol = arcpy.cim.CIMSolidFill()
@ -574,20 +564,6 @@ class FeatureRenderer:
unique_value_class.symbol.symbol.symbolLayers.append(
stroke_symbol
)
elif layer_shape_type == "Polyline":
# Add stroke symbol layer
stroke_symbol = arcpy.cim.CIMSolidStroke()
update_color(stroke_symbol, color_value)
unique_value_class.symbol.symbol.symbolLayers.append(
stroke_symbol
)
elif layer_shape_type == "Point":
# Add marker symbol layer
marker_symbol = arcpy.cim.CIMMarker()
update_color(marker_symbol, color_value)
unique_value_class.symbol.symbol.symbolLayers.append(
marker_symbol
)
# Regroup items
if heading_field:
@ -638,6 +614,9 @@ def update_color(symbol_layer, color_value):
def update_symbol_layer_colors(symbol_layer, symbol_color_value):
if isinstance(symbol_layer, arcpy.cim.CIMSymbols.CIMSolidStroke):
update_color(symbol_layer, symbol_color_value)
if isinstance(
symbol_layer,
arcpy.cim.CIMSymbols.CIMCharacterMarker,
@ -675,6 +654,14 @@ def get_code_components(code):
"symbol_key": "",
"symbol_color": {},
}
if code_len == 7:
return {
"color": {},
"symbol_key": code[0:7],
"symbol_color": {
"CMYK": [0, 0, 0, 100, 100],
},
}
elif code_len == 10:
return {
"color": {},