10
我正在開發一個應用程序,其中用戶可以繪製一個多邊形區域的地圖。防止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;
}
真的,沒有人能告訴我哪跟蹤我可以跟着我的平滑多邊形的邊? – Lisarien 2015-04-03 08:37:29
請提供一個代碼,您正在創建MKPolygon並將其添加到mapView – ninjaproger 2015-04-14 11:30:30