Skip to content
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

Merged
merged 5 commits into from
Feb 21, 2018
Merged

Move to constants, make a public #1124

merged 5 commits into from
Feb 21, 2018

Conversation

bsudekum
Copy link
Contributor

This makes a few helpful functions public and also moves around global variables to the constants file.

/cc @mapbox/navigation-ios

Copy link
Contributor

@JThramer JThramer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

/**
Line width base values used at zoom levels.
*/
public let lineWidthAtZoomLevels: [Int: MGLStyleValue<NSNumber>] = [
Copy link
Contributor

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.

Copy link
Contributor

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.

/**
Default opttions applied to features in NavigationMapView.
*/
public let sourceOptions: [MGLShapeSourceOption: Any] = [.maximumZoomLevel: 16]
Copy link
Contributor

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?

/**
Attribute name for the route line that is used for identifying whether a RouteLeg is the current active leg.
*/
public let currentLegAttribute = "isCurrentLeg"
Copy link
Contributor

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 {
Copy link
Contributor

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.
Copy link
Contributor

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.

/**
Line width base values used at zoom levels.
*/
public let lineWidthAtZoomLevels: [Int: MGLStyleValue<NSNumber>] = [
Copy link
Contributor

@1ec5 1ec5 Feb 16, 2018

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.

@@ -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>] = [
Copy link
Contributor

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.

@1ec5
Copy link
Contributor

1ec5 commented Feb 19, 2018

The assumption we made back when introducing navigationMapView(_:routeStyleLayerWithIdentifier:source:) et al. was that a developer would bring their own totally custom line layer. But if the more usual use case is to copy the built-in one and make a few tweaks, maybe what we really need to do is to publicly expose the default line layer’s ID as a constant. Then the developer can call style.layer(withIdentifier:) after calling showRoutes(_:legIndex:) to do the tweaking.

@bsudekum
Copy link
Contributor Author

@1ec5 could we go with what we have now and make some breaking changes when we pick #1076 back up?

*/
public func multiplied(by factor: Double) -> Dictionary {
var newCameraStop: [Int: MGLStyleValue<NSNumber>] = [:]
for stop in MBRouteLineWidthByZoomLevel {
Copy link
Contributor

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.

typealias CongestionSegment = ([CLLocationCoordinate2D], CongestionLevel)

/**
Line width base values used at zoom levels.
Copy link
Contributor

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>] {
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues.

@bsudekum bsudekum merged commit e6c9200 into master Feb 21, 2018
@1ec5 1ec5 deleted the move-constants branch December 5, 2019 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants