ios 百度地图SDK 设置标注点显示优先级,并自定义弹出视图
程序员文章站
2022-03-04 12:34:57
...
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation {
if ([annotation isKindOfClass:[CustomAnnotation class]]) {
/**
根据指定标识查找一个可被复用的标注,用此方法来代替新创建一个标注,返回可被复用的标注
*/
BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationViewIdentifier];
if (!annotationView) {
/**
初始化并返回一个annotationView
@param annotation 关联的annotation对象
@param reuseIdentifier 如果要重用view,传入一个字符串,否则设为nil,建议重用view
@return 初始化成功则返回annotationView,否则返回nil
*/
annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationViewIdentifier];
}
NSString *fileName;
if ([((CustomAnnotation*)annotation).specialFlag isEqual:@"start"]) {
fileName = @"start_70";
// CGPoint p={11,-11};
// annotationView.centerOffset=p;
[annotationView setBounds:CGRectMake(0, 0, 50, 50)];
annotationView.displayPriority=251 ;
}else if([((CustomAnnotation*)annotation).specialFlag isEqual:@"end"]){
fileName = @"end";
[annotationView setBounds:CGRectMake(0, 0, 50, 50)];
annotationView.displayPriority=252 ;
}else{
fileName = @"icon_nav_waypoint";
annotationView.displayPriority=BMKFeatureDisplayPriorityDefaultLow;
}
UIImage *img=[UIImage imageNamed:fileName];
//annotationView显示的图片,默认是大头针
annotationView.image =img;
TimeAddressPaoPaoView *customPopView = [[[NSBundle mainBundle] loadNibNamed:@"TimeAddressPaoPaoView" owner:nil options:nil] firstObject];
[customPopView setTimeStr:((CustomAnnotation*)annotation).timeStr andAddressStr:((CustomAnnotation*)annotation).title];
BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc] initWithCustomView:customPopView];
pView.frame = customPopView.frame;
annotationView.paopaoView = pView;
return annotationView;
}
return nil;
}
上一篇: C# 窗体控件
下一篇: 百度地图定位代码保存