-
Notifications
You must be signed in to change notification settings - Fork 314
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
Add waypoint handling #270
Changes from 1 commit
92a1d30
d009fff
c33b154
c6dabb3
2c6524a
382ede6
52b867d
315a681
cbe2ce1
988dfd0
753814a
275b973
13b4ad1
ebfa33f
204eeff
85684aa
e88e2b1
d7828aa
9f10ad9
082c44e
40d58cd
2c26fe9
6340c58
f052af0
0ab7e26
3e95e9c
8eb79fa
ee9df0f
bb73e66
edd881b
b0247d6
4369010
3c568c4
f0ab02f
0c5ae6f
cfa67b6
7144f59
087de57
7b15853
ba54bd0
4934ad0
84c3c41
2f5602f
8b41be7
5907c9a
3f0e8ca
deda53a
20bc71e
3f8214f
4305493
b2562d6
cb66468
a1d4cbe
8e17b03
771dbca
5b66ffd
5ebb998
e177cd2
1ab08d5
1286a2e
9b2f21b
306e55a
518d535
8ef4112
f0dc3d5
e5eb660
b9b3555
84a1f34
de69c03
5995b2f
26fec4b
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 |
---|---|---|
|
@@ -24,7 +24,7 @@ open class NavigationMapView: MGLMapView { | |
let arrowLayerStrokeIdentifier = "arrowStrokeLayer" | ||
let arrowCasingSymbolLayerIdentifier = "arrowCasingSymbolLayer" | ||
let arrowSymbolSourceIdentifier = "arrowSymbolSource" | ||
let isOpaqueIdentifier = "isOpaqueIdentifier" | ||
let isCurrentLeg = "isCurrentLeg" | ||
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. #270 (comment) got collapsed for some reason: the name |
||
|
||
let routeLineWidthAtZoomLevels: [Int: MGLStyleValue<NSNumber>] = [ | ||
10: MGLStyleValue(rawValue: 6), | ||
|
@@ -80,7 +80,7 @@ open class NavigationMapView: MGLMapView { | |
/** | ||
Adds or updates both the route line and the route line casing | ||
*/ | ||
public func showRoute(_ route: Route, legIndex: Int?) { | ||
public func showRoute(_ route: Route, legIndex: Int? = nil) { | ||
guard let style = style else { | ||
return | ||
} | ||
|
@@ -152,8 +152,8 @@ open class NavigationMapView: MGLMapView { | |
|
||
let source = navigationMapDelegate?.navigationMapView?(self, shapeFor: routeProgress.remainingWaypoints) ?? shape(for: Array(routeProgress.remainingWaypoints.dropLast())) | ||
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. Let’s give this variable and |
||
|
||
if let s = style.source(withIdentifier: waypointSourceIdentifier) as? MGLShapeSource { | ||
s.shape = source | ||
if let waypointSource = style.source(withIdentifier: waypointSourceIdentifier) as? MGLShapeSource { | ||
waypointSource.shape = source | ||
} else { | ||
let sourceShape = MGLShapeSource(identifier: waypointSourceIdentifier, shape: source, options: nil) | ||
style.addSource(sourceShape) | ||
|
@@ -204,9 +204,9 @@ open class NavigationMapView: MGLMapView { | |
let polyline = MGLPolylineFeature(coordinates: congestionSegment.0, count: UInt(congestionSegment.0.count)) | ||
polyline.attributes["congestion"] = String(describing: congestionSegment.1) | ||
if let legIndex = legIndex { | ||
polyline.attributes[isOpaqueIdentifier] = index != legIndex | ||
polyline.attributes[isCurrentLeg] = index != legIndex | ||
} else { | ||
polyline.attributes[isOpaqueIdentifier] = false | ||
polyline.attributes[isCurrentLeg] = index != 0 | ||
} | ||
return polyline | ||
} | ||
|
@@ -227,9 +227,9 @@ open class NavigationMapView: MGLMapView { | |
|
||
let polyline = MGLPolylineFeature(coordinates: legCoordinates, count: UInt(legCoordinates.count)) | ||
if let legIndex = legIndex { | ||
polyline.attributes[isOpaqueIdentifier] = index != legIndex | ||
polyline.attributes[isCurrentLeg] = index != legIndex | ||
} else { | ||
polyline.attributes[isOpaqueIdentifier] = false | ||
polyline.attributes[isCurrentLeg] = index != 0 | ||
} | ||
linesPerLeg.append(polyline) | ||
} | ||
|
@@ -239,7 +239,7 @@ open class NavigationMapView: MGLMapView { | |
|
||
func shape(for waypoints: [Waypoint]) -> MGLShape? { | ||
var features = [MGLPointFeature]() | ||
let letters = (97...122).map({Character(UnicodeScalar($0))}).map { String(describing:$0).uppercased() } | ||
let letters = String.localizedStringWithFormat(NSLocalizedString("ALPHABET", bundle: .mapboxNavigation, value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", comment: "Format string for alphabet;")).components(separatedBy: "") | ||
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. Use an actual separator like a space, because some locales may have multi-character letters in the alphabet, like “IJ” in Dutch. 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. Stray semicolon at the end of the comment. Make sure to point out that each letter should be separated by a space. |
||
|
||
for (waypointIndex, waypoint) in waypoints.enumerated() { | ||
let feature = MGLPointFeature() | ||
|
@@ -292,7 +292,7 @@ open class NavigationMapView: MGLMapView { | |
line.lineOpacity = MGLStyleValue(interpolationMode: .categorical, sourceStops: [ | ||
true: MGLStyleValue(rawValue: 0), | ||
false: MGLStyleValue(rawValue: 1) | ||
], attributeName: isOpaqueIdentifier, options: nil) | ||
], attributeName: isCurrentLeg, options: nil) | ||
|
||
line.lineJoin = MGLStyleValue(rawValue: NSValue(mglLineJoin: .round)) | ||
|
||
|
@@ -320,9 +320,9 @@ open class NavigationMapView: MGLMapView { | |
lineCasing.lineJoin = MGLStyleValue(rawValue: NSValue(mglLineJoin: .round)) | ||
|
||
lineCasing.lineOpacity = MGLStyleValue(interpolationMode: .categorical, sourceStops: [ | ||
true: MGLStyleValue(rawValue: 0.4), | ||
true: MGLStyleValue(rawValue: 0.70), | ||
false: MGLStyleValue(rawValue: 1) | ||
], attributeName: isOpaqueIdentifier, options: nil) | ||
], attributeName: isCurrentLeg, options: nil) | ||
|
||
return lineCasing | ||
} | ||
|
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.
The name
isCurrentLeg
implies that it’s a Boolean. Since this string is being used as an attribute name, call itcurrentLegAttribute
but give it the valueisCurrentLeg
.