ThinkGeo.com    |     Documentation    |     Premium Support

How can I display a background for a label?

I set up my label like so (see code below). How ca I create a background rectangle of one color so I can display label text inside it?



_featureLayer =



new InMemoryFeatureLayer();new FeatureSourceColumn(LABEL_KEY_NAME, "String", 30));PointType.Bitmap;TextStyles.City1(LABEL_KEY_NAME);PointPlacement.LowerRight;ApplyUntilZoomLevel.Level20;


_featureLayer.Open();


_featureLayer.Columns.Add(


_featureLayer.Close();


_featureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType =


_featureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = CreateGpsMarkerImage();


_featureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle =


_featureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.PointPlacement =


_featureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel =



Gregory,



  This is just a few lines of code.  On the TextSytle there is a mask property that you can use.  In the sample below you can see I create a new TextStyle just like you on the constructor.  Then I set the Mask property to an AreaStyle, this is what will be used for the mask.  Using the AreaStyle you can specify a fill, pen or either or, it is really flexible.  To control how large the mask is around your text you can set the TextStyle.MaskMargin as in the sample code below.  Making the value larger will make the margin at the mask takes up around your text larger.



 





     textsytle.Mask = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black, 1), new GeoSolidBrush(GeoColor.StandardColors.WhiteSmoke));
     textsytle.MaskMargin = 3;

 


 


David



Thanks, David. That works perfectly! I didn’t know what the Mask property was for but it looks very full-featured.

Greg, 
  
   Glad to see it all worked for you.  This was one of the first things we did with labeling.  I personally like the Halo property a bit better but the mask has a nice looking effect as well.  I think you can just use them for different situations.  Just in-case you didn’t know about the halo, it is used to put a soft ‘glow’ around the label.  This ‘glow’ helps set it apart and to not blend in with the background.  I think the Mask is more pronounced and would be great for a few items of high importance and it stands out better but the halo is nice also for maybe second level items. 
  
 David