heres my code in my viewController class. implementing the graphics layer here.
#import "GMViewController.h"
@interface GMViewController ()
@end
@implementation GMViewController
@synthesize painting;
@synthesize colorPalette;
@synthesize colorPicker;
@synthesize mapView = _mapView;
@synthesize tiledLayer;
@synthesize dynamicLayer;
@synthesize sketchLayer;
@synthesize graphicsLayer;
@synthesize midSymbol;
@synthesize vertSymbol;
@synthesize cred;
@synthesize toolbar = _toolbar;
@synthesize sketchToolbar = _sketchToolbar;
@synthesize lineColor;
@synthesize gLine;
- (void)viewDidLoad
{
[super viewDidLoad];
painting1 = [[PaintingView alloc] init];
[painting1 setDelegate:self];
[painting setDelegate:self];
NSString *backgroundLayer = kTiledMapServiceURL1;
tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:backgroundLayer]];
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
NSString *pass = @"mobile1!";
cred = [[AGSCredential alloc] initWithUser:@"mobile" password:pass];
dynamicLayer = [[AGSDynamicMapServiceLayer alloc] initWithURL:[NSURL URLWithString: kDynamicMapServiceURL] credential:cred];
[self.mapView addMapLayer:dynamicLayer withName:@"Dynamic Layer"];
//Graphics layer to hold all sketches (points, polylines, and polygons)
graphicsLayer = [AGSGraphicsLayer graphicsLayer];
[self.mapView addMapLayer:graphicsLayer withName:@"Graphics Layer"];
AGSGraphicsLayer *graphicsLayer2 = [AGSGraphicsLayer graphicsLayer];
[self.mapView addMapLayer:graphicsLayer2 withName:@"Graphics Layer 2"];
//A composite symbol for the graphics layer's renderer to symbolize the sketches
AGSCompositeSymbol* composite = [AGSCompositeSymbol compositeSymbol];
AGSSimpleMarkerSymbol* markerSymbol = [[[AGSSimpleMarkerSymbol alloc] init] autorelease];
//markerSymbol.style = AGSSimpleMarkerSymbolStyleSquare;
//markerSymbol.color = [UIColor greenColor];
//[composite.symbols addObject:markerSymbol];
AGSSimpleLineSymbol* lineSymbol = [[[AGSSimpleLineSymbol alloc] init] autorelease];
lineSymbol.color= [UIColor redColor];
lineSymbol.width = 4;
[composite.symbols addObject:lineSymbol];
AGSSimpleFillSymbol* fillSymbol = [[[AGSSimpleFillSymbol alloc] init] autorelease];
fillSymbol.outline.color = [UIColor redColor];//colorWithRed:1.0 green:0 blue:0 alpha:4] ;
fillSymbol.outline.width = 4;
[composite.symbols addObject:fillSymbol];
AGSSimpleRenderer* renderer = [AGSSimpleRenderer simpleRendererWithSymbol:composite];
//graphicsLayer.renderer = renderer;
graphicsLayer2.renderer = renderer;
//Sketch layer
sketchLayer = [[[AGSSketchGraphicsLayer alloc] initWithGeometry:nil] autorelease];
[self.mapView addMapLayer:sketchLayer withName:@"Sketch layer"];
AGSSketchGraphicsLayer *sketchLayer2 = [[[AGSSketchGraphicsLayer alloc] initWithGeometry:nil]autorelease];
[self.mapView addMapLayer:sketchLayer2 withName:@"Sketch layer2"];
//Helper class to manage the UI toolbar, Sketch Layer, and Graphics Layer
//Basically, where the magic happens
self.sketchToolbar = [[[GMSketchToolBar alloc] initWithToolbar:self.toolbar
sketchLayer:sketchLayer2
mapView:self.mapView
graphicsLayer:graphicsLayer2] autorelease];
poly = [[AGSMutablePolyline alloc] initWithSpatialReference:self.mapView.spatialReference];
midSymbol = self.sketchLayer.midVertexSymbol;
vertSymbol = self.sketchLayer.vertexSymbol;
self.sketchLayer.midVertexSymbol = nil;
self.sketchLayer.vertexSymbol = nil;
AGSSpatialReference *sr = [AGSSpatialReference spatialReferenceWithWKID:1984];
AGSEnvelope *env = [AGSEnvelope envelopeWithXmin:-16.7178 ymin:10.9251 xmax:-13.6439 ymax:12.6847 spatialReference:sr];
[self.mapView zoomToEnvelope:env animated:YES];
gLine.outline.color = [UIColor redColor];
AGSSimpleFillSymbol *gfxLine = [[[AGSSimpleFillSymbol alloc] init] autorelease];
gfxLine.outline.color = [UIColor redColor];
//gLine = (AGSFillSymbol* )gfxLine;
AGSCompositeSymbol *mainSym = self.sketchLayer.mainSymbol;
for (AGSSymbol *s in mainSym.symbols)
{
if ([s isKindOfClass:[AGSSimpleFillSymbol class]])
{
lineColor = (AGSSimpleFillSymbol *)s;
lineColor.outline.color = [UIColor redColor]; //changes line
lineColor.outline.width = 4; // changes width of line.
}
}
}
-(void)makeLine:(CGPoint)touch firstTouch:(BOOL)firstTouch lineFinished:(BOOL)lineFinished
{
if (firstTouch)
{
//poly = [[AGSMutablePolyline alloc] initWithSpatialReference:self.mapView.spatialReference];
//self.sketchLayer.geometry = [[[AGSMutablePolyline alloc]initWithSpatialReference:self.mapView.spatialReference]autorelease];
[poly addPathToPolyline];
//polly = [[[AGSMutablePolyline alloc] initWithSpatialReference:self.mapView.spatialReference]autorelease];
}
[poly addPointToPath:[self.mapView toMapPoint:touch]];
self.sketchLayer.geometry = poly;
}
-(void) mapView:(AGSMapView *) mapView failedLoadingLayerForLayerView:(UIView<AGSLayerView> *)layerView baseLayer:(BOOL)baseLayer withError:(NSError *)error
{
if (!baseLayer)
[self.mapView removeMapLayerWithName:layerView.name];
}
- (void)viewDidUnload
{
[self setMapView:nil];
[self setPainting:nil];
[self setColorPicker:nil];
[self setColorPalette:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(void)dealloc
{
[painting1 release];
self.mapView = nil;
self.toolbar = nil;
self.sketchToolbar = nil;
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (IBAction)pullPaintBoard:(id)sender {
CGRect redLiningFrame = painting.frame;
CGRect colorFrame = colorPalette.frame;
if (redLiningFrame.origin.x == 0)
{
redLiningFrame.origin.x = 1024;
colorFrame.origin.x = 1024;
AGSGeometry* sketchGeometry = [[self.sketchLayer.geometry copy] autorelease];
//gLine.outline.color = lineColor.outline.color;
AGSGraphic* graphic = [AGSGraphic graphicWithGeometry:sketchGeometry symbol:lineColor attributes:nil infoTemplateDelegate:nil];
[self.graphicsLayer addGraphic:graphic];
[self.graphicsLayer dataChanged];
[self.sketchLayer clear];
}
else
{
redLiningFrame.origin.x = 0;
colorFrame.origin.x = 60;
}
painting.frame = redLiningFrame;
colorPalette.frame = colorFrame;
}
- (IBAction)colorPicker:(id)sender {
}
- (IBAction)selectRed:(id)sender {
lineColor.outline.color = [UIColor redColor];
gLine.outline.color = [UIColor redColor];
}
- (IBAction)selectBlue:(id)sender {
lineColor.outline.color = [UIColor blueColor];
gLine.outline.color = [UIColor blueColor];
}
- (IBAction)clearScreen:(id)sender {
[self.graphicsLayer removeAllGraphics];
[self.graphicsLayer dataChanged];
}
@end
edited code slightly to add lines to graphic layer.lines are created in my makeLine method. they are added to the graphic layer in the pullPaintBoard method.