-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of Wayname calculation #2635
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -684,6 +684,15 @@ extension RouteMapViewController: NavigationViewDelegate { | |||||||||||||
streetLabelLayer.lineOpacity = NSExpression(forConstantValue: 1) | ||||||||||||||
streetLabelLayer.lineWidth = NSExpression(forConstantValue: 20) | ||||||||||||||
streetLabelLayer.lineColor = NSExpression(forConstantValue: UIColor.white) | ||||||||||||||
|
||||||||||||||
if ![DirectionsProfileIdentifier.walking, DirectionsProfileIdentifier.cycling].contains( router.routeProgress.routeOptions.profileIdentifier) { | ||||||||||||||
// filter out to road classes valid for motor transport | ||||||||||||||
let roadPredicates = ["motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "tertiary_link", "street", "street_limited", "roundabout", "mini_roundabout"].compactMap { roadClass -> NSPredicate? in | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m not sure about |
||||||||||||||
return NSPredicate(format: "%K == %@", "class", roadClass) | ||||||||||||||
} | ||||||||||||||
let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: roadPredicates) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something along these lines should work and would probably perform slightly better:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll adopt these changes. Worth getting the best performance. |
||||||||||||||
streetLabelLayer.predicate = compoundPredicate | ||||||||||||||
} | ||||||||||||||
style.insertLayer(streetLabelLayer, at: 0) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
@@ -692,6 +701,7 @@ extension RouteMapViewController: NavigationViewDelegate { | |||||||||||||
var smallestLabelDistance = Double.infinity | ||||||||||||||
var currentName: String? | ||||||||||||||
var currentShieldName: NSAttributedString? | ||||||||||||||
let slicedLine = stepShape.sliced(from: closestCoordinate)! | ||||||||||||||
|
||||||||||||||
for feature in features { | ||||||||||||||
var allLines: [MGLPolyline] = [] | ||||||||||||||
|
@@ -706,7 +716,6 @@ extension RouteMapViewController: NavigationViewDelegate { | |||||||||||||
guard line.pointCount > 0 else { continue } | ||||||||||||||
let featureCoordinates = Array(UnsafeBufferPointer(start: line.coordinates, count: Int(line.pointCount))) | ||||||||||||||
let featurePolyline = LineString(featureCoordinates) | ||||||||||||||
let slicedLine = stepShape.sliced(from: closestCoordinate)! | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, moving the slicing out of the loop should have a measurable impact on areas where there are lots of overlapping lines. |
||||||||||||||
|
||||||||||||||
let lookAheadDistance: CLLocationDistance = 10 | ||||||||||||||
guard let pointAheadFeature = featurePolyline.sliced(from: closestCoordinate)!.coordinateFromStart(distance: lookAheadDistance) else { continue } | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I think it’s possible to shorten this line based on the type of
profileIdentifier
: