Create Symbology & Labels From Attributes

559
2
02-18-2021 04:29 AM
mjzagis
New Contributor

I have a simple hosted layer showing six universities in Virginia:

https://services1.arcgis.com/7SazdyBTbp9w1Fga/arcgis/rest/services/VA_colleges_web_doc_test/FeatureS...

The attributes include hex values for the individual school colors: COLOR1 and COLOR2.  I want to take these attribute values and use them to color the symbology and label for each school.  I want COLOR1 to become the color of the point on the map and I want COLOR2 to become the color of the label on top of each point.

I could use a UniqueRenderer but, from what I've read, I would have to type out each unique value in the code.  I don't want to do that.  I want the program to go through the attribute table and collect the values it finds.  Is this possible?  If so, is there some code that can point me in the right direction?

Thank you.

0 Kudos
2 Replies
Noah-Sager
Esri Regular Contributor

Hi @mjzagis, yep, this should be possible to do. My recommendation would be to use a for loop and a uniqueValueRenderer. Then multiple labelClasses with where statements. Loop through each feature in the layer and pull out the color field value in the attribute of each feature and assign it to render the features with that value. Then do the same for the labels, but create a new LabelClass for each different color. I have some overly complicated code that I tried to simplify as an example, here's a snippet to get you started: https://github.com/NoashX/NoashX.github.io/blob/master/JavaScript/label_color_snippet.js

 

0 Kudos
mjzagis
New Contributor

Thank you Noah but I'm afraid this is beyond me.  I've learned a bit by looking at it but I haven't been able to use it for anything.  It also appears this code would loop through multiple layers in a webmap.  I'm working in a map with one layer.  Can the code be simplified to reflect this?  I only want to loop through the layer's attribute table.  Thank you.

0 Kudos