Graphic with LineSymbol not displayed on GraphicTracker

1395
3
Jump to solution
02-25-2013 03:10 AM
JeremieJoalland1
Occasional Contributor II
ArcGIS Engine 10.1 for Java

I'm using the ESRI ArcObjects Java sample "AddPointGTCommand" to test the GraphicTracker performences. (from http://resources.arcgis.com/en/help/arcobjects-java/concepts/engine/index.html#//00010000068z000000).

I was able to change point's symbol by any customSymbol.
Now I'm trying to draw Lines on my GraphicTracker, it seems so simple, but can't get it working.

It seems all my random lines are added to the graphic Tracker (graphicTracker.getCount() return the right number), I can zoom to the extent of the last line added for example.

But I can't see any line on my map, like the LineSymbol I'm using is not correct, but can't determine what I'm missing here...

my source Code below :
package com.example.local;  import java.io.IOException; import java.util.Random;  import com.esri.arcgis.carto.IActiveView; import com.esri.arcgis.carto.IMap; import com.esri.arcgis.controls.BaseCommand; import com.esri.arcgis.controls.HookHelper; import com.esri.arcgis.display.IDisplayTransformation; import com.esri.arcgis.display.IScreenDisplay; import com.esri.arcgis.display.ISimpleLineSymbol; import com.esri.arcgis.display.ISymbol; import com.esri.arcgis.display.RgbColor; import com.esri.arcgis.display.SimpleLineSymbol; import com.esri.arcgis.display.esriSimpleLineStyle; import com.esri.arcgis.enginecore.GraphicTracker; import com.esri.arcgis.enginecore.IGraphicTracker; import com.esri.arcgis.enginecore.IGraphicTrackerSymbol; import com.esri.arcgis.geometry.Envelope; import com.esri.arcgis.geometry.IEnvelope; import com.esri.arcgis.geometry.ILine; import com.esri.arcgis.geometry.IPoint; import com.esri.arcgis.geometry.ISpatialReference; import com.esri.arcgis.geometry.Line; import com.esri.arcgis.geometry.Point;  public class AddPointGTCommand extends BaseCommand {    private static final long serialVersionUID = 1L;    private HookHelper hookHelper = null;  private IActiveView activeView;  private IScreenDisplay screenDisplay;  private IDisplayTransformation displayTransformation;  private IEnvelope mapVisibleExtent;  private IMap map;    private IGraphicTracker graphicTracker_LN;  private IGraphicTrackerSymbol graphicTrackerSymbol_LN;  private int numOfLines = 10; // number of lines   public AddPointGTCommand() throws Exception{   name = "Add GraphicTracker";   caption = "Add GraphicTracker";   toolTip = "Add GraphicTracker";   message = "Add GraphicTracker";   category = "CustomCommand";    enabled = true;  }    public void onCreate(Object obj) {   try {    hookHelper = new HookHelper();    hookHelper.setHookByRef( obj );   } catch (IOException ex) {    ex.printStackTrace();    throw new RuntimeException(ex);   }   }    public void onClick() {   try{    System.out.println("Add GraphicTracker is Clicked");                 map = hookHelper.getFocusMap();             activeView = hookHelper.getActiveView();             screenDisplay = activeView.getScreenDisplay();             displayTransformation = screenDisplay.getDisplayTransformation();              if (graphicTracker_LN == null)                 graphicTracker_LN = new GraphicTracker();              if (map != null) {              graphicTracker_LN.initialize(map);             }              // Init Data = draw lines             InitData();   }   catch(Exception e){    e.printStackTrace();   }  }    // private void InitData(int charIndex) throws Exception     private void InitData() throws Exception     {         ISpatialReference spatialReference;         spatialReference = hookHelper.getFocusMap().getSpatialReference();                  if (displayTransformation != null)         {             mapVisibleExtent = displayTransformation.getFittedBounds();         }         else         {             if (mapVisibleExtent == null)             {                 mapVisibleExtent = new Envelope();                 mapVisibleExtent.putCoords(-130.0, 25.0, -70.0, 55.0);                 mapVisibleExtent.setSpatialReferenceByRef(spatialReference);             }         }                  // initialize the points data according to the visible extent         double[] XMin = new double[1];         double[] YMin = new double[1];         double[] XMax = new double[1];         double[] YMax = new double[1];                  mapVisibleExtent.queryCoords(XMin, YMin, XMax, YMax);         double dWidth = XMax[0] - XMin[0];         double dHeight = YMax[0] - YMin[0];                  // Create the Line's symbol         ISymbol symboleLine = CreateSymbolLine();                  // Create the GraphicTracker symbol from LineSymbol         graphicTrackerSymbol_LN = graphicTracker_LN.createSymbol(symboleLine,  null);                  // suspend auto updates in order to do a bulk of updates         graphicTracker_LN.setSuspendUpdate(true);          Random rand = new Random();          // Dessin des LINES         ILine line = null;         for (int i = 0; i < numOfLines; i++)         {             IPoint point1 = new Point();             point1.putCoords(XMin[0] + rand.nextDouble() * dWidth, YMin[0] + rand.nextDouble() * dHeight);             IPoint point2 = new Point();             point2.putCoords(point1.getX() + 5, point1.getY() + 5);                          line = new Line();             line.setFromPoint(point1);             line.setToPoint(point2);             line.setSpatialReferenceByRef(spatialReference);                          // need to add the new element to the graphic tracker             int graphicId = graphicTracker_LN.add(line, graphicTrackerSymbol_LN);         }                  graphicTracker_LN.setSuspendUpdate(false);                  System.out.println("number of graphics : " + graphicTracker_LN.getCount());                  // zoom on last Line added !         activeView.setExtent(line.getEnvelope());         activeView.refresh();     }          private ISymbol CreateSymbolLine() throws Exception {         RgbColor clr = new RgbColor();   clr.setRed(150); clr.setGreen(50); clr.setBlue(200); // purple            ISimpleLineSymbol lineSymbol = new SimpleLineSymbol();         lineSymbol.setColor(clr);         lineSymbol.setWidth(1.20);         lineSymbol.setStyle(esriSimpleLineStyle.esriSLSSolid);    return (ISymbol) lineSymbol;  }      }
0 Kudos
1 Solution

Accepted Solutions
JeremieJoalland1
Occasional Contributor II
ok, found it.
as I use GraphicTracker in .net plateform before, I miss the CreateValidLine and CreateValidPolygon in Java...

So my symbol was correct, but my geometry polyline was not.

I can now draw polylines and polygons on my Graphic Tracker :

// Draw random polylines Random rand = new Random(); for (int i = 0; i < numOfLines; i++) {  // Initialize the Polyline  Point[] pointsPath0 = new Point[2];  Path pathColl[] = new Path[1];   Polyline polyline = new Polyline();  polyline.setSpatialReferenceByRef(spatialReference);   // Initialize points & path  pointsPath0[0] = new Point();  pointsPath0[1] = new Point();  pathColl[0] = new Path();    // Putcoords on the points  pointsPath0[0].putCoords(XMin[0] + rand.nextDouble() * dWidth, YMin[0] + rand.nextDouble() * dHeight);  pointsPath0[1].putCoords(pointsPath0[0].getX() + 5, pointsPath0[0].getY() + 5);   // Add points to separate paths  GeometryEnvironment gBridge = new GeometryEnvironment();  gBridge.addPoints(pathColl[0], pointsPath0);   // Add all the paths to the polyline using AddGeometries method  gBridge.addGeometries(polyline, pathColl);       // need to add the new element to the graphic tracker     int graphicId = graphicTracker_LN.add(polyline, graphicTrackerSymbol_LN);     graphicTracker_LN.setTransparency(graphicId, 50); }


// Draw random POLYGONS Random rand = new Random(); for (int i = 0; i < numOfPolygon; i++) {  // Initialize the polygon     Polygon polygon = new Polygon();  polygon.setSpatialReferenceByRef(spatialReference);    // Initialize the points  Point pt[] = new Point[3];  pt[0] = new Point();     pt[0].putCoords(XMin[0] + rand.nextDouble() * dWidth, YMin[0] + rand.nextDouble() * dHeight);  pt[1] = new Point();     pt[1].putCoords(pt[0].getX() + 5, pt[0].getY() + 5);  pt[2] = new Point();     pt[2].putCoords(pt[1].getX() -10, pt[1].getY());   // Add the points to the polygon  GeometryEnvironment gBridge = new GeometryEnvironment();  gBridge.addPoints(polygon, pt);                      // need to add the new element to the graphic tracker     int graphicId = graphicTracker_PL.add(polygon, graphicTrackerSymbol_PL);     graphicTracker_PL.setTransparency(graphicId, 50); }

View solution in original post

0 Kudos
3 Replies
JeremieJoalland1
Occasional Contributor II
ok, found it.
as I use GraphicTracker in .net plateform before, I miss the CreateValidLine and CreateValidPolygon in Java...

So my symbol was correct, but my geometry polyline was not.

I can now draw polylines and polygons on my Graphic Tracker :

// Draw random polylines Random rand = new Random(); for (int i = 0; i < numOfLines; i++) {  // Initialize the Polyline  Point[] pointsPath0 = new Point[2];  Path pathColl[] = new Path[1];   Polyline polyline = new Polyline();  polyline.setSpatialReferenceByRef(spatialReference);   // Initialize points & path  pointsPath0[0] = new Point();  pointsPath0[1] = new Point();  pathColl[0] = new Path();    // Putcoords on the points  pointsPath0[0].putCoords(XMin[0] + rand.nextDouble() * dWidth, YMin[0] + rand.nextDouble() * dHeight);  pointsPath0[1].putCoords(pointsPath0[0].getX() + 5, pointsPath0[0].getY() + 5);   // Add points to separate paths  GeometryEnvironment gBridge = new GeometryEnvironment();  gBridge.addPoints(pathColl[0], pointsPath0);   // Add all the paths to the polyline using AddGeometries method  gBridge.addGeometries(polyline, pathColl);       // need to add the new element to the graphic tracker     int graphicId = graphicTracker_LN.add(polyline, graphicTrackerSymbol_LN);     graphicTracker_LN.setTransparency(graphicId, 50); }


// Draw random POLYGONS Random rand = new Random(); for (int i = 0; i < numOfPolygon; i++) {  // Initialize the polygon     Polygon polygon = new Polygon();  polygon.setSpatialReferenceByRef(spatialReference);    // Initialize the points  Point pt[] = new Point[3];  pt[0] = new Point();     pt[0].putCoords(XMin[0] + rand.nextDouble() * dWidth, YMin[0] + rand.nextDouble() * dHeight);  pt[1] = new Point();     pt[1].putCoords(pt[0].getX() + 5, pt[0].getY() + 5);  pt[2] = new Point();     pt[2].putCoords(pt[1].getX() -10, pt[1].getY());   // Add the points to the polygon  GeometryEnvironment gBridge = new GeometryEnvironment();  gBridge.addPoints(polygon, pt);                      // need to add the new element to the graphic tracker     int graphicId = graphicTracker_PL.add(polygon, graphicTrackerSymbol_PL);     graphicTracker_PL.setTransparency(graphicId, 50); }
0 Kudos
JeremieJoalland1
Occasional Contributor II
I'm just curious to know if anybody has used the Transparency on GraphicTracker, which seems to be editable only at graphic level, not for tthe entire GraphicTracker.

but graphicTracker_PL.setTransparency(graphicId, 50); has no effect in my case, despite simple symbol types... documentation mentions that graphic's symbol has to support ISymbolEffects, but how can I check that ?
0 Kudos
DavidClarke1
New Contributor III
I was hoping for transparency as well and noticed this in the documentation for the "IGraphicTracker.SetTransparency" method.

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server. Requires 3D Analyst Extension.
0 Kudos