Select to view content in your preferred language

Displaying a circular arc with the Graphic Tracker

1101
6
Jump to solution
04-02-2012 04:42 AM
ManfredLauterbach
Deactivated User
Hi,

This documentation : http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Using_a_GraphicTracker/... provides some information about the graphic tracker.
It states that the tracker only supports IPoint, IPolyline, and IPolygon geometry.

Thanks to Neil's explanation (http://forums.arcgis.com/threads/54068-Extracting-elliptical-properties-from-TrackCircle%28%29-geome...) I understand how a polygon is several objects at once - it could represent a circular arc.
In other words, we are able to create a circular arc (which could be a complete circle), and add it to the graphics tracker - but I'm having trouble with this - nothing is displayed, even though the call to add the graphic succeeds :

           ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();           RgbColorClass red = new RgbColorClass() { Red = 255, Green = 0, Blue = 0 };           fillSymbol.Color = red;           fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;           IGraphicTrackerSymbol graphicTrackerSymbol = graphicTracker.CreateSymbol(fillSymbol as ISymbol, null);            PointClass centroid = new PointClass();           PointClass fromPoint = new PointClass();           PointClass toPoint = new PointClass();           centroid.PutCoords(0, 0);           fromPoint.PutCoords(0, 10);           toPoint.PutCoords(10, 0);           CircularArcClass circularArc = new CircularArcClass();           circularArc.PutCoords(centroid, fromPoint, toPoint, esriArcOrientation.esriArcClockwise);            int graphicID = graphicTracker.Add(circularArc, graphicTrackerSymbol);            mapControl.Refresh(); 



However, when displaying something else, like a character marker symbol, it displays correctly :

           ICharacterMarkerSymbol charSymbol = new CharacterMarkerSymbolClass();           charSymbol.CharacterIndex = 122;           charSymbol.Color = new RgbColorClass() { Red = 15, Green = 255, Blue = 255 };           charSymbol.Font = tactFont;           charSymbol.Size = 36;           charSymbol.XOffset = 0;           charSymbol.YOffset = 0;            PointClass offset = new PointClass() { X = 0, Y = 0 };           IGraphicTrackerSymbol graphicTrackerSymbol = graphicTracker.CreateSymbol(charSymbol as ISymbol, null);           int graphicID = graphicTracker.Add(offset, graphicTrackerSymbol); 


Does the tracker only display objects that do not have an associated geometry (i.e. the graphics tracker accepts a separate geometry object only to position the symbol)?
I've found several references on the web which indicate that the first section of code (with the circular arc) should be working - can anyone explain what is wrong there?


(similarly with Cartographic Symbol - nothing is displayed) :
           CartographicLineSymbolClass cartoSymbol = new CartographicLineSymbolClass();           cartoSymbol.Color = new RgbColorClass() { Red = 0, Green = 0, Blue = 255 };           cartoSymbol.Cap = esriLineCapStyle.esriLCSButt;           cartoSymbol.Join = esriLineJoinStyle.esriLJSBevel;           cartoSymbol.Width = 2;            PointClass p1 = new PointClass() {X = 0, Y = 10};           PointClass p2 = new PointClass() {X = 10, Y = 0};           ILine line = new LineClass();           line.PutCoords(p1, p2);            IEnvelope env = new EnvelopeClass() { XMin = -10, XMax = 10, YMin = -10, YMax = 10 };           IGraphicTrackerSymbol graphicTrackerSymbol = graphicTracker.CreateSymbol(cartoSymbol as ISymbol, null);           int graphicID = graphicTracker.Add(env, graphicTrackerSymbol); 
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Honored Contributor
I've never used this class but from the documentation it looks like the graphics tracker only works on high level geometries.  Even though there are many classes that implement IGeometry only those that also implement IPoint, IMultiPoint, IPolyline, or IPolygon are considered high level geometries (at least in the 2d world).  So, what you need to do is create a polyline from the circular arc.  To do this, you create a new polyline object and add the circular arc to its segment collection.  You then pass the polyline to the graphics tracker.

Dim polyline As IPolyline = New Polyline
DirectCast(polyline, ISegmentCollection).AddSegment(circularArc)

