Hello Team,
I am trying to display the line name corresponding to draw polyline in the apple map. when I used the draw function to draw the line name when polyline get render in the apple map. but these are too cluttered and it is not easy to readable. Please refer to the screenshot.
I need a solution something like how apple shows the name for any road name, street name in the apple map.
Please find the below Screenshots link :
https://drive.google.com/open?id=1hCVGTvB7cytlcbHA2ZQ3gHd-ptkEK2ZL
https://drive.google.com/open?id=1Ce8ebz8wSiJqGkV7THqcvNMehrMlYD1v
Code which we are using to render the linename to map
//
// CustomOverlayPathRenderer.m
// lineinspection
//
// Created by Rupendra Kumar on 13/02/17.
// Copyright © 2017 Rupendra kumar. All rights reserved.
//
#import "CustomPolylineRenderer.h"
#import "LineGuide-Swift.h"
#define kchangeDistanceKmToMiles 0.621371
@interface CustomPolylineRenderer()
{
NSInteger coordinatesNumbers;
}
@property (nonatomic,assign)MKMapView * controllerName;
@end
@implementation CustomPolylineRenderer
@synthesize pathName =_pathName;
@synthesize objectId =_objectId;
@synthesize coordinates = coordinates;
- (instancetype)initWithOverlay:(id<MKOverlay>)overlay
{
self = [super initWithOverlay:overlay];
if (self) {
coordinatesNumbers = 0;
if ([overlay isKindOfClass:[CustomPolyline class]]) {
_pathName = ((CustomPolyline *)overlay).lineName;
_objectId = ((CustomPolyline *)overlay).lineid;
coordinates = ((CustomPolyline *)overlay).coordinate;
_controllerName = ((CustomPolyline *)overlay).controllerName;
}
}
return self;
}
- (void)applyStrokePropertiesToContext:(CGContextRef)context atZoomScale:(MKZoomScale)zoomScale {
[super applyStrokePropertiesToContext:context atZoomScale:zoomScale];
CGContextSetLineWidth(context, self.lineWidth/zoomScale);
}
- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
return YES;
}
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
// //calculate CG values from circle coordinate and radius...
CGFloat roadWidth = MKRoadWidthAtZoomScale(zoomScale);
float size ;
if (zoomScale >0.001 && zoomScale <0.9) {
size = (5.0 * roadWidth);
}
else {
size = MIN(1200, (15.0 * roadWidth));
}
BOOL shouldDraw = YES;
if (coordinates.latitude != NAN && coordinates.longitude != NAN) {
shouldDraw = YES;
} else {
shouldDraw = NO;
}
if (shouldDraw) {
if ([_pathName length] > 0)
{
CLLocationCoordinate2D center = coordinates;
CGPoint centerPoint =
[self pointForMapPoint:MKMapPointForCoordinate(center)];
NSDictionary *mutableAttributedString = @{NSForegroundColorAttributeName: [UIColor grayColor], NSFontAttributeName: [UIFont boldSystemFontOfSize: size]};
UIGraphicsPushContext(context);
[_pathName drawAtPoint:centerPoint withAttributes:mutableAttributedString];
UIGraphicsPopContext();
}
}
}
@end