1

I am drawing a line in - (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation. But at the same time i also want to use a customise marker for annotaion. How can i do this. Any kind of help will be really appreciated. Below are my source code.

-(void) drawSipTrackerPath
{



    RMMapboxSource *tileSource = [[RMMapboxSource alloc] initWithMapID:@"id"];


    self.mapView = [[RMMapView alloc] initWithFrame:CGRectMake(0, 64, 375, 534) andTilesource:tileSource];

    self.mapView.delegate = self;

    self.mapView.clusteringEnabled = YES;

    [self.view addSubview:self.mapView];

    self.mapView.zoom = 3;

    self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
    UIViewAutoresizingFlexibleWidth;


    double latitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray lastObject]valueForKey:@"lat"]] doubleValue];

    double longnitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray lastObject]valueForKey:@"lon"]] doubleValue];




    for(NSInteger i=0; i < self.trajectoryArray.count; i++)
    {
        double latitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray objectAtIndex:i]valueForKey:@"lat"]] doubleValue];

        double longnitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray objectAtIndex:i]valueForKey:@"lon"]] doubleValue];

        CLLocation* location = [[CLLocation alloc]initWithLatitude:latitude longitude:longnitude];

        [self.trajectoryArray replaceObjectAtIndex:i withObject:location];
    }


    CLLocationCoordinate2D coordinate = [self getLocationObject:latitude toLong:longnitude];

    RMAnnotation *annotation = [[RMAnnotation alloc] initWithMapView:self.mapView
                                                          coordinate:coordinate
                                                            andTitle:@"My Path"];
    annotation.userInfo = @"My path";

    [self.mapView addAnnotation:annotation];


    RMPointAnnotation *annotationn = [[RMPointAnnotation alloc]
                                     initWithMapView:self.mapView
                                     coordinate:coordinate
                                     andTitle:@"Hello, world!"];


    annotationn.annotationIcon = [UIImage imageNamed:@"arrow"];

    annotationn.userInfo = @"Hello World";

    [self.mapView addAnnotation:annotationn];


    [annotationn setBoundingBoxFromLocations:self.trajectoryArray];


     [self.mapView setCenterCoordinate:coordinate animated:YES];

}

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{   
    if (annotation.isUserLocationAnnotation)
        return nil;

    RMShape *shape = [[RMShape alloc] initWithView:mapView];
    shape.lineColor = [UIColor redColor];
    shape.lineWidth = 5.0;
    for (CLLocation *point in self.trajectoryArray)
    {
        [shape addLineToCoordinate:point.coordinate];
    }


    return shape;

}
Or Ron
  • 2,313
  • 20
  • 34
Rafay Hasan
  • 115
  • 9

1 Answers1

0

You need to branch in your mapView:layerForAnnotation: and inspect some property or properties of the annotation in order to determine whether it's your marker or your shape. Then you can proceed with either RMMarker or RMShape as appropriate.

I recommend the annotation.userInfo property for this sort of info.

incanus
  • 5,100
  • 1
  • 13
  • 20
  • If i branch this then shape never gets called and path isn't drawing. Can you please help me with this as i am having a hard time with this. Please check the source code screenshot https://www.dropbox.com/s/vbbswtwukisryva/Screen%20Shot%202015-08-21%20at%202.59.34%20PM.png?dl=0 – Rafay Hasan Aug 21 '15 at 08:58