pml

Using callouts programmatically with existing AGSGraphics

Discussion created by pml on Dec 4, 2011
Latest reply on Dec 5, 2011 by njarecha-esristaff
I have a tableView that holds an array of records that correspond with AGSGraphics which are in a mapView. The tableView and mapView are separate views. The goal here is to allow the user to tap the tableView's accessoryButton then the view changes to the mapView and a callout for the corresponding AGSGraphic shows. I can step through the code until I get to the first method in the infoTemplateDelegate. It is here that the Xcode gives the error message: "CALayer position contains NaN: [nan nan]". I am listing the code below in the order that it is stepped through.

I have two graphics layers - one that holds the graphics on the map (myGraphicsLayer) and another that is used to show the callout (popupGraphicsLayer). This seems odd so perhaps this is where I have messed up.

pointsTableController.m

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:
(NSIndexPath *)indexPath {
    
    GPS1AppDelegate *delegate = (GPS1AppDelegate *)[[UIApplication sharedApplication] delegate];
    mapViewController = [[MapView alloc] init];

    [delegate.navController pushViewController:mapViewController animated:YES];
    
    NSUInteger matchingObjectID;
    for ( NSMutableDictionary *dict1 in pointRows )
    {
        if ( [[dict1 valueForKey:@"dict_objectid"] isEqual:
[[pointRows objectAtIndex:indexPath.row] valueForKey:@"dict_objectid"]] )
        {
            matchingObjectID = [[dict1 valueForKey:@"dict_objectid"] intValue];
        }
    }
    
       [mapViewController selectThePoint:matchingObjectID];
}


MapView.m

-(void)selectThePoint:(NSUInteger)objectID
{
    
    self.popupGraphicsLayer = [AGSGraphicsLayer graphicsLayer];
    
    [self.mapView addMapLayer:self.popupGraphicsLayer withName:@"Popup Layer"];
    
    AGSGraphic *foundAGSGraphic;
    foundAGSGraphic = [[AGSGraphic alloc] init];
    for ( AGSGraphic *graphicItem in self.myGraphicsLayer.graphics )
    {
        if ( [[graphicItem.attributes valueForKey:@"dict_objectid"] intValue] == objectID )
        {
            foundAGSGraphic = graphicItem;
        }
    }

    [self.popupGraphicsLayer addGraphic:foundAGSGraphic];
    
    [self.popupGraphicsLayer dataChanged];
    
    [self.mapView showCalloutAtPoint:nil forGraphic:foundAGSGraphic animated:YES];
}


infoTemplateDelegate.m
@implementation infoTemplateDelegate

-(NSString *)titleForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)map
{
                // when this is called from selectThePoint, Xcode returns 
                // "CALayer position contains NaN:   [nan nan]" when
                //  the next line is stepped through.
  return [graphic.attributes valueForKey:@"dict_point_number"];
}

-(NSString *)detailForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)map
{
  return [graphic.attributes valueForKey:@"dict_comment"];
}

@end


Thanks for any help,
Paul Lohr

Outcomes