# Label Positioning

**URL:** <https://community.thinkgeo.com/t/label-positioning/255>\
**Category:** WinForms\
**Created:** [February 21, 2009, 3:10am UTC](https://community.thinkgeo.com/t/label-positioning/255 "2009-02-21T03:10:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![John4](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@John4](https://community.thinkgeo.com/u/John4)\
**Post date:** [February 21, 2009, 3:10am UTC](https://community.thinkgeo.com/t/label-positioning/255/1 "2009-02-21T03:10:47Z")

</div>

Hi&nbsp;Guys,

We&nbsp;would&nbsp;like&nbsp;to&nbsp;ensure&nbsp;that&nbsp;labels&nbsp;are&nbsp;not&nbsp;cut&nbsp;off&nbsp;at&nbsp;the&nbsp;edges&nbsp;of&nbsp;the&nbsp;map&nbsp;control;&nbsp;this&nbsp;was&nbsp;automatic&nbsp;in&nbsp;our&nbsp;previous&nbsp;product.&nbsp;&nbsp;In&nbsp;other&nbsp;words&nbsp;we&nbsp;want&nbsp;to&nbsp;change&nbsp;the&nbsp;LabelPlacement&nbsp;to&nbsp;ensure&nbsp;the&nbsp;label&nbsp;is&nbsp;fully&nbsp;visible&nbsp;when&nbsp;the&nbsp;points&nbsp;are&nbsp;located&nbsp;towards&nbsp;the&nbsp;edges&nbsp;of&nbsp;the&nbsp;map&nbsp;control.

Does&nbsp;anyone&nbsp;have&nbsp;any&nbsp;thoughts&nbsp;about&nbsp;how&nbsp;to&nbsp;do&nbsp;this?

Regards

John

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [February 23, 2009, 3:17am UTC](https://community.thinkgeo.com/t/label-positioning/255/2 "2009-02-23T03:17:20Z")

</div>

John,

We&nbsp;don’t&nbsp;support&nbsp;it&nbsp;in&nbsp;the&nbsp;3.0&nbsp;version&nbsp;for&nbsp;now.&nbsp;You&nbsp;can&nbsp;implement&nbsp;it&nbsp;yourself&nbsp;by&nbsp;overwriting&nbsp;the&nbsp;GetLabelingCandidateCore&nbsp;method;&nbsp;there&nbsp;you&nbsp;can&nbsp;change&nbsp;the&nbsp;label’s&nbsp;position&nbsp;yourself.&nbsp;Sure&nbsp;it’s&nbsp;not&nbsp;very&nbsp;easy&nbsp;that&nbsp;you&nbsp;need&nbsp;to&nbsp;calculate&nbsp;if&nbsp;part&nbsp;of&nbsp;the&nbsp;label&nbsp;is&nbsp;cut&nbsp;off&nbsp;at&nbsp;the&nbsp;edge&nbsp;and&nbsp;if&nbsp;yes,&nbsp;how&nbsp;to&nbsp;modify&nbsp;that&nbsp;label.&nbsp;If&nbsp;you&nbsp;are&nbsp;very&nbsp;clear&nbsp;about&nbsp;the&nbsp;requirements,&nbsp;it’s&nbsp;not&nbsp;that&nbsp;hard.&nbsp;Here&nbsp;is&nbsp;a&nbsp;simple&nbsp;demo&nbsp;just&nbsp;show&nbsp;you&nbsp;how&nbsp;to&nbsp;change&nbsp;the&nbsp;position&nbsp;of&nbsp;a&nbsp;label&nbsp;in&nbsp;that&nbsp;override&nbsp;method.  
`  public partial class LabelNiceLookingRoads : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {            if (!Page.IsPostBack)            {                Map1.CurrentExtent = new RectangleShape(-97.766, 30.291, -97.755, 30.286);                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));                Map1.MapUnit = GeographyUnit.DecimalDegree;                ShapeFileFeatureLayer austinStreetsShapeLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~\SampleData\USA\Austin\austinstreets.shp"));                austinStreetsShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad1;                austinStreetsShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;                austinStreetsShapeLayer.DrawingMarginPercentage = 10;                ShapeFileFeatureLayer austinStreetsLabelLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~\SampleData\USA\Austin\austinstreets.shp"));                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new myTextStyle("FENAME", new GeoFont("Arial", 10), new GeoSolidBrush(GeoColor.StandardColors.Black));                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;                austinStreetsLabelLayer.DrawingMarginPercentage = 100;                Map1.StaticOverlay.Layers.Add(austinStreetsShapeLayer);                Map1.StaticOverlay.TileType = TileType.MultipleTile;                Map1.DynamicOverlay.Layers.Add(austinStreetsLabelLayer);            }        }    }    class myTextStyle : TextStyle    {        public myTextStyle()            : this("", new GeoFont(), new GeoSolidBrush())        { }        public myTextStyle(string textColumnName, GeoFont textFont, GeoSolidBrush textSolidBrush)            : base(textColumnName, textFont, textSolidBrush)        { }        protected override Collection<LabelingCandidate> GetLabelingCandidateCore(Feature feature, GeoCanvas canvas)        {            Collection<LabelingCandidate>  candidates = base.GetLabelingCandidateCore(feature, canvas);            foreach (LabelingCandidate candidate in candidates)            {                foreach (LabelInformation labelInformation in candidate.LabelInformation)                {                    labelInformation.PositionInScreenCoordinates.Y += 10;                }            }            return candidates;        }    }`

 ![](https://community.thinkgeo.com/uploads/default/original/2X/8/886df4db8201f2cddb5c0dae3cf7199950effb34.JPG)

Thanks,

Ben

---

<div class="post-metadata">

**Author:** ![John4](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@John4](https://community.thinkgeo.com/u/John4)\
**Post date:** [February 23, 2009, 7:19am UTC](https://community.thinkgeo.com/t/label-positioning/255/3 "2009-02-23T07:19:11Z")

</div>

Hi&nbsp;Ben,

Spot&nbsp;on&nbsp;mate,&nbsp;just&nbsp;exactly&nbsp;what&nbsp;I&nbsp;was&nbsp;looking&nbsp;for,&nbsp;I&nbsp;was&nbsp;just&nbsp;looking&nbsp;in&nbsp;the&nbsp;wrong&nbsp;place!

Regards

John

&nbsp;

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [February 23, 2009, 7:46pm UTC](https://community.thinkgeo.com/t/label-positioning/255/4 "2009-02-23T19:46:07Z")

</div>

Great&nbsp;it&nbsp;helps,&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;issues.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Ben

---

<div class="post-metadata">

**Author:** ![John4](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@John4](https://community.thinkgeo.com/u/John4)\
**Post date:** [March 13, 2009, 3:14am UTC](https://community.thinkgeo.com/t/label-positioning/255/5 "2009-03-13T03:14:03Z")

</div>

Hi&nbsp;Ben,

Back&nbsp;again,&nbsp;not&nbsp;quite&nbsp;there&nbsp;yet.

I'm&nbsp;very&nbsp;confused&nbsp;as&nbsp;to&nbsp;exactly&nbsp;what&nbsp;PositionInScreenCoordinates&nbsp;is&nbsp;and&nbsp;how&nbsp;it&nbsp;relates&nbsp;to&nbsp;the&nbsp;width&nbsp;and&nbsp;height&nbsp;of&nbsp;the&nbsp;winforms&nbsp;map&nbsp;control&nbsp;and&nbsp;the&nbsp;absolute&nbsp;position&nbsp;in&nbsp;pixels.&nbsp;&nbsp;The&nbsp;PositionInScreenCoordinates&nbsp;also&nbsp;seems&nbsp;to&nbsp;change&nbsp;with&nbsp;the&nbsp;zoom&nbsp;factor&nbsp;even&nbsp;if&nbsp;the&nbsp;point&nbsp;remains&nbsp;in&nbsp;the&nbsp;same&nbsp;physical&nbsp;poition&nbsp;on&nbsp;the&nbsp;winforms&nbsp;control.

I&nbsp;have&nbsp;the&nbsp;map&nbsp;control&nbsp;on&nbsp;a&nbsp;form,&nbsp;its&nbsp;width&nbsp;is&nbsp;668&nbsp;pixels&nbsp;and&nbsp;its&nbsp;height&nbsp;is&nbsp;400&nbsp;pixels,&nbsp;one&nbsp;single&nbsp;point&nbsp;with&nbsp;a&nbsp;label.

If&nbsp;I&nbsp;pan&nbsp;the&nbsp;map&nbsp;and&nbsp;position&nbsp;the&nbsp;point&nbsp;at&nbsp;the&nbsp;extreme&nbsp;top&nbsp;left&nbsp;hand&nbsp;edge&nbsp;of&nbsp;the&nbsp;map&nbsp;control&nbsp;its&nbsp;PositionInScreenCoordinates&nbsp;is&nbsp;reported&nbsp;as&nbsp;X&nbsp;=&nbsp;165,&nbsp;Y&nbsp;=&nbsp;247,&nbsp;move&nbsp;it&nbsp;to&nbsp;the&nbsp;right&nbsp;hand&nbsp;top&nbsp;corner&nbsp;and&nbsp;we&nbsp;get&nbsp;X&nbsp;=&nbsp;933&nbsp;and&nbsp;Y&nbsp;=&nbsp;165,&nbsp;move&nbsp;it&nbsp;to&nbsp;the&nbsp;bottom&nbsp;right&nbsp;hand&nbsp;corner&nbsp;and&nbsp;we&nbsp;get&nbsp;X&nbsp;=&nbsp;933&nbsp;and&nbsp;Y&nbsp;=&nbsp;503.&nbsp;&nbsp;This&nbsp;would&nbsp;seem&nbsp;to&nbsp;indicate&nbsp;that&nbsp;the&nbsp;width&nbsp;is&nbsp;768&nbsp;pixels&nbsp;and&nbsp;the&nbsp;height&nbsp;is&nbsp;256&nbsp;pixels.&nbsp;&nbsp;I'm&nbsp;confused.&nbsp;I&nbsp;kind&nbsp;of&nbsp;thought&nbsp;that&nbsp;the&nbsp;position&nbsp;in&nbsp;screen&nbsp;coordinates&nbsp;would&nbsp;be&nbsp;for&nbsp;the&nbsp;top&nbsp;left&nbsp;hand&nbsp;corner&nbsp;X&nbsp;=&nbsp;0&nbsp;and&nbsp;Y&nbsp;=&nbsp;0&nbsp;and&nbsp;for&nbsp;the&nbsp;left&nbsp;hand&nbsp;top&nbsp;corner&nbsp;x&nbsp;=&nbsp;668&nbsp;and&nbsp;Y&nbsp;=&nbsp;0&nbsp;etc.

What&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;do&nbsp;is&nbsp;to&nbsp;make&nbsp;sure&nbsp;that&nbsp;the&nbsp;labels&nbsp;that&nbsp;are&nbsp;positioned&nbsp;PointPlacement.UpperRight&nbsp;are&nbsp;always&nbsp;visible,&nbsp;so&nbsp;if&nbsp;the&nbsp;point&nbsp;is&nbsp;located&nbsp;on&nbsp;the&nbsp;left&nbsp;hand&nbsp;edge&nbsp;of&nbsp;the&nbsp;screen&nbsp;and&nbsp;is&nbsp;visible&nbsp;the&nbsp;label&nbsp;is&nbsp;displayed&nbsp;to&nbsp;the&nbsp;right&nbsp;of&nbsp;the&nbsp;point&nbsp;and&nbsp;is&nbsp;thus&nbsp;always&nbsp;fully&nbsp;visible.

My&nbsp;logic&nbsp;here&nbsp;would&nbsp;be&nbsp;to&nbsp;get&nbsp;the&nbsp;length&nbsp;of&nbsp;the&nbsp;label&nbsp;as&nbsp;drawn&nbsp;in&nbsp;pixels&nbsp;subtract&nbsp;that&nbsp;from&nbsp;PositionInScreenCoordinates.X&nbsp;and&nbsp;if&nbsp;the&nbsp;value&nbsp;is&nbsp;negative&nbsp;i.e&nbsp;off&nbsp;the&nbsp;visible&nbsp;screen,&nbsp;move&nbsp;the&nbsp;printed&nbsp;position&nbsp;of&nbsp;the&nbsp;label&nbsp;by&nbsp;adding&nbsp;the&nbsp;label&nbsp;width&nbsp;to&nbsp;PositionInScreenCoordinates.X&nbsp;to&nbsp;shift&nbsp;the&nbsp;label&nbsp;to&nbsp;the&nbsp;right&nbsp;of&nbsp;the&nbsp;point.

It&nbsp;seems&nbsp;daft&nbsp;to&nbsp;have&nbsp;a&nbsp;point&nbsp;visible&nbsp;on&nbsp;the&nbsp;screen&nbsp;with&nbsp;the&nbsp;label&nbsp;positioned&nbsp;to&nbsp;the&nbsp;right&nbsp;and&nbsp;not&nbsp;or&nbsp;only&nbsp;partially&nbsp;visible.

Any&nbsp;thoughts?

John

---

<div class="post-metadata">

**Author:** ![John4](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@John4](https://community.thinkgeo.com/u/John4)\
**Post date:** [March 15, 2009, 5:09am UTC](https://community.thinkgeo.com/t/label-positioning/255/6 "2009-03-15T05:09:05Z")

</div>

Hi&nbsp;Ben,

Found&nbsp;the&nbsp;solutiuon.

John

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [March 16, 2009, 12:27am UTC](https://community.thinkgeo.com/t/label-positioning/255/7 "2009-03-16T00:27:48Z")

</div>

That’s&nbsp;great,&nbsp;John.
