美文网首页
iOS调用百度地图(二)

iOS调用百度地图(二)

作者: LiuffSunny | 来源:发表于2019-08-05 18:20 被阅读0次

    可以借助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];
    }
    

    大头针打点 单个

    • (void)addLocationAnnotationWithModel:(SiteelectFenceModel *)model {
      BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init];
      annotation.title = WarningTag;
      [_mapView addAnnotation:annotation];
      _annotation = annotation;
      CLLocationCoordinate2D coor = CLLocationCoordinate2DMake([model.lat doubleValue], [model.lon doubleValue]);
      _annotation.coordinate = coor;
      }

    代理方法

    //根据overlay生成对应的View

    • (BMKOverlayView *)mapView:(BMKMapView )mapView viewForOverlay:(id <BMKOverlay>)overlay
      {
      if ([overlay isKindOfClass:[BMKCircle class]])
      {
      BMKCircleView
      circleView = [[BMKCircleView alloc] initWithOverlay:overlay];
      if ([overlay.title isEqual:WarningTag]) {
      circleView.fillColor = [UIColor colorWithHex:0xFF0000 alpha:0.2];
      circleView.strokeColor = [UIColor colorWithHex:0xFF0000 alpha:1];
      }else
      {
      circleView.fillColor = [UIColor colorWithHex:0x6FB1FF alpha:0.2];
      circleView.strokeColor = [UIColor colorWithHex:0x6FB1FF alpha:1];
      }
      circleView.lineWidth = 0.5;
      return circleView;
      }

      if ([overlay isKindOfClass:[BMKPolygon class]])
      {
      BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay];
      if ([overlay.title isEqual:WarningTag]) {
      polygonView.fillColor = [UIColor colorWithHex:0xFF0000 alpha:0.2];
      polygonView.strokeColor = [UIColor colorWithHex:0xFF0000 alpha:1];
      }else{
      polygonView.strokeColor = [UIColor colorWithHex:0x6FB1FF alpha:1];
      polygonView.fillColor = [UIColor colorWithHex:0x6FB1FF alpha:0.2];
      }
      polygonView.lineWidth = 0.5;
      // polygonView.lineDash = (overlay == polygon2);
      return polygonView;
      }

      return nil;
      }

    #大头针图标显示和区分的代理方法
    #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;
    }
    

    相关文章

      网友评论

          本文标题:iOS调用百度地图(二)

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