Select to view content in your preferred language

How To Render Layer By Unique Value Without Hard Coding the Values

8915
12
Jump to solution
12-07-2012 10:02 AM
Dan
by
Frequent Contributor
Javascript API 3.2  ArcGIS Server 10.1

Greetings,

I am new to the Javascript API (JSAPI), and am trying not to get bogged down with what should be very basic and easy by now.  But, nonetheless, here I am . . .

I would like to symbolize selected features in a polygon layer by unique value without hard-coding all of the values.

I also want to be sure that the colors are as distinguishable as possible depending on the quantity of unique values (in other words, not render 15 values in 15 shades of green, but render via an algorithm that does a better job than just random color generation).

The only unique-value renderer example I could find for JSAPI was here -----  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/renderer_uniqu...  ----- but it only shows how to do this by hard-coding each value.

I've been searching the web for a solution, but found none as of yet.  I've also been banging my head with ESRI support, but the answer I finally got was that there is no such thing as an ESRI unique value renderer for JSAPI and that I will have to hard code all of the values manually and write a bunch of Javascript to sort out any duplicates.  That just doesn't seem reasonable to me since rendering a selected set of polygons by unique value is fundamental GIS - basic thematic mapping that we've been doing for many years.

I just know there are many out there doing this successfully.  Any guidance would be appreciated.

Thanks.

-Dan
0 Kudos
12 Replies
JohnGravois
Deactivated User
heres a fiddle which demonstrates the usage of UniqueValueDefinition

although the number of unique values, algorithm, fromColor, and toColor can be modified to generate different results, This is not a "random" palette generator, but produces instead a ramp.

http://jsfiddle.net/jagravois/59Gra/
0 Kudos
JianHuang
Deactivated User
As John pointed out, it's not a random color palette. If you want the effect of the sample you attached, you can create a field with random values and generate the renderer based on it.
0 Kudos
Dan
by
Frequent Contributor
Thanks, everyone, for taking time to respond to this thread.
0 Kudos