IOS 设置百度地图自定义标注图片,自定义泡泡

#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];


转载于:https://my.oschina.net/jack088/blog/526167

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值