IOS 設置百度地圖自定義標註圖片,自定義泡泡

#pragma mark - BMKMapViewDelegatespa

// 根據anntation生成對應的Viewget

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotationit

{io

    //普通annotationselect

    NSString *AnnotationViewID = @"ClusterMark";sso

    ClusterAnnotation *cluster = (ClusterAnnotation*)annotation;map

    ClusterAnnotationView *annotationView = [[ClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];im

    annotationView.size = cluster.size;地圖

    annotationView.canShowCallout = NO;//在點擊大頭針的時候會彈出那個黑框框animate

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

相關文章
相關標籤/搜索