我正在开发一个地图的应用程序,用户可以在其中绘制多边形区域.
我的问题是可以用结打印多边形(见图像)(我不知道结是否是正确的词).我没有找到一个简单的方法来防止多边形得到结.
对于所附图像的情况,我想要小的卷曲被去除,甚至轮廓平滑
你知道一个办法吗?
在用户触摸屏幕时绘制多边形的过程使用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; }
解决方法
>从iOS 7.0起,MKOverlayPathView为
deprecated.您可以使用
MKOverlayRenderer而不是相关的地图委托方法.
>尝试玩与MKOverlayRenderer的 miterLimit属性.
>尝试玩与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; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。