Mark a location with a Simple Marker Symbol

564
2
10-28-2011 01:25 PM
GregRieck
Occasional Contributor III
Hello,

I have a known location stored as an IPoint.  The point is not a feature class displayed in the map document.

How can I:
Mark the point location with a Simple Marker Symbol stored in a style?
Possibly change the size of the symbol.
Possibly include label information with the symbol.
Not have to add a layer to the map to accomplish this.
How do I remove the symbol from the map.

I've been able to display the location as a graphic. But I'd like to see if it's possible to do the same thing with symbols stored in a style file. I don't like how the graphics hide existing labels.
Any suggestions would be helpful including pointing to the correct Arc Object to get started.
G
0 Kudos
2 Replies
JustinConklin
New Contributor
Grieck,

The code below will add a simple marker symbol to the map at the location of pPoint(iPoint). The size and color are determined by the properties of the SimpleMarkerSymbol.  For the labeling, you can use the graphics container to add a TextSymbol at a location that is offset from pPoint - something like pPoint.X + 5, pPoint.Y + 5.  I'm not sure about use the style file you mentioned, but I hope this helps. 

Justin

Dim pRGB As IRgbColor = New RgbColor
        pRGB.Red = 84
        pRGB.Green = 255
        pRGB.Blue = 255


        Dim pPointSymbol As ISimpleMarkerSymbol = New SimpleMarkerSymbol
        pPointSymbol.Color = pRGB
        pPointSymbol.Size = 10


        Dim pPointEl As IMarkerElement = New MarkerElement
        pPointEl.Symbol = pPointSymbol
        Dim pElement As IElement = pPointEl
        pElement.Geometry = pPoint

        Dim pGraphicsContainer As IGraphicsContainer
        pGraphicsContainer = My.ArcMap.Document.FocusMap
        pGraphicsContainer.AddElement(pElement, 0)
        pElement.Activate(My.ArcMap.Document.ActiveView.ScreenDisplay)
        My.ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)
0 Kudos
GregRieck
Occasional Contributor III
Justin,

Thanks for responding. That's close to what I was looking for. I'm actually looking for a way to access a marker symbol inside a custom style. Your sample deals with a default ESRI symbol.

This is what I ended up with:
        IStyleGallery sg = MxDoc.StyleGallery;
        sg.LoadStyle("My.Style", "Marker Symbols");
        IEnumStyleGalleryItem pEnumStyGall = sg.get_Items("Marker Symbols", "My.Style", "");
        IMarkerSymbol msym = null;
        pEnumStyGall.Reset();
        IStyleGalleryItem2 sgitem2 = (IStyleGalleryItem2)pEnumStyGall.Next();
        while (sgitem2 != null)
        {
          if ((sgitem2.Name.ToLower() == "mysymbol") & (sgitem2.Tags.ToLower() == "mysymbol"))
          {
            msym = (IMarkerSymbol)sgitem2.Item;
            msym.Size = 108;
            break;
          }
          sgitem2 = (IStyleGalleryItem2)pEnumStyGall.Next();
        }
        IMarkerElement markerElement = new MarkerElementClass();
        markerElement.Symbol = (IMarkerSymbol) msym;
        IElement element = (IElement)markerElement;
        IElementProperties3 ep3 = (IElementProperties3)element;
        element.Geometry = point;
        ep3.Name = sgitem2.Name;
        MxDoc.ActiveView.GraphicsContainer.AddElement(element, 0);
        MxDoc.ActiveView.GraphicsContainer.UpdateElement(element);
        MxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
0 Kudos