zhangzhb369

Can't get custom graphic from GraphicLayer...

Discussion created by zhangzhb369 on Jun 1, 2014
Latest reply on Jun 3, 2014 by zhangzhb369
### I create a custom circle graphic :

[PHP]
public class CircleGraphic extends Graphic {

private CircleGraphic(Geometry geometry, Symbol symbol) {
  super(geometry, symbol);
}

public static CircleGraphic getInstance(Point center, int size, int color) {
  Geometry geometry = getCircleGeometry(center, size);
  SimpleLineSymbol symbol = new SimpleLineSymbol(color, 3, SimpleLineSymbol.STYLE.SOLID);
 
  return new CircleGraphic(geometry, symbol);
}

public static Geometry getCircleGeometry(Point center, int size) {
  ......
}
}
[/PHP]

### Then I add this CircleGraphic to GraphicsLayer:

[PHP]
CircleGraphic circle = CircleGraphic.getInstance(point, size, color);
GraphicsLayer.addGraphic(circle);
[/PHP]

### But I can't get the CircleGraphic from the GraphicsLayer again:

[PHP]
        int[] ids = GraphicsLayer.getGraphicIDs();
        for (int i = 0; i < ids.length; i++) {
            int id = ids[i];
            Graphic g = getGraphic(id);
           
            if (g instanceof CircleGraphic) {
       ......   // can't reach here!! Why??  It should be a CircleGraphic!!
            }

            CircleGraphic circle = (CircleGraphic)getGraphic(id);  //raise type casting error... Why?? 
        }
[/PHP]

Thanks for your help .

Outcomes