2015-03-31 9 views
10

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

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

Знаете ли вы способ сделать это?

Polygon with curl

Процесс рисования многоугольника, когда пользователь прикасается к экрану, действительно использует 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; 
} 
+0

Действительно, никто не мог сказать мне, какой трек я мог бы следовать, чтобы сгладить края моих полигонов? – Lisarien

+0

Просьба указать код, в котором вы создаете MKPolygon, и добавить его в mapView – ninjaproger

ответ

6
  1. MKOverlayPathView был deprecated начиная с прошивкой 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; 
} 
+0

Спасибо за ваш ответ, который, как представляется, является хорошим путем. Я расскажу вам, смогу ли я решить эту проблему. – Lisarien