#pragma mark - BMKMapViewDelegate 
 
// 根据anntation生成对应的View 
 
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation 
 
{ 
 
    //普通annotation 
 
    NSString *AnnotationViewID = @"ClusterMark"; 
 
    ClusterAnnotation *cluster = (ClusterAnnotation*)annotation; 
 
    ClusterAnnotationView *annotationView = [[ClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; 
 
    annotationView.size = cluster.size; 
 
    annotationView.canShowCallout = NO;//在点击大头针的时候会弹出那个黑框框 
 
    annotationView.draggable = NO;//禁止标注在地图上拖动 
 
    annotationView.annotation = cluster; 
 
//    annotationView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]]; 
 
    annotationView.centerOffset=CGPointMake(0,0); 
 
     
 
    UIView *viewForImage=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 110, 110)]; 
 
    UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 110, 110)]; 
 
    [imageview setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]]]; 
 
    imageview.layer.masksToBounds=YES; 
 
    imageview.layer.cornerRadius = 10; 
 
    [viewForImage addSubview:imageview]; 
 
    annotationView.image=[self getImageFromView:viewForImage]; 
 
    return annotationView; 
 
} 
 
 
-(UIImage *)getImageFromView:(UIView *)view{ 
 
    UIGraphicsBeginImageContext(view.bounds.size); 
 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
 
    UIGraphicsEndImageContext(); 
 
    return image; 
 
} 
 
 
//气泡框左侧显示的View,可自定义 
annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_location.png"]]; 
//气泡框右侧显示的View 可自定义 
annotationView.rightCalloutAccessoryView =selectButton; 
//让标注在进入界面时就处于弹出气泡框的状态 
[annotationView setSelected:YES animated:YES]; 
 
 

发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

iOS通过按钮点击异步加载图片代码详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。