Ich entwickle eine App mit einer Karte, in der der Benutzer einen Polygonbereich zeichnen kann.Verhindern, dass MKPolygon Knoten hat
Mein Problem ist, was es möglich ist, Polygone mit Knoten zu zeichnen (siehe das Bild) (ich weiß nicht, ob Knoten das richtige Wort ist). Ich habe keine einfache Möglichkeit gefunden, das Polygon daran zu hindern, Knoten zu bekommen. Für den Fall des angehängten Bildes, möchte ich die kleine Wellung entfernt und sogar die Kontur geglättet werden
Kennen Sie einen Weg, das zu machen?
Der Prozess um das Polygon zu zeichnen, während der Benutzer den Bildschirm berührt, verwenden Sie nicht MKPolyline
, MKPolygon
und MKOverlay
wie folgt:
- (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;
}
Wirklich, niemand konnte mir sagen, welche Spur ich folgen konnte die Ränder meiner Polygone zu glätten? – Lisarien
Bitte geben Sie einen Code ein, mit dem Sie MKPolygon erstellen und zu mapView hinzufügen. – ninjaproger