This is why your example with the point worked and the other two didn't.  A Point is a high level geometry while the circular arc and envelope are not.

View solution in original post

0 Kudos
6 Replies
NeilClemmons
Honored Contributor
I've never used this class but from the documentation it looks like the graphics tracker only works on high level geometries.  Even though there are many classes that implement IGeometry only those that also implement IPoint, IMultiPoint, IPolyline, or IPolygon are considered high level geometries (at least in the 2d world).  So, what you need to do is create a polyline from the circular arc.  To do this, you create a new polyline object and add the circular arc to its segment collection.  You then pass the polyline to the graphics tracker.

Dim polyline As IPolyline = New Polyline
DirectCast(polyline, ISegmentCollection).AddSegment(circularArc)

This is why your example with the point worked and the other two didn't.  A Point is a high level geometry while the circular arc and envelope are not.
0 Kudos
ManfredLauterbach
Deactivated User
Thanks for the suggestion, but ArcObjects throws an exception when trying to cast polyline to ISymbol :

          IPolyline polyline = new PolylineClass();
          ISegmentCollection segmentCollection = polyline as ISegmentCollection;
          segmentCollection.AddSegment(circularArc);
          ISymbol targetSymbol = (ISymbol)polyline;


{System.InvalidCastException: Unable to cast COM object of type 'ESRI.ArcGIS.Geometry.PolylineClass' to interface type 'ESRI.ArcGIS.Display.ISymbol'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{F3435802-5779-11D0-98BF-00805F7CED21}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I've tried doing the same in AfterDraw() - without using the graphic tracker, but get an exception when drawing directly to the map instead as well.

Is there any other way to add an ellipse to the graphic tracker?
0 Kudos
NeilClemmons
Honored Contributor
You can't cast a geometry to a symbol.  The first code example you posted is what you should be doing except you create the polyline using the circular arc and then pass the polyline to the Add method instead of the circular arc.
0 Kudos
ManfredLauterbach
Deactivated User
ok, got it now - I was getting confused with the other examples.


          ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
          RgbColorClass red = new RgbColorClass() { Red = 255, Green = 0, Blue = 0 };
          fillSymbol.Color = red;
          fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;

          PointClass centroid = new PointClass();
          PointClass fromPoint = new PointClass();
          PointClass toPoint = new PointClass();
          centroid.PutCoords(0, 0);
          fromPoint.PutCoords(0, 10);
          toPoint.PutCoords(10, 0);
          CircularArcClass circularArc = new CircularArcClass();
          circularArc.PutCoords(centroid, fromPoint, toPoint, esriArcOrientation.esriArcClockwise);


 
          IPolyline polyline = new PolylineClass();
          ISegmentCollection segmentCollection = polyline as ISegmentCollection;
          segmentCollection.AddSegment(circularArc);


          IGraphicTrackerSymbol graphicTrackerSymbol = graphicTracker.CreateSymbol(fillSymbol as ISymbol, null);

          int graphicID = graphicTracker.Add(polyline, graphicTrackerSymbol);





This still doesn't display anything though (like the first and third code sample in my first post).

feel like something else is fundamentally wrong? - The second code example is the only one that does not associate a geometry with the symbol, could that be the problem, that the GraphicTracker will not work with certain symbol geometry?
(the viewing extent should be correct because when adding a marker symbol it is immediately visible at the correct location).
0 Kudos
NeilClemmons
Honored Contributor
Yeah, I forgot to mention you're using the wrong symbol type.  You're creating a fill symbol and trying to use it to draw a polyline.  You need to use a line symbol type instead.  In the envelope sample, you're trying to use a line symbol type to draw a polygon (you'd need to create a polygon from the envelope).  You should be using a fill symbol.  Those changes should be all you need to get it working.
0 Kudos
ManfredLauterbach
Deactivated User
Sorted. Thanks for the help.


          IGraphicTrackerSymbol graphicTrackerSymbol = graphicTracker.CreateSymbol(lineSymbol as ISymbol, null);
          int graphicID = graphicTracker.Add(polyline, graphicTrackerSymbol);

0 Kudos