地图-半径

2019-11-22  本文已影响0人  coder1003
#pragma mark -添加
- (void)addStopAnnotation
{
    CGFloat space = 0.01;
    if (self.stopPointMarray.count >= 2 && self.planMArray.count > 2) {
        if (fabs([[[self.stopPointMarray firstObject] firstObject] doubleValue] - [[[self.planMArray firstObject] firstObject] doubleValue]) < space &&
            fabs([[self.stopPointMarray firstObject][1] doubleValue] - [[self.planMArray firstObject][1] doubleValue]) < space) {
            [self.stopPointMarray removeObjectAtIndex:0];
        }
        if (fabs([[[self.stopPointMarray lastObject] firstObject] doubleValue] - [[[self.planMArray lastObject] firstObject] doubleValue]) < space &&
            fabs([[self.stopPointMarray lastObject][1] doubleValue] - [[self.planMArray lastObject][1] doubleValue]) < space) {
            [self.stopPointMarray removeObjectAtIndex:self.stopPointMarray.count - 1];
        }
    }
    for (NSInteger i = 0; i < self.stopPointMarray.count; i++) {
        NSArray *array = self.stopPointMarray[i];
        SFPointAnnotation *arrivelPoint = [[SFPointAnnotation alloc] init];
        arrivelPoint.coordinate = CLLocationCoordinate2DMake([array[1] doubleValue], [array[0] doubleValue]);
        arrivelPoint.annotationType = StopPointType;
        [self.mapView addAnnotation:arrivelPoint];
        //1120
        //构造圆
        MACircle *circle = [MACircle circleWithCenterCoordinate:CLLocationCoordinate2DMake([array[1] doubleValue], [array[0] doubleValue]) radius:250]; //[array[0] floatValue]
        //在地图上添加圆
        [_mapView addOverlay: circle];
    }
}

#pragma mark - MAMapViewDelegate
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
{
    if([overlay isKindOfClass:[MAPolyline class]]){
        NSInteger index = [self.lines indexOfObject:overlay];
        
        if(index == 0) {
            MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:(MAPolyline *)overlay];
            polylineRenderer.lineWidth = 10.f;
            // 利用图片或者这个做一些区别
            NSBundle *bundle = [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"AMap.bundle/images"]];
            UIImage *image = [UIImage imageNamed:@"traffic_texture_gray" inBundle:bundle compatibleWithTraitCollection:nil];
            polylineRenderer.strokeImage = image;
            return polylineRenderer;
        }else{
            MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:(MAPolyline *)overlay];
            polylineRenderer.lineWidth = 10.f;
            // 利用图片或者这个做一些区别
            NSBundle *bundle = [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"AMap.bundle/images"]];
            UIImage *image = [UIImage imageNamed:@"traffic_texture_blue" inBundle:bundle compatibleWithTraitCollection:nil];
            polylineRenderer.strokeImage = image;
            return polylineRenderer;
        }
    }
    //1120
    if ([overlay isKindOfClass:[MACircle class]])
    {
        MACircleRenderer *circleRenderer = [[MACircleRenderer alloc] initWithCircle:(MACircle *)overlay];
        circleRenderer.lineWidth   = 2.f;
        circleRenderer.strokeColor = [UIColor colorWithRed:70.0/255.0 green:131.0/255.0 blue:245.0/255.0 alpha:0.8];
        circleRenderer.fillColor   = [UIColor colorWithRed:70.0/255.0 green:131.0/255.0 blue:245.0/255.0 alpha:0.2];
        return circleRenderer;
    }
    return nil;
}
上一篇 下一篇

猜你喜欢

热点阅读