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;
}
You need to branch in your
mapView:layerForAnnotation:and inspect some property or properties of theannotationin order to determine whether it's your marker or your shape. Then you can proceed with eitherRMMarkerorRMShapeas appropriate.I recommend the
annotation.userInfoproperty for this sort of info.