Ich habe Karte in meiner App, in der sich wie Benutzer Standort bewegt. Ich habe erfolgreich eine Polylinie für Quelle und Ziel gezeichnet. Mit folgenden Codedynamisch ändern LineWidth von mkpolyline
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{
MKPolylineView *view1 = [[MKPolylineView alloc] initWithOverlay:overlay];
view1.lineWidth = 27.0;
view1.strokeColor = [UIColor colorWithRed:55.0/255.0 green:168.0/255.0 blue:219.0/255.0 alpha:1];
return view1;
}
Aber mein Problem ist, wenn Karte bewegt, ich meine Region Karte als Benutzer bewegt mich zu ändern, dann einige Male Linienzug ist nicht gut einige Zeit seine als Istmaß dicker gezeigt, wie Sie können sehen Sie in Bild unten.
Ich füge das Bild unten an, bitte lassen Sie mich wissen, was ich für glatte Polylinie tun kann, wenn sich die Karte bewegt.
EDIT
Als Matt schlug ich eine Unterklasse von MKPolylineRenderer erstellen und drawMapRect Methode wie unten implementieren:
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{
CGMutablePathRef fullPath = CGPathCreateMutable();
BOOL pathIsEmpty = YES;
//merging all the points as entire path
for (int i=0;i< self.polyline.pointCount;i++){
CGPoint point = [self pointForMapPoint:self.polyline.points[i]];
if (pathIsEmpty){
CGPathMoveToPoint(fullPath, nil, point.x, point.y);
pathIsEmpty = NO;
} else {
CGPathAddLineToPoint(fullPath, nil, point.x, point.y);
}
}
//get bounding box out of entire path.
CGRect pointsRect = CGPathGetBoundingBox(fullPath);
CGRect mapRectCG = [self rectForMapRect:mapRect];
//stop any drawing logic, cuz there is no path in current rect.
if (!CGRectIntersectsRect(pointsRect, mapRectCG))return;
UIColor *darker = [UIColor blackColor];
CGFloat baseWidth = 10/zoomScale;
// draw the dark colour thicker
CGContextAddPath(context, self.path);
CGContextSetStrokeColorWithColor(context, darker.CGColor);
CGContextSetLineWidth(context, baseWidth * 1.5);
CGContextSetLineCap(context, self.lineCap);
CGContextStrokePath(context);
// now draw the stroke color with the regular width
CGContextAddPath(context, self.path);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, baseWidth);
CGContextSetLineCap(context, self.lineCap);
CGContextStrokePath(context);
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
}
aber die gleiche Problem Bild unten ansehen :
ok, ich glaube, ich habe Problem, meine Linienzug einmal hinzugefügt, aber als Geschwindigkeit des Benutzers i Zoomstufe MKMapView geändert wird, wird Zoomstufe geändert, aber Polylinienbreite aktualisieren nicht,
SO Wie kann ich dynamisch ändern lineWidth von mkpolyline ??
Die gleiche Problem in iOS 10 Verwenden von MKPolylineRenderer. Hast du eine Lösung dafür gefunden? –
Ich stehe vor demselben Problem und habe noch keine Lösung gefunden. – Kumar
Ich bin auch vor demselben Problem, jede Lösung herauszufinden, Polyline-Breite zu verwalten, je nach Zoom in oder verkleinern @Kumar –