iOS调用百度地图(二)

2019-08-05  本文已影响0人  LiuffSunny

可以借助title属性来绘制多个电子围栏

//添加预警区域覆盖物
- (void)addWarningOverlayViewAndAnnotationWithModel:(SiteelectFenceModel *)model {
    if ([model.electFenceType isEqualToString:@"1"]) {
        // 添加圆形覆盖物
        int electRadius = 100;
        if (![NSString isNull:model.electRadius]) {
            if ([model.electRadius intValue] < 30) {
                electRadius = 30;
            }else{
                electRadius = [model.electRadius intValue];
            }
        }
        BMKCircle* warningcircle;
        CLLocationCoordinate2D coor = CLLocationCoordinate2DMake([model.electCenter.lat doubleValue], [model.electCenter.lon doubleValue]);
        warningcircle = [BMKCircle circleWithCenterCoordinate:coor radius:electRadius];
        warningcircle.title = WarningTag;
        [_mapView addOverlay:warningcircle];
    }else if ([model.electFenceType isEqualToString:@"2"]){
        BMKPolygon *warningpolygon;
        // 添加多边形覆盖物
        CLLocationCoordinate2D coords[model.coordinateList.count];
        for (int i = 0; i < model.coordinateList.count; i ++) {
            SiteLocationModel *lomodel = model.coordinateList[i];
            CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([lomodel.lat doubleValue], [lomodel.lon doubleValue]);
            coords[i] = coord;
        }
        warningpolygon = [BMKPolygon polygonWithCoordinates:coords count:model.coordinateList.count];
        warningpolygon.title = WarningTag;
        [_mapView addOverlay:warningpolygon];
    }else{//不去绘制
    }
    // 打点
    [self addLocationAnnotationWithModel:model];
}

大头针打点 单个

代理方法

//根据overlay生成对应的View

#大头针图标显示和区分的代理方法
#pragma mark - BMKMapViewDelegate
/**
 根据anntation生成对应的annotationView
 
 @param mapView 地图View
 @param annotation 指定的标注
 @return 生成的标注View
 */
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation {
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        newAnnotationView.animatesDrop = NO;// 设置该标注点动画显示
        newAnnotationView.annotation=annotation;
        [newAnnotationView.paopaoView removeFromSuperview];
        //    newAnnotationView.tag = [annotation.subtitle integerValue];

        NSString *imagename;
        if ([annotation.title isEqual:WarningTag]) {
            //预警小图标
            imagename = @"icon_jingzhi_42*42_3.6";
        }else{
            if (![NSString isNull:self.showView.siteModel.addressType] && ![NSString isNull:self.showView.siteModel.markColor]) {
                imagename = [NSString stringWithFormat:@"icon_%@_%@_big",self.showView.siteModel.addressType,self.showView.siteModel.markColor];
            }else
            {
                if ([self.showView.siteModel.isExists isEqualToString:@"1"]) {
                    // 是个库区
                    imagename = [NSString stringWithFormat:@"icon_dingwei1_m_90x106_3.2"];
                }else
                {
                    imagename = [NSString stringWithFormat:@"icon_tanhao_m_90x106_3.2"];
                }
            }
        }
        UIImage *icoImage = [UIImage imageNamed:imagename];
        newAnnotationView.image = icoImage;   //把大头针换成别的图片
        [self.BkAnnotionViews addObject:newAnnotationView];
        newAnnotationView.frame = CGRectMake(0, 0, icoImage.size.width, icoImage.size.height);
        
        UIView *popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 260, 124)];
        BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];
        pView.hidden = YES;
        pView.frame = CGRectMake(0, 0, 260, 124);
        ((BMKPinAnnotationView*)newAnnotationView).paopaoView = nil;
        ((BMKPinAnnotationView*)newAnnotationView).paopaoView = pView;
        
        return newAnnotationView;
    }
    return nil;
}
上一篇 下一篇

猜你喜欢

热点阅读