# Map Legend

The **RadMap** control introduces the **MapLegend** object. It allows you to display a legend for a particular **Information Layer** inside the **RadMap** control. This topic will explain you the following:

* [Using the MapLegend object](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/map-legend#using-the-maplegend-object)

* [Configuring the Map Legend](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/map-legend#configuring-the-map-legend)

## Using the MapLegend object

The **MapLegend** object shouldn't be defined in the context of the **RadMap** control. It can be defined in any part of the **UserControl**. Here is an example of a **RadMap** that doesn't uses its default layout and a **MapLegend** that appears in the bottom right corner of the map.

```XAML
<telerik:RadMap x:Name="radMap"
	                Width="600"
	                Height="480"
	                UseDefaultLayout="False">
</telerik:RadMap>
<telerik:MapLegend x:Name="mapLegend">
</telerik:MapLegend>
```

At this point the **MapLegend** is not connected to the **RadMap** and the **RadMap** doesn't display any data, that should be reflected in the legend. Here is a **RadMap** that displays the world countries, read from an **ESRI Shapefile**. It uses its **Colorizer** property to color each country in different color depending on its area. On the other side the **MapLegend** object is connected to the **InformationLayer** displaying the countries via its **Layer** property.

> tip You can learn more about the MapShapeReader in the [Shape Reader](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder) help topic.

> The **MapLegend** creates the items in the legend on the basis of the **ColorMeasureScale** object set to the **Colorizer** property of the **Information Layer**.

```XAML
<telerik:RadMap x:Name="radMap1"
	                Width="600"
	                Height="480"
	                UseDefaultLayout="False">
    <telerik:InformationLayer x:Name="informationLayer1">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader DataSource="/Silverlight.Help.RadMapSamples;component/Data/world.dbf"
	                                    Source="/Silverlight.Help.RadMapSamples;component/Data/world.shp" />
        </telerik:InformationLayer.Reader>
        <telerik:InformationLayer.Colorizer>
            <telerik:ColorMeasureScale ExtendedPropertyName="SQKM"
	                                        Mode="Count"
	                                        TickMarkCount="7">
                <telerik:ColorMeasureScale.ShapeFillCollection>
                    <telerik:MapShapeFill Fill="#FFF0D9"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                    <telerik:MapShapeFill Fill="#FFE4BA"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                    <telerik:MapShapeFill Fill="#FFDBA3"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                    <telerik:MapShapeFill Fill="#FFD28D"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                    <telerik:MapShapeFill Fill="#FFBF5C"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                    <telerik:MapShapeFill Fill="#FFAF33"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                    <telerik:MapShapeFill Fill="#E2942D"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                </telerik:ColorMeasureScale.ShapeFillCollection>
                <telerik:ColorMeasureScale.HighlightFillCollection>
                    <telerik:MapShapeFill Fill="Orange"
	                                            Stroke="#B1946D"
	                                            StrokeThickness="1" />
                </telerik:ColorMeasureScale.HighlightFillCollection>
            </telerik:ColorMeasureScale>
        </telerik:InformationLayer.Colorizer>
    </telerik:InformationLayer>
</telerik:RadMap>
<telerik:MapLegend Layer="{Binding ElementName=informationLayer}"
	                    VerticalAlignment="Bottom"
	                    HorizontalAlignment="Right">
</telerik:MapLegend>
```

```C#
this.radMap.Provider = new EmptyProvider();
```

```VB.NET
	Me.radMap.Provider = New EmptyProvider()
```

Here is a snapshot of the result.

> tip To learn how to configure the appearance of the **MapLegend** and its items read the [next](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/map-legend#configuring-the-map-legend) section.

![WPF RadMap Map Legend](https://www.telerik.com/products/wpf/documentation/assets/de38e2009cc33b829e82a5a4ce1df173/radmap_features_maplegend_01.png)

## Configuring the Map Legend

To configure the appearance of the **MapLegend** you can use the following properties:

* **Format** - specifies the format string for the labels of the legend items.

* **Header** - specifies the content for the header of the legend. It is of type object and can be used as any other content property. Additionally you can use the **HeaderTemplate** and **HeaderTemplateSelecotr** properties with it.

* **MarkerSize** - specifies the size of the marker inside the legend item.

* **MarkerSpacing** - specifies the spacing between the legend items.

* **MarkerRadiusX** - specifies the X radius for the marker inside the legend item.

* **MarkerRadiusY** - specifies the Y radius for the marker inside the legend item

* **LabelLayout** - specifies whether the Label should be position in the center of the item or between the items.

* **LabelLocation** - specifies whether the label should be positioned in the top left corner or in the bottom right one.

* **Orientation** - specifies whether the order of the items in the legend should be vertical or horizontal.

Since **Q2 2011** you are allowed of using an arbitrary strings as map range labels in the *MapLegend* control. For the purpose - the **MaxOutput** and **MinOutput** properties of the *MapRange* class can be used. If these properties have not null and non-empty value, they will be used by MapLegend as range label.

Here is an example of a **MapLegend** configured via these properties:

> tip Defining format strings in XAML can be done in the following way - **{}:{0:your format string}.** To learn more about formatting visit the [Formatting Overview](http://msdn.microsoft.com/en-us/library/26etazsy.aspx) chapter in MSDN.

```XAML
<telerik:MapLegend x:Name="mapLegend1"
	                    Layer="{Binding ElementName=informationLayer}"
	                    Header="Area (in million sq.km.):"
	                    VerticalAlignment="Bottom"
	                    HorizontalAlignment="Right"
	                    Format="{}{0:0,,.0}"
	                    MarkerSize="40,20"
	                    MarkerSpacing="0"
	                    LabelLayout="Between"
	                    LabelLocation="BottomRight"
	                    Margin="0,0,10,10">
</telerik:MapLegend>
```

Here is a snapshot of the result:

![WPF RadMap Configured Map Legend](https://www.telerik.com/products/wpf/documentation/assets/4e1678cc6aa67c88327d731cb40027a3/radmap_features_maplegend_02.png)

## See Also

* [Shape Reader](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder)
* [Colorizer](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/colorizer)
* [Shape Appearance](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-appearance)
