Запретить MKPolygon иметь узлы

Я разрабатываю приложение с картой, на которой пользователь может рисовать многоугольники.

Моя проблема заключается в том, что можно рисовать многоугольники с узлами (см. изображение) (я не знаю, правильное ли слово узел). Я не нашел простого способа предотвратить образование узлов на многоугольнике. В случае с прикрепленным изображением я хотел бы, чтобы небольшой завиток был удален и даже контур был сглажен.

Вы знаете способ сделать это?

Многоугольник с завитком

Процесс рисования многоугольника, когда пользователь касается экрана, использует MKPolyline, MKPolygon и MKOverlay следующим образом:

- (void)touchesBegan:(UITouch*)touch
{
    CGPoint location = [touch locationInView:self.mapView];
    CLLocationCoordinate2D coordinate = [self.mapView convertPoint:location toCoordinateFromView:self.mapView];
    [self.coordinates addObject:[NSValue valueWithMKCoordinate:coordinate]];
}

- (void)touchesMoved:(UITouch*)touch
{
    CGPoint location = [touch locationInView:self.mapView];
    CLLocationCoordinate2D coordinate = [self.mapView convertPoint:location toCoordinateFromView:self.mapView];
    [self.coordinates addObject:[NSValue valueWithMKCoordinate:coordinate]];
}

- (void)touchesEnded:(UITouch*)touch
{
    CGPoint location = [touch locationInView:self.mapView];
    CLLocationCoordinate2D coordinate = [self.mapView convertPoint:location toCoordinateFromView:self.mapView];
    [self.coordinates addObject:[NSValue valueWithMKCoordinate:coordinate]];
    [self didTouchUpInsideDrawButton:nil];
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKOverlayPathView *overlayPathView;

    if ([overlay isKindOfClass:[MKPolygon class]])
    {
        // create a polygonView using polygon_overlay object
        overlayPathView = [[MKPolygonView alloc] initWithPolygon:overlay];
        overlayPathView.fillColor   = [UIColor redColor];
        overlayPathView.lineWidth = 1.5;
        return overlayPathView;
    }
    else if ([overlay isKindOfClass:[MKPolyline class]])
    {
        overlayPathView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];
        overlayPathView.fillColor   = [UIColor redColor];
        overlayPathView.lineWidth = 3;
        return overlayPathView;
    }
    return nil;
}

person Lisarien    schedule 31.03.2015    source источник
comment
Неужели никто не мог мне подсказать, по какой дорожке мне следовать, чтобы сгладить края моих полигонов?   -  person Lisarien    schedule 03.04.2015
comment
Пожалуйста, предоставьте код, в котором вы создаете MKPolygon и добавляете его в mapView.   -  person ninjaproger    schedule 14.04.2015


Ответы (1)


  1. MKOverlayPathView был устарел, начиная с iOS 7.0. Вы должны использовать MKOverlayRenderer вместо него, а также соответствующий метод делегата карты.
  2. Попробуйте поиграть с miterLimit свойства MKOverlayRenderer.

Пример:

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
    if ([overlay isKindOfClass:[MKPolygon class]]) {
        MKPolygonRenderer *polygonRenederer = [[MKPolygonRenderer alloc] initWithPolygon:overlay];
        polygonRenederer.fillColor = [UIColor redColor];
        polygonRenederer.lineWidth = 1.5;
        polygonRenederer.miterLimit = 10;
        return polygonRenederer;
    } else if ([overlay isKindOfClass:[MKPolyline class]]) {
        MKPolylineRenderer *lineRenderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
        lineRenderer.strokeColor = [UIColor redColor];
        lineRenderer.lineWidth = 3;
        return lineRenderer;
    }
    return nil;
}
person ninjaproger    schedule 14.04.2015
comment
Спасибо за ваш ответ, который кажется хорошим путем для подражания. Я скажу вам, смогу ли я решить мою проблему с этим. - person Lisarien; 17.04.2015