2015-03-31 6 views
10

पर रोकें मैं एक मानचित्र के साथ एक ऐप विकसित कर रहा हूं जिसमें उपयोगकर्ता बहुभुज क्षेत्र खींच सकता है।एमके पोलिगॉन को नॉट्स

मेरा मुद्दा यह है कि यह संभव है कि यह नॉट्स के साथ बहुभुज ड्राइंग (छवि देखें) (मुझे नहीं पता कि गाँठ सही शब्द है)। मुझे बहुभुज को नॉट्स प्राप्त करने से रोकने का एक आसान तरीका नहीं मिला। संलग्न छवि के मामले में, मुझे छोटे कर्ल को हटाया जाना चाहिए और यहां तक ​​कि रूपरेखा को भी

क्या आप इसे बनाने का कोई तरीका जानते हैं?

- (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 बना रहे हैं और इसे मानचित्र में जोड़ रहे हैं – ninjaproger

उत्तर

6
  1. MKOverlayPathView iOS 7.0 के बाद से deprecated था:

    Polygon with curl

    बहुभुज बना जबकि उपयोगकर्ता स्क्रीन को छू रहा करने की प्रक्रिया इस प्रकार है, MKPolyline, MKPolygon और MKOverlay का उपयोग करता है। आप इसके बजाय MKOverlayRenderer और नक्शा प्रतिनिधि विधि से संबंधित भी उपयोग करेंगे।

  2. MKOverlayRenderer की miterLimit संपत्ति के साथ खेलने का प्रयास करें।

उदाहरण:

-(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

संबंधित मुद्दे

 संबंधित मुद्दे