-
Notifications
You must be signed in to change notification settings - Fork 318
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
Move to constants, make a public #1124
Conversation
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.
Looks good.
MapboxNavigation/Constants.swift
Outdated
/** | ||
Line width base values used at zoom levels. | ||
*/ | ||
public let lineWidthAtZoomLevels: [Int: MGLStyleValue<NSNumber>] = [ |
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.
Avoid polluting the global namespace in Objective-C: rename these public methods with the MB
class prefix.
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.
Also, bring back the words “route line”, because these line widths are only applicable to route line styling.
MapboxNavigation/Constants.swift
Outdated
/** | ||
Default opttions applied to features in NavigationMapView. | ||
*/ | ||
public let sourceOptions: [MGLShapeSourceOption: Any] = [.maximumZoomLevel: 16] |
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.
How is the developer expected to use this constant? Are they expected to use these options for all shape sources they create?
MapboxNavigation/Constants.swift
Outdated
/** | ||
Attribute name for the route line that is used for identifying whether a RouteLeg is the current active leg. | ||
*/ | ||
public let currentLegAttribute = "isCurrentLeg" |
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.
Note that this constant will most likely go away or be replaced by something like legIndex
in #1076.
/** | ||
Returns a proportional `Dictionary` of `lineWidthAtZoomLevels` at a specific factor. | ||
*/ | ||
public func multiplied(by factor: Double) -> Dictionary { |
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.
This method will also go away as part of the migration to expressions in #1076.
|
||
extension Dictionary where Key == Int, Value: MGLStyleValue<NSNumber> { | ||
/** | ||
Returns a proportional `Dictionary` of `lineWidthAtZoomLevels` at a specific factor. |
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.
As written, this method could just as well operate on circle size stops, not just line width stops:
Returns a copy of the stop dictionary with each value multiplied by the given factor.
MapboxNavigation/Constants.swift
Outdated
/** | ||
Line width base values used at zoom levels. | ||
*/ | ||
public let lineWidthAtZoomLevels: [Int: MGLStyleValue<NSNumber>] = [ |
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.
I don’t think we should expose this constant publicly at all. The whole point of making the route line style customizable is that the developer would substitute style values like these with their own.
MapboxNavigation/Constants.swift
Outdated
@@ -6,19 +6,14 @@ typealias CongestionSegment = ([CLLocationCoordinate2D], CongestionLevel) | |||
/** | |||
Line width base values used at zoom levels. | |||
*/ | |||
public let lineWidthAtZoomLevels: [Int: MGLStyleValue<NSNumber>] = [ | |||
public let MBRoutelineWidthAtZoomLevels: [Int: MGLStyleValue<NSNumber>] = [ |
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.
Nit: “route line” is two words. Also, the usual phrasing for a dictionary would be “by zoom level”. So MBRouteLineWidthByZoomLevel
.
The assumption we made back when introducing |
*/ | ||
public func multiplied(by factor: Double) -> Dictionary { | ||
var newCameraStop: [Int: MGLStyleValue<NSNumber>] = [:] | ||
for stop in MBRouteLineWidthByZoomLevel { |
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.
Because this line refers to MBRouteLineWidthByZoomLevel
instead of self
, this code:
let stops = [5: MGLStyleValue(rawValue: 1)]
stops.multiplied(by: 1)
magically produces a dictionary equivalent to MBRouteLineWidthByZoomLevel
, even though MBRouteLineWidthByZoomLevel
was never used explicitly.
MapboxNavigation/Constants.swift
Outdated
typealias CongestionSegment = ([CLLocationCoordinate2D], CongestionLevel) | ||
|
||
/** | ||
Line width base values used at zoom levels. |
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.
A stop dictionary representing the default line widths of the route line by zoom level when
NavigationMapViewDelegate.navigationMapView(_:routeStyleLayerWithIdentifier:source:)
is undefined.You may use this constant in your implementation of
NavigationMapViewDelegate.navigationMapView(_:routeStyleLayerWithIdentifier:source:)
if you want to keep the default line widths but customize other aspects of the route line.
*/ | ||
public func multiplied(by factor: Double) -> Dictionary { | ||
var newCameraStop: [Int: MGLStyleValue<NSNumber>] = [:] | ||
for stop in self as [Int : MGLStyleValue<NSNumber>] { |
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.
Unsure if I can get away with not casting here.
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 only thing that comes to mind for me is that making a private typealias NumericStyleDictionary = [Int: MGLStyleValue<NSNumber>]
(or something) might make the code a little cleaner.
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 overall extension requires the same type conformance in its where
condition. If as
builds without errors (as opposed to as!
or as?
), then casting is fine.
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.
No issues.
This makes a few helpful functions public and also moves around global variables to the constants file.
/cc @mapbox/navigation-ios