AnsweredAssumed Answered

Graphic with LineSymbol not displayed on GraphicTracker

Question asked by jjoalland13 on Feb 25, 2013
Latest reply on Aug 19, 2013 by davidclarke
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;  }      }

Outcomes