ThinkGeo.com    |     Documentation    |     Premium Support

Formatting/Splitting the Data for a Label

Hi,


I have a shapefile that has a field in the DBF named LandDescription that I want to label on.  I can get the label displaying fine, but the problem is that the data is stored in teh DBF like "12NW3228"  and I want the Label to display like this "12-NW-32-38".  Is there any way to do this besides splitting the one column in the DBF into multiple columns? 


Thanks!



Clint,


Thanks for the post! 

There are couple ways to accomplish this. 1st, you can create your own textStyle class, override the DrawCore method and custom the label you want to display. The code will be like this:



//……
DashTextStyle myTextStyle = new DashTextStyle("AREANAME", new GeoFont("Arial", 10, DrawingFontStyles.Italic), new GeoSolidBrush(GeoColor.StandardColors.Black));
                majorCitiesShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = myTextStyle;
//……      

  class DashTextStyle : TextStyle
    {
        protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labeledInLayer, Collection<SimpleCandidate> labeledInLayers)
        {
   // custom features’ string here
          base.DrawCore(features, canvas, labeledInLayer, labeledInLayers);
        }
    }


 


The 2nd one, you can hook up the layer.DrawingFeatures event and custom the label there. Code will be like this

 





// …
labelLayer.DrawingFeatures += new EventHandler<DrawingFeaturesEventArgs>(labelLayer_DrawingFeatures);
// …

void labelLayer_DrawingFeatures(object sender, DrawingFeaturesEventArgs e)
      {
        // custom e.FeaturesToDraw here
      }



 


Here also attached the code specific for your case, as well as the result as following. For any issues please let us know.

 





Ben.

119-CustomTheLabel.txt (1.88 KB)