# Sample for v5.0 LegendAdornmentLayer

**URL:** <https://community.thinkgeo.com/t/sample-for-v5-0-legendadornmentlayer/1709>\
**Category:** WinForms\
**Created:** [May 18, 2011, 10:17am UTC](https://community.thinkgeo.com/t/sample-for-v5-0-legendadornmentlayer/1709 "2011-05-18T10:17:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elisa](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@Elisa](https://community.thinkgeo.com/u/Elisa)\
**Post date:** [May 18, 2011, 10:17am UTC](https://community.thinkgeo.com/t/sample-for-v5-0-legendadornmentlayer/1709/1 "2011-05-18T10:17:25Z")

</div>

Your&nbsp;news&nbsp;announcement&nbsp;for&nbsp;the&nbsp;5.0&nbsp;version&nbsp;lists&nbsp;added&nbsp;support&nbsp;for&nbsp;creating&nbsp;map&nbsp;legends.&nbsp;&nbsp;However,&nbsp;I&nbsp;could&nbsp;not&nbsp;find&nbsp;any&nbsp;information&nbsp;or&nbsp;sample&nbsp;code&nbsp;on&nbsp;to&nbsp;how&nbsp;to&nbsp;do&nbsp;this.

Could&nbsp;you&nbsp;please&nbsp;post&nbsp;a&nbsp;sample&nbsp;application&nbsp;for&nbsp;the&nbsp;Desktop&nbsp;Edition&nbsp;of&nbsp;how&nbsp;to&nbsp;do&nbsp;this?&nbsp;&nbsp;Perhaps&nbsp;a&nbsp;Getting&nbsp;Started&nbsp;with&nbsp;sample&nbsp;code&nbsp;for&nbsp;the&nbsp;new&nbsp;features&nbsp;in&nbsp;5.0?

Thanks.

Elisa

---

<div class="post-metadata">

**Author:** ![Clint](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Clint](https://community.thinkgeo.com/u/Clint)\
**Post date:** [May 18, 2011, 3:57pm UTC](https://community.thinkgeo.com/t/sample-for-v5-0-legendadornmentlayer/1709/2 "2011-05-18T15:57:13Z")

</div>

Elisa,

Thank&nbsp;you&nbsp;for&nbsp;the&nbsp;post.&nbsp;&nbsp;There&nbsp;is&nbsp;currently&nbsp;a&nbsp;legend&nbsp;sample&nbsp;application&nbsp;being&nbsp;worked&nbsp;on&nbsp;that&nbsp;will&nbsp;be&nbsp;released&nbsp;out&nbsp;to&nbsp;the&nbsp;wiki&nbsp;in&nbsp;the&nbsp;coming&nbsp;days.&nbsp;&nbsp;If&nbsp;you&nbsp;follow&nbsp;us&nbsp;on&nbsp;Facebook&nbsp;or&nbsp;Twitter&nbsp;you&nbsp;will&nbsp;be&nbsp;notified&nbsp;whenever&nbsp;a&nbsp;new&nbsp;sample&nbsp;is&nbsp;added&nbsp;to&nbsp;the&nbsp;collection.

In&nbsp;order&nbsp;to&nbsp;help&nbsp;you&nbsp;get&nbsp;your&nbsp;feet&nbsp;wet&nbsp;with&nbsp;the&nbsp;new&nbsp;legend&nbsp;I&nbsp;have&nbsp;posted&nbsp;the&nbsp;following&nbsp;code&nbsp;below&nbsp;that&nbsp;shows&nbsp;how&nbsp;to&nbsp;use&nbsp;the&nbsp;new&nbsp;Legend&nbsp;Feature&nbsp;in&nbsp;5.0.&nbsp;&nbsp;The&nbsp;API&nbsp;is&nbsp;pretty&nbsp;easy&nbsp;to&nbsp;use,&nbsp;there&nbsp;are&nbsp;really&nbsp;only&nbsp;two&nbsp;classes&nbsp;you&nbsp;need&nbsp;to&nbsp;know.&nbsp;&nbsp;The&nbsp;LegendAdornmentLayer&nbsp;class&nbsp;which&nbsp;controls&nbsp;things&nbsp;like&nbsp;the&nbsp;Location,&nbsp;Title&nbsp;and&nbsp;Background&nbsp;mask&nbsp;the&nbsp;LegendItem&nbsp;class&nbsp;which&nbsp;defines&nbsp;the&nbsp;items&nbsp;that&nbsp;will&nbsp;be&nbsp;present&nbsp;in&nbsp;the&nbsp;Legend.&nbsp;&nbsp;Most&nbsp;of&nbsp;your&nbsp;code&nbsp;will&nbsp;be&nbsp;dealing&nbsp;with&nbsp;setting&nbsp;up&nbsp;LegendItems,&nbsp;each&nbsp;legend&nbsp;item&nbsp;has&nbsp;an&nbsp;ImageStyle&nbsp;property&nbsp;and&nbsp;a&nbsp;TextStyle&nbsp;propertly.&nbsp;&nbsp;This&nbsp;allows&nbsp;you&nbsp;to&nbsp;have&nbsp;full&nbsp;control&nbsp;over&nbsp;each&nbsp;item&nbsp;in&nbsp;the&nbsp;legend&nbsp;and&nbsp;make&nbsp;it&nbsp;look&nbsp;exactly&nbsp;how&nbsp;you&nbsp;want.&nbsp;&nbsp;The&nbsp;ImageStyle&nbsp;will&nbsp;take&nbsp;virtually&nbsp;any&nbsp;style&nbsp;that&nbsp;can&nbsp;be&nbsp;defined&nbsp;in&nbsp;Map&nbsp;Suite,&nbsp;it&nbsp;uses&nbsp;the&nbsp;DrawSample&nbsp;method&nbsp;of&nbsp;the&nbsp;Style&nbsp;to&nbsp;draw&nbsp;the&nbsp;image&nbsp;on&nbsp;the&nbsp;Legend&nbsp;so&nbsp;as&nbsp;long&nbsp;as&nbsp;your&nbsp;style&nbsp;support&nbsp;this&nbsp;method&nbsp;it&nbsp;will&nbsp;work&nbsp;in&nbsp;the&nbsp;legend&nbsp;too.&nbsp;&nbsp;The&nbsp;TextStyle&nbsp;property&nbsp;sets&nbsp;what&nbsp;Text&nbsp;you&nbsp;want&nbsp;to&nbsp;put&nbsp;by&nbsp;each&nbsp;legend&nbsp;item&nbsp;and&nbsp;allows&nbsp;you&nbsp;to&nbsp;control&nbsp;the&nbsp;font,&nbsp;color&nbsp;and&nbsp;size&nbsp;just&nbsp;like&nbsp;you&nbsp;would&nbsp;when&nbsp;setting&nbsp;a&nbsp;TextStyle&nbsp;to&nbsp;do&nbsp;labeling&nbsp;in&nbsp;Map&nbsp;Suite.

Please&nbsp;take&nbsp;a&nbsp;look&nbsp;at&nbsp;the&nbsp;code&nbsp;below&nbsp;and&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;questions&nbsp;or&nbsp;feedback.&nbsp;&nbsp;The&nbsp;result&nbsp;of&nbsp;this&nbsp;code&nbsp;will&nbsp;generate&nbsp;a&nbsp;Map&nbsp;just&nbsp;like&nbsp;the&nbsp;picture&nbsp;below.&nbsp;&nbsp;

 ![](https://community.thinkgeo.com/uploads/default/original/2X/2/214d9fc2e6fe211a6730c3fc12d955ce754bc162.png)

&nbsp;

`        winformsMap1.MapUnit = GeographyUnit.DecimalDegree;        LegendItem title = new LegendItem();        title.TextStyle = new TextStyle("Map Legend", new GeoFont("Arial", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));        LegendItem legendItem1 = new LegendItem();        legendItem1.ImageStyle = winformsMap1.FindFeatureLayer("Primaryborder").ZoomLevelSet.ZoomLevel09.DefaultLineStyle;        legendItem1.TextStyle = new TextStyle("State Borders", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));        LegendItem legendItem2 = new LegendItem();        legendItem2.ImageStyle = winformsMap1.FindFeatureLayer("Capitals").ZoomLevelSet.ZoomLevel06.CustomStyles[0];        legendItem2.TextStyle = new TextStyle("Capitals", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));                LegendItem legendItem3 = new LegendItem();        legendItem3.ImageStyle = winformsMap1.FindFeatureLayer("Fedlandnps").ZoomLevelSet.ZoomLevel04.DefaultAreaStyle;        legendItem3.TextStyle = new TextStyle("Forests", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));        LegendItem legendItem4 = new LegendItem();        legendItem4.ImageStyle = winformsMap1.FindFeatureLayer("Cover").ZoomLevelSet.ZoomLevel01.DefaultAreaStyle;        legendItem4.TextStyle = new TextStyle("Oceans", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));        LegendItem legendItem5 = new LegendItem();        legendItem5.ImageStyle = new AreaStyle(new GeoSolidBrush(new GeoColor(255, 0, 128, 0)));        legendItem5.TextStyle = new TextStyle("Trees", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));        LegendItem legendItem6 = new LegendItem();        legendItem6.ImageStyle = new AreaStyle(new GeoSolidBrush(new GeoColor(255, 128, 96, 0)));        legendItem6.TextStyle = new TextStyle("Dirt", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));        LegendAdornmentLayer legendLayer = new LegendAdornmentLayer();        legendLayer.BackgroundMask = AreaStyles.CreateLinearGradientStyle(new GeoColor(255, 255, 255, 255), new GeoColor(255, 230, 230, 230), 90, GeoColor.SimpleColors.Black);        legendLayer.LegendItems.Add(legendItem1);        legendLayer.LegendItems.Add(legendItem2);        legendLayer.LegendItems.Add(legendItem3);        legendLayer.LegendItems.Add(legendItem4);        legendLayer.LegendItems.Add(legendItem5);        legendLayer.LegendItems.Add(legendItem6);        legendLayer.Title = title;        legendLayer.Location = AdornmentLocation.LowerLeft;        AdornmentOverlay adornmentOverlay = new AdornmentOverlay();        adornmentOverlay.IsBase = true;        adornmentOverlay.Layers.Add("LengendLayer", legendLayer);        winformsMap1.Overlays.Add(adornmentOverlay);        winformsMap1.CurrentExtent = new RectangleShape(-125, 50, -66, 23);        winformsMap1.Refresh();`

&nbsp;

&nbsp;

Thanks!

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [May 23, 2011, 10:03am UTC](https://community.thinkgeo.com/t/sample-for-v5-0-legendadornmentlayer/1709/3 "2011-05-23T10:03:30Z")

</div>

Elisa,

We&nbsp;have&nbsp;just&nbsp;posted&nbsp;a&nbsp;new&nbsp;code&nbsp;sample&nbsp;that&nbsp;demonstrates&nbsp;the&nbsp;construction&nbsp;of&nbsp;a&nbsp;sample&nbsp;legend&nbsp;using&nbsp;the&nbsp;new&nbsp;LegendAdornmentLayer&nbsp;in&nbsp;Map&nbsp;Suite&nbsp;5.0.&nbsp;&nbsp;You&nbsp;can&nbsp;download&nbsp;it&nbsp;here:

[wiki.thinkgeo.com/wiki/Map\_S...w\_A\_Legend](http://wiki.thinkgeo.com/wiki/Map_Suite_Services_Edition_Miscellaneous_Samples#Show_A_Legend)

Please&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;questions.

Thanks,  
  
ThinkGeo&nbsp;Support
