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

  1. #pragma mark - BMKMapViewDelegate  
  2.   
  3. // 根据anntation生成对应的View  
  4.   
  5. - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation  
  6.   
  7. {  
  8.   
  9.     //普通annotation  
  10.   
  11.     NSString *AnnotationViewID = @"ClusterMark";  
  12.   
  13.     ClusterAnnotation *cluster = (ClusterAnnotation*)annotation;  
  14.   
  15.     ClusterAnnotationView *annotationView = [[ClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];  
  16.   
  17.     annotationView.size = cluster.size;  
  18.   
  19.     annotationView.canShowCallout = NO;//在点击大头针的时候会弹出那个黑框框  
  20.   
  21.     annotationView.draggable = NO;//禁止标注在地图上拖动  
  22.   
  23.     annotationView.annotation = cluster;  
  24.   
  25. //    annotationView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]];  
  26.   
  27.     annotationView.centerOffset=CGPointMake(0,0);  
  28.   
  29.       
  30.   
  31.     UIView *viewForImage=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 110, 110)];  
  32.   
  33.     UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 110, 110)];  
  34.   
  35.     [imageview setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]]];  
  36.   
  37.     imageview.layer.masksToBounds=YES;  
  38.   
  39.     imageview.layer.cornerRadius = 10;  
  40.   
  41.     [viewForImage addSubview:imageview];  
  42.   
  43.     annotationView.image=[self getImageFromView:viewForImage];  
  44.   
  45.     return annotationView;  
  46.   
  47. }  
  48.   
  49.   
  50. -(UIImage *)getImageFromView:(UIView *)view{  
  51.   
  52.     UIGraphicsBeginImageContext(view.bounds.size);  
  53.   
  54.     [view.layer renderInContext:UIGraphicsGetCurrentContext()];  
  55.   
  56.     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();  
  57.   
  58.     UIGraphicsEndImageContext();  
  59.   
  60.     return image;  
  61.   
  62. }  
  63.   
  64.   
  65. //气泡框左侧显示的View,可自定义  
  66. annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_location.png"]];  
  67. //气泡框右侧显示的View 可自定义  
  68. annotationView.rightCalloutAccessoryView =selectButton;  
  69. //让标注在进入界面时就处于弹出气泡框的状态  
  70. [annotationView setSelected:YES animated:YES];  

猜你喜欢

转载自blog.csdn.net/iotjin/article/details/79715758