Line names are too cluttered. Name is not readable.

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

these are too cluttered and it is not easy to readable


Indeed !!!


I need a solution something like how apple shows the name for any road name, street name in the apple map.


Can you explain:

display the line name corresponding to draw polyline in the apple map

What is a line ? Is it a metro line ?

What do you want to display: the name of the line ?

Then why do you display several times ?

Where on the map do you want to display ?


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

          }
    }


It seems you call this several times for the same line.

You should:

- either select in which case you want to display

- or have a status Bool to keep track that display was already done for this line


It is hard to tell more with the limited code you provided.

Hi Claude,
Thanks for your support. I am providing anwser of your questions.

What is a line ? Is it a metro line ? -> No it is an electric power line.

What do you want to display: the name of the line ? -> To identify the line by their name.

Then why do you display several times ? -> we are not displaying several time, there are multiple lines which have same color corresponding to their voltage

Where on the map do you want to display ? -> near by line.




this code which was provide by me only when I was render line with name over the map.

do you know something like how apple shows the name for any road name, street name in the apple map.

do you know something like how apple shows the name for any road name, street name in the apple map.

Unfortunately, no, I can only gues.


Then why do you display several times ? -> we are not displaying several time, there are multiple lines which have same color corresponding to their voltage

There are hundreds of labels on screen.

How many lines have you on the map ?

There are hundreds of labels on screen.

How many lines have you on the map ?



there are 1450 ploylines draw in the map with multi geometry.

I have draw the name over the coordinate of the overlay when lines render over map. so its comes over one another when we zoom in and out.

You mean 1450 electric lines ?


For sure, tehre is no room for 1450 labels, whatever you try.


So, either :

- there are not 1450 electric lines and youn should modify your code to display a label only once on a iOS polyline (and not for each segment)

-there are 1450 electric lines, and you should create some type of hierarchy, to display labels only for some of them: in large scale (large area map), only highest voltage lines ; when zooming in, as number of lines on screen reduces, progressively show labels for lower voltage.

Line names are too cluttered. Name is not readable.
 
 
Q