AnsweredAssumed Answered

Unable to clear graphic/limit user to one graphic shown

Question asked by cmartin616 on Nov 15, 2014
Latest reply on Dec 12, 2014 by Gagandeep_Singh-esristaff

Hello,

 

I'm making an iOS app where the user clicks a point and a GP tool is run on the given X/Y of the point.  I've been successful in creating the point but each successive click adds another point.  I'd like the graphics layer to only contain the most recent point clicked.  The graphics flash off and back on after each click, so I think it is re-drawing.  Where am I going wrong?

 

Here is my code:

 

int graphicCount = 0;

 

-(void)addPoint:(AGSPoint*) mappoint{

   

    graphicCount+=1;

    AGSGraphicsLayer* myGraphicsLayer = [AGSGraphicsLayer graphicsLayer];

    [self.mapView addMapLayer:myGraphicsLayer withName:@"Graphics Layer"];

   

    //create a marker symbol to be used by our Graphic

    AGSSimpleMarkerSymbol *myMarkerSymbol =

    [AGSSimpleMarkerSymbol simpleMarkerSymbol];

    myMarkerSymbol.color = [UIColor blueColor];

   

    [myMarkerSymbol setSize:CGSizeMake(10,10)];

    [myMarkerSymbol setOutline:[AGSSimpleLineSymbol simpleLineSymbolWithColor:[UIColor redColor] width:1]];

   

    //Create an AGSPoint (which inherits from AGSGeometry) that

    //defines where the Graphic will be drawn

    AGSPoint* myMarkerPoint =

    [AGSPoint pointWithX:mappoint.x

                       y:mappoint.y

        spatialReference:[AGSSpatialReference wgs84SpatialReference]];

   

    //Create the Graphic, using the symbol and

    //geometry created earlier

    AGSGraphic* myGraphic =

    [AGSGraphic graphicWithGeometry:myMarkerPoint

                             symbol:myMarkerSymbol

                         attributes:nil];

   

    if(graphicCount>1){

        NSLog(@"DELETING OLD GRAPHICS");

        [myGraphicsLayer removeAllGraphics];

        graphicCount=0;

    }

   

    //Add the graphic to the Graphics layer

    [myGraphicsLayer addGraphic:myGraphic];

   

}

 

The if statement fires correctly but removeAllGraphics or removeGraphic: myGraphic do not remove the previous graphic.  Suggestions?  Thank you!

Outcomes