Select to view content in your preferred language

Custom Symbology Using Renderers and Feature Sets

816
3
Jump to solution
04-16-2013 09:29 AM
DanielTrone
Deactivated User
I have a working application here: http://dola.colorado.gov/gis-cms/sites/default/files/html/census2000v2.html

I'm using the Javascript API with ArcGIS Online. I have a bunch of layers loaded and pre-symbolized in an AGOL 'Web Map'.

I'd like to be able to customize the symbology of each layer dynamically using javascript. I'd ideally like to use a renderer and be able to create a different symbology for each demographic variable.

I've run into a major brick wall. To be able to change the symbology, I need to be able to iterate through graphics in a feature set - yet I have no idea where to get a feature set object from. All the examples I see use 'Feature Layers' loaded through URLs.

Can anyone provide guidance or show me some good example code?
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
createMap gives you access to the map once it's loaded. From there, you can get to layers via map.getLayer and map.layerIds and (in your case, since you want to work with feature layers), map.graphicsLayerIds.

To be able to change the symbology, I need to be able to iterate through graphics in a feature set - yet I have no idea where to get a feature set object from. All the examples I see use 'Feature Layers' loaded through URLs.


Rather than iterating through features and changing their symbology, use a renderer. Here's an simple example that uses the CO counties layer from your webmap, changes the symbology and then turns the layer on:  http://jsfiddle.net/yUY34/

The example uses a SimpleRenderer but you can use a ClassBreaks or UniqueValue renderer depending on how you want to symbolize your data. If you comment out line 55, which sets the renderer, you'll see that the original symbology is used. You can use this approach in your app:  create renderers and then use featureLayer.setRenderer to specify them for your various feature layers.

View solution in original post

0 Kudos
3 Replies
derekswingley1
Deactivated User
createMap gives you access to the map once it's loaded. From there, you can get to layers via map.getLayer and map.layerIds and (in your case, since you want to work with feature layers), map.graphicsLayerIds.

To be able to change the symbology, I need to be able to iterate through graphics in a feature set - yet I have no idea where to get a feature set object from. All the examples I see use 'Feature Layers' loaded through URLs.


Rather than iterating through features and changing their symbology, use a renderer. Here's an simple example that uses the CO counties layer from your webmap, changes the symbology and then turns the layer on:  http://jsfiddle.net/yUY34/

The example uses a SimpleRenderer but you can use a ClassBreaks or UniqueValue renderer depending on how you want to symbolize your data. If you comment out line 55, which sets the renderer, you'll see that the original symbology is used. You can use this approach in your app:  create renderers and then use featureLayer.setRenderer to specify them for your various feature layers.
0 Kudos
DanielTrone
Deactivated User
You are a superhero!  This was just what I needed to solve my problem.  Thanks!
0 Kudos
derekswingley1
Deactivated User
You're welcome!
0 Kudos