2

I am currently trying to load different shapefiles in ArcObjects programmatically. Currently I can load lines, polylines, polygons and ellipses (even though that's just a fancy polygon as far as ArcObjects is concerned).

However, I'm having a problem loading texts. Basically it's a point on a map with some text above it.

This is how I'm trying to load the shapefile. Note this is basically the same thing I do for polygons, polylines and ellipses. The only notable difference is ITextSymbol as opposed to ISimpleFillSymbol for Polygons or ISimpleLineSymbol for lines:

IFeatureLayer featureLayer = new FeatureLayerrClass();
featureLayer.FeatureClass = myFeatureClass //Loaded from the featureWorkspace
featureLayer.Name = featureClass.AliasName;
featureLayer.Visibile = true;

IGeoFeatureLayer layer = featureLayer as IGeoFeatureLayer;

IRgbColor textColor = new RgbColorClass();
textColor.Red = 255;
textColor.Blue = 0;
textColor.Green =0;

ITextSymbol textSymbol = new TextSymbolClass();
textSymbol.Color = textColor;
textSymbol.Font = (stdole.IFontDisp)OLE.GetIFontDispFromFont(new Font("Arial", 12 , FontStyle.Bold);
textSymbol.Size = 12;
textSymbol.Text = myText;

ISimpleRenderer simpleRenderer = new SimpleRendererClass();
simpleRenderer.Symbol = textSymbol as ISymbol;
geoFeatureLayer.Renderer = simpleRenderer;

myAxMap.AddLayer(geoFeatureLayer as ILayer);
Invalidate();

1 Answer 1

2

Text symbols cannot be used as renderer symbols. You will need to set up labeling for your layer instead.

A good start for setting layer's labeling properties is IGeoFeatureLayer.AnnotationProperties.

3
  • I do labeling already with other shape files that have labels i.e rivers/lakes/ and just use the ILabelEngineLayerProperties and IAnnotateLayerProperties so I guess it's the same logic
    – ist_lion
    Commented Mar 24, 2011 at 18:19
  • That being said, should I be using IPoint as my shape? Or is there a better ESRI.ArcGIS.Geometry that I should be using. It was straight forward with Polygon/Polyline/Ellipse
    – ist_lion
    Commented Mar 24, 2011 at 18:26
  • But I guess you did not display any text for the polygon/polyline/ellipse cases, did you? Points are the obvious choice for text labels, but once you get into labeling, you can pretty much place the labels on top of anything (be it point, line or polygon).
    – Petr Krebs
    Commented Mar 24, 2011 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.