Best practices: Graphics layers, symbols, and renderers

Using the ArcGIS API for Silverlight, you can dynamically display graphics on a map through a Graphics layer. A Graphics layer could, for example, be used to hold polygons drawn by a user or display features that satisfy a user-defined query.

Symbols define all the non-geographic aspects of a graphic's appearance. This includes a graphic's color, border width, transparency, and more. The ArcGIS API for Silverlight includes many symbol classes, each of which allows you to specify symbology in a unique way. Each symbol type is also specific to one geometry type (that is, point, line, or polygon).

Renderers define one or more symbols to apply to a Graphics layer. The symbol applied to each graphic depends on the graphic's attributes. The renderer specifies which attribute values correspond to which symbol.

The following sections detail some of the best practices for working with a GraphicsLayer, symbols, and renderers.

Set the GraphicsLayer.Renderer property

You must use the GraphicsLayer.Renderer property to set the layer’s symbology. If the Renderer property is not set when a GraphicsLayer is added to the map, the Map Web Part automatically populates this property with a default renderer; therefore, you should set the GraphicsLayer.Renderer property before the layer is added to the map. A GraphicsLayer’s Renderer property always overrides any symbols set via Graphic.Symbol.

GraphicsLayer gl = new GraphicsLayer()
    ID = "IdentifyResultsLayer",
    Renderer = new SimpleRenderer()
          Symbol = identifyDialog.Resources["RedMarkerSymbol"] as Symbol

Supported renderers

Only UniqueValueRenderer, ClassBreaksRenderer, and SimpleRenderer are currently supported for persistence and configuration. If an unsupported renderer type is used, users will not be able to configure the symbology of the results layer after it has been added to the map. As an example, consider a tool that adds a GraphicsLayer to the map. It is possible for users of the Application Builder to run such a tool while they are editing the Map Web Part. If they use a supported renderer type, users can configure the symbology of the results layer after it has been added to the map. Additionally, if they save or deploy that application, the results layer will be stored as part of that application’s map. These capabilities will not be available on GraphicsLayers that use renderer types that do not support persistence and configuration (for example, TemporalRenderer).

If a renderer type other than UniqueValueRenderer, ClassBreaksRenderer, or SimpleRenderer is used, do not allow the tool to be executed from within the Application Builder. This is because renderer types other than the ones listed do not support persistence and configuration. To do this, check whether Application.Current.IsEditMode is true, and, if so, prevent the tool from being run.

GraphicsLayer symbols

Declare the symbols used in your GraphicsLayer in a resource collection within your UI’s Extensible Application Markup Language (XAML). While symbols can be created programmatically, declaring them in XAML is more concise, readable, and generally easier to maintain.

       <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />

Layer name

To retrieve or set the layer name that is shown in the Map Contents panel, use MapApplication.LayerNameProperty. You can set the name by calling Layer.SetValue(MapApplication.LayerNameProperty, “layer name”), and retrieve the name by calling Layer.GetValue(MapApplication.LayerNameProperty).

GraphicsLayer gl = new GraphicsLayer();
gl.SetValue(MapApplication.LayerNameProperty, "Identify Results");