Draw missing verticies in GeometryEditor sample

Discussion created by jsmithgisguy2 on May 7, 2013
Latest reply on May 10, 2013 by shamr0ck01
I was working with the GeometryEditor sample for Android and did not like that I could not see what I was adding: new Point features would not draw until saved to the server; polygons and lines would begin to draw only after the 2[SUP]nd[/SUP] vertex was added.

What I found within the code (GeometryEditor.java) was that there were 2 GraphicsLayer instances being used:

  • graphicsLayer                           - this is the culprit, is not drawing its content

  • graphicsLayerEditing         - this is the GOOD one

I got things to draw by using a single GraphicsLayer:  graphicsLayerEditing.

What was happening:
User-added vertices were being added to both GraphicsLayers. The graphicsLayer instance was attempting to draw the last vertex entered ??? in the case of Point features the only vertex entered. The GraphicsLayer never drew its content, due to the way it was being instantiated prior to map initialization. (There were actually 2 initializations in the onCreate method: 1 prior to, and 1 after map initialization).

What I did:
Below are my modifications to the drawVertices method. (I changed the color of the point/end-point to blue to improve my validation, disabled use of the graphicsLayer instance, changed/added comments).

private void drawVertices() {
         int index;
         // draw vertices
         index = 0;
         if(graphicsLayerEditing == null){
             graphicsLayerEditing = new GraphicsLayer();
         for (Point pt : points) {
             if (vertexselected && index == insertingindex){
                 // Draw only the SELECTED vertex
                 Graphic graphic = new Graphic(pt,new SimpleMarkerSymbol(Color.RED, 20,
                 Log.i(TAG, "Add (selected) Graphic vertex: " + index);
             else if (index == points.size() - 1 && !midpointselected && !vertexselected)
                 // This draws either the last vertex in a line/polygon or Point features
                 Graphic graphic = new Graphic(pt,new SimpleMarkerSymbol(Color.BLUE, 20,
 //                int id = graphicsLayer.addGraphic(graphic); // original version
                 // If INSTEAD the other graphics layer is added to, you can see added points for Point features!
                 // Also will draw the end-point when adding lines
                 int id = graphicsLayerEditing.addGraphic(graphic); // the fix
                 //Log.d(TAG, "Add Graphic mid point: "+ pt.getX()+" "+pt.getY()+" id = "+id);
                 Log.i(TAG,"Add Point or line end vertex: " + index);
                 // This is the most common case when adding lines/polygons for n=0 to n= points.size() - 2,
                 // draws all but the last vertex in a line
                 Graphic graphic = new Graphic(pt,new SimpleMarkerSymbol(Color.BLACK, 20,
                 Log.i(TAG, "Add Graphic point num: " + index);


This also could have been solved by only instantiating the graphicsLayer instance once, after the map status was initialized. It would then be drawing lines and polygons from 2 GraphicsLayer instances ??? I liked the simplicity of keeping a single feature in a single GraphicsLayer instance.