not able to add a polyline to a graphics layer

713
5
03-13-2011 08:45 PM
SumanChatterjee
New Contributor
Hi,
I am trying to add a polyline to a graphics layer. But it is not getting displayed although it is not giving any error.
Any help is highly appreciated!!
Thanks
Suman

The code is as below:

-(void)drawLine{
GisAppAppDelegate *mapDelegate =(GisAppAppDelegate *)[[UIApplication sharedApplication] delegate];
    int i= [mapDelegate.geomObject count];// geomObject is a mutableArray in which I am storing the AGSPoint on map click
if(i >= 2){
AGSMutablePolyline *polyline = [[AGSMutablePolyline alloc] initWithSpatialReference:self.mapView.spatialReference];
AGSSimpleLineSymbol *ln1=[AGSSimpleLineSymbol simpleLineSymbol];
ln1.color = [UIColor colorWithRed:9 green:0 blue: 0 alpha:0.5];
ln1.width = 5.0;
ln1.style = AGSSimpleLineSymbolStyleSolid;

[polyline addPathToPolyline];
         for (int x1=0; x1< i; x1++) {
  AGSPoint *mappoint= [self.geomObject objectAtIndex:x1];
 
  [polyline addPointToPath:[AGSPoint pointWithX:mappoint.x y:mappoint.y spatialReference:nil]];
 

      }
AGSGraphic *line=[[AGSGraphic alloc] initWithGeometry:polyline symbol:ln1 attributes:nil infoTemplateDelegate:nil];
          [self.myGraphicsLayer removeAllGraphics];
  [self.myGraphicsLayer addGraphic:line];

         [self.myGraphicsLayer dataChanged];
   }
}
0 Kudos
5 Replies
NimeshJarecha
Esri Regular Contributor
Hi Suman,

Please let me know following which will help to narrow down the issue.

What is the spatial reference of the points stored in geomObject?
What is the map's spatial reference which you are assigning to the polyline?

Regards,
Nimesh
0 Kudos
SumanChatterjee
New Contributor
Hi Nimesh,
Thanks! I am using the map service from arcgisonline .

static NSString *kMapServiceURL=@"http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer";

The spatial reference of the map as found in debugging is
wkid :4326
wkt:nil

The spatial reference of the points stored in the NSMutableArray geomObject is :
wkid:4326
wkt: out of scope.//although before getting added to the array the points have a wkt:nil



This is the code that is getting fired on  clicking on the map and where the points are getting stored in the array.


- (void) mapView: (AGSMapView *) mapView didClickAtPoint: (CGPoint) screen mapPoint: (AGSPoint *) mappoint graphics: (NSDictionary *) graphics

{
// adding a point

GisAppAppDelegate *mapDelegate =(GisAppAppDelegate *)[[UIApplication sharedApplication] delegate];
int k = [mapDelegate.geomObject count];
if (k == 0){
  NSMutableArray * geometryArray = [NSMutableArray array];
  [geometryArray addObject: mappoint];
  mapDelegate.geomObject = geometryArray;
 
}
else {
  [mapDelegate.geomObject addObject:mappoint];
}

[self drawLine];

}
0 Kudos
NimeshJarecha
Esri Regular Contributor
If possible, can you please attach a sample project so I can look at it and help you with?

Regards,
Nimesh
0 Kudos
SumanChatterjee
New Contributor
Hi Nimesh,
Thanks for taking so much pain. I am not able to attach the project here although the compressed project(.zip) is  1.2 MB. Can you send me an email address where I can send the zipped project. It will be really very helpful as I got stuck in it.


Thanks
Suman
0 Kudos
NimeshJarecha
Esri Regular Contributor
Send it to njarecha@esri.com

Regards,
Nimesh
0 Kudos