2

I'm looking to do the following. Create a point on a map at a given coordinate (x,y) and then display text at that point. Right now I can create a shape file but nothing is displayed on the map. Hopefully someone can tell me why

Here is my code:

ArcDisplay.IRgbColor color = new RgbColorClass()
{
    Red   = 255,
    Green = 255,
    Blue  = 255
};

IPoint point = new PointClass()
{
    X = 0.0,
    Y = 0.0,
    Z = 0.0,
    SpatialReference = myMap.Map.SpatialReference
};

IElement elem = null;
ITextElement txtElement = new TextElementClass();
element = textElement as IElement;

ITextSymbol textSymbol = new TextSymbolClass();
textSymbol.Color = color;
textSymbol.Size = 16;
textSymbol.Font = (stdole.IFontDisp)OLE.GetIFontDispFromFont(new Font("Arial" , 16 , FontStyle.Bold);

element.Geometry = point as IGeometry;

textSymbol.Text = "My Test Text";
txtElement.Symbol = textSymbol;

((ITextElement)element).Symbol = textSymbol;

IGrpahicsLayer graphicsLayer = new CompositeGraphicsLayerClass();
((ILayer)graphicsLayer).Name = "Text Layer";
IGraphicsContainer graphicsContainer = graphicsLayer as IGraphicsContainer;
graphicsContainer.AddElement(element , 0);

myMap.AddLayer(graphicsLayer as ILayer);
((ILayer)graphicsLayer).Draw(esriDrawPhase.esriDPGeography , null , null);

Any ideas?

0
2

I think I used to do it like this while in non-dynamic-display mode (warning haven't used this code in a while): -- In dynamic display mode it will flicker - so you will need another method for that.

IActiveView activeView = mapControl.Map as IActiveView;
ITextElement pTextElement;
IElement pElement;
ICallout pCallout;
IFormattedTextSymbol pTextSymbol;
IGraphicsContainer pGraphicsContainer;

pTextElement = new TextElementClass();
pElement = pTextElement as IElement;
pTextElement.Text = message;

ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;

int x, y;
displayTransformation.FromMapPoint(anchorPoint, out x, out y);IPoint messagePoint = mapControl.ToMapPoint(x, y - 100); //this is in pixels 
pElement.Geometry = messagePoint;

pTextSymbol = new TextSymbol();
pCallout = new BalloonCallout();
pTextSymbol.Background = pCallout as ITextBackground;
pCallout.AnchorPoint = anchorPoint;
pTextElement.Symbol = pTextSymbol;


if (pGraphicsContainer == null) pGraphicsContainer = activeView as IGraphicsContainer; 
pGraphicsContainer.AddElement(pElement, 0);
pElement.Activate(activeView.ScreenDisplay);
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);
1
  • pTextElement.Text = message;
    – ist_lion
    Mar 3 '11 at 13:38
0

Just throwing this out there - it could be something that you've already checked, but sometimes we overlook the simple stuff (I'm guilty of this constantly). But are the labels turned on for the feature?

1
  • Labels are not turned off. Thanks though
    – ist_lion
    Mar 3 '11 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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