美文网首页
地图上添加自定义的大头针

地图上添加自定义的大头针

作者: 神一样的队友 | 来源:发表于2018-08-14 15:23 被阅读0次

大头针的图片是网络图片,之前整的都特卡,搜了半天,解决方法如下,加载网络图片就不卡了

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id )annotation

{

 if ([annotation isKindOfClass:[ClusterAnnotation class]]) {// 聚合状态

 NSString *AnnotationViewID = @"ClusterMark";

 ClusterAnnotation *cluster = (ClusterAnnotation*)annotation;

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

 // 添加聚合类的点击手势

 UITapGestureRecognizer* cluTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cluViewClick:)];

[cluAnnotationView addGestureRecognizer:cluTap];

        cluAnnotationView.size = cluster.size;

        cluAnnotationView.annotation = cluster;

 return cluAnnotationView;

    }else if ([annotation isKindOfClass:[LocalModel class]]) { 

       YLBMKPinAnnotationView *newAnnotationView = [[YLBMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];

 // 普通状态下的大头针添加点击手势

        newAnnotationView.userInteractionEnabled = YES;

 UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(animationViewDidClick:)];

[newAnnotationView addGestureRecognizer:tap];

 LocalModel *tempModel = (LocalModel *)annotation;

        newAnnotationView.paopaoView.hidden = YES;

        newAnnotationView.animatesDrop = NO;

 if ((tempModel.pic_app_url.length > 0) && tempModel.showImageType != kStationShowImageTypeYellow) { //网络图片

 UIImage* localImage = self.sever_stationImages[tempModel.pic_app_url];

 if (localImage) { // 已下载过

                newAnnotationView.image = [UIImage scaleToSizeImg:localImage scalRation:[UIScreen mainScreen].scale];

            }else{ // 未下载

                   // 设置占位图

                    newAnnotationView.image = [UIImage imageNamed:@"station_gray.png"];

 // 下载图片

                    [self downLoadStationGroupImageWith:tempModel annotation:newAnnotationView];

            }

        }else{ // 本地图片

 if (tempModel.type == kLocationTypeSelf) {

 UIImage *image = [UIImage imageNamed:@"my_car.png"];

                newAnnotationView.image = image;

            }

 else if (tempModel.showImageType == kStationShowImageTypeBlue) {

 UIImage *image = [UIImage imageNamed:@"station_blue.png"];

                newAnnotationView.image = image;

            }

 else if (tempModel.showImageType == kStationShowImageTypeYellow) {

 //UIImage *image = [UIImage imageNamed:@"StationImageYellow.png"];

 UIImage *image = [UIImage imageNamed:@""];

                newAnnotationView.image = image;

            }

 else if (tempModel.showImageType == kStationShowImageTypeGray) {

 UIImage *image = [UIImage imageNamed:@"station_gray.png"];

                newAnnotationView.image = image;

            }

        }

        return newAnnotationView;

    }

 BMKAnnotationView* norAnotaion = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"nor"];

    norAnotaion.image = [UIImage imageNamed:@"StationImageYellow.png"];

 return norAnotaion;

}

// 下载图片

-(void)downLoadStationGroupImageWith:(LocalModel*)tempModel annotation:(YLBMKPinAnnotationView*)newAnnotationView

{

 dispatch_async(dispatch_get_global_queue(0, 0), ^{

 NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:tempModel.pic_app_url]];

 if(imageData == nil) return ;

 UIImage *image = [UIImage imageWithData:imageData];

 // 回到主线程更新 UI

 dispatch_async(dispatch_get_main_queue(), ^{

            newAnnotationView.image = [UIImage scaleToSizeImg:image scalRation:[UIScreen mainScreen].scale];

 // 将图片写进文件

//            NSData* data = UIImagePNGRepresentation(image);

//            [data writeToFile:kFileImagePath(tempModel.pic_app_url) atomically:YES];

        });

 self.sever_stationImages[tempModel.pic_app_url] = image;

 // 将照片文件存储进沙盒 获取 cashs 沙盒文件路径

    });

}

/*

 *   UIimage 分类  根据下载图片重绘图片

 */

#import "UIImage+Scal.h"

@implementation UIImage (Scal)

+(UIImage *)scaleToSizeImg:(UIImage *)img scalRation:(CGFloat)scal

{

 CGSize size = CGSizeZero;

 CGFloat scale_screen = [UIScreen mainScreen].scale;

 if(scale_screen < 3){

size = CGSizeMake(100, 100);

    }else{

size = CGSizeMake(150,150));

    }

 UIGraphicsBeginImageContext(size);

 // 绘制改变大小的图片

[img drawInRect:CGRectMake(0,0, size.width, size.height)];

 // 从当前context中创建一个改变大小后的图片

 UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();

 // 使当前的context出堆栈

 UIGraphicsEndImageContext();

 //返回新的改变大小后的图片

 return scaledImage;

}

参考文章:  https://blog.csdn.net/lele9096_bk/article/details/68942794

相关文章

  • 大头针Annotation

    自定义大头针 使用大头针 点击添加大头针 自定义大头针颜色和动画 系统大头针的处理 自定义大头针图片 修改大头针模...

  • UI(三十六)地图上的大头针

    大头针的添加展示 《1》大头针视图(MKAnnotationView)在地图上展示 <1>MKAnnotation...

  • iOS - 地图上的大头针

    大头针的添加展示 《1》大头针视图(MKAnnotationView)在地图上展示 <1>MKAnnotation...

  • iOS 大头针基本使用

    一、简介 必须理解: 在地图上操作大头针,实际上是控制大头针数据模型 添加大头针就是添加大头针数据模型添加方法:直...

  • 8.实现自定义的大头针视图用天而降的效果

    #pragma mark -当已经添加大头针视图后调用(还没有显示在地图上)该方法可以用来设置自定义动画--实现大...

  • 地图上添加自定义的大头针

    大头针的图片是网络图片,之前整的都特卡,搜了半天,解决方法如下,加载网络图片就不卡了 - (BMKAnnotati...

  • 高德地图

    #pragma mark - 创建地图 #pragma mark - 在地图上添加大头针标注 #pragma ma...

  • 地图高级 - 自定义大头针

    地图高级 - 自定义大头针 1. 理论支撑 2. 模拟实现系统大头针 实现当添加大头针数据模型时,地图回调的代理方...

  • 高德地图calloutView点击无响应,解决办法

    因为自定义的气泡是添加到大头针上的,而大头针的size只有下面很小一部分,所以calloutView是在大头针的外...

  • 地图高级- 大头针基本使用

    地图高级- 大头针基本使用 1. 大头针 现实生活中的大头针(左图)大头针1.png 地图上的大头针(右图)钉在某...

网友评论

      本文标题:地图上添加自定义的大头针

      本文链接:https://www.haomeiwen.com/subject/morvbftx.html