From 6e4f476e4d9a1ef13c9b87dc8eb06b0fce6fde78 Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Wed, 16 Sep 2020 14:22:28 -0700 Subject: [PATCH 1/3] Add a predicate filter for the road label MGLLineStyleLayer. Prevent repeated recalculation of sliced current step line shape. --- MapboxNavigation/RouteMapViewController.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MapboxNavigation/RouteMapViewController.swift b/MapboxNavigation/RouteMapViewController.swift index 2e4c6c621e..ed3ac27ba6 100644 --- a/MapboxNavigation/RouteMapViewController.swift +++ b/MapboxNavigation/RouteMapViewController.swift @@ -684,6 +684,13 @@ extension RouteMapViewController: NavigationViewDelegate { streetLabelLayer.lineOpacity = NSExpression(forConstantValue: 1) streetLabelLayer.lineWidth = NSExpression(forConstantValue: 20) streetLabelLayer.lineColor = NSExpression(forConstantValue: UIColor.white) + + // filter out to road classes valid for motor transport + let roadPredicates = ["motorway", "trunk", "primary", "secondary", "tertiary", "street"].compactMap { roadClass -> NSPredicate? in + return NSPredicate(format: "%K == %@", "class", roadClass) + } + let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: roadPredicates) + streetLabelLayer.predicate = compoundPredicate style.insertLayer(streetLabelLayer, at: 0) } @@ -692,6 +699,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 +714,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)! let lookAheadDistance: CLLocationDistance = 10 guard let pointAheadFeature = featurePolyline.sliced(from: closestCoordinate)!.coordinateFromStart(distance: lookAheadDistance) else { continue } From 4facc22ae2230e256b7d0bc126932fe6f166f3d5 Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Wed, 16 Sep 2020 21:24:19 -0700 Subject: [PATCH 2/3] Include additional road classes in filter for road names. Skip using the predicate filter for walking or cycling profiles. --- MapboxNavigation/RouteMapViewController.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MapboxNavigation/RouteMapViewController.swift b/MapboxNavigation/RouteMapViewController.swift index ed3ac27ba6..6ae15221e9 100644 --- a/MapboxNavigation/RouteMapViewController.swift +++ b/MapboxNavigation/RouteMapViewController.swift @@ -685,12 +685,14 @@ extension RouteMapViewController: NavigationViewDelegate { streetLabelLayer.lineWidth = NSExpression(forConstantValue: 20) streetLabelLayer.lineColor = NSExpression(forConstantValue: UIColor.white) - // filter out to road classes valid for motor transport - let roadPredicates = ["motorway", "trunk", "primary", "secondary", "tertiary", "street"].compactMap { roadClass -> NSPredicate? in - return NSPredicate(format: "%K == %@", "class", roadClass) + 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 + return NSPredicate(format: "%K == %@", "class", roadClass) + } + let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: roadPredicates) + streetLabelLayer.predicate = compoundPredicate } - let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: roadPredicates) - streetLabelLayer.predicate = compoundPredicate style.insertLayer(streetLabelLayer, at: 0) } From ff440d2ebf67cac4cb83740479ccd38212fdd10b Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Mon, 21 Sep 2020 09:53:22 -0700 Subject: [PATCH 3/3] Revise logic for forming the road class predicate for wayname label finding. --- MapboxNavigation/RouteMapViewController.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MapboxNavigation/RouteMapViewController.swift b/MapboxNavigation/RouteMapViewController.swift index 6ae15221e9..82d5adba5c 100644 --- a/MapboxNavigation/RouteMapViewController.swift +++ b/MapboxNavigation/RouteMapViewController.swift @@ -687,10 +687,9 @@ extension RouteMapViewController: NavigationViewDelegate { 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 - return NSPredicate(format: "%K == %@", "class", roadClass) - } - let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: roadPredicates) + let roadPredicates = ["motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "tertiary_link", "street", "street_limited", "roundabout"] + + let compoundPredicate = NSPredicate(format: "class IN %@", roadPredicates) streetLabelLayer.predicate = compoundPredicate } style.insertLayer(streetLabelLayer, at: 0)