-
Notifications
You must be signed in to change notification settings - Fork 299
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
Show current way name #155
Changes from 11 commits
9cf513b
06fac74
6238945
f5b84d4
c201373
98d53dc
8c8784d
0de970a
9cdd7f2
4f2dfbe
fd5193c
194e474
b298170
04cba87
567fa34
bf04c05
75732d2
8b035a1
04614fd
310d211
77d309f
9dad9fa
93974a9
15efc46
75c67c6
4d036fa
dec8456
a9fffd6
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// MGLVectorSource.swift | ||
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. Nit: Drop default header comments |
||
// MapboxNavigation | ||
// | ||
// Created by Bobby Sudekum on 4/18/17. | ||
// Copyright © 2017 Mapbox. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Mapbox | ||
|
||
extension MGLVectorSource { | ||
var isMapboxStreets: Bool { | ||
guard let configurationURL = configurationURL else { | ||
return false | ||
} | ||
return configurationURL.scheme == "mapbox" && configurationURL.host!.components(separatedBy: ",").contains("mapbox.mapbox-streets-v7") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ class ArrowStrokePolyline: ArrowFillPolyline {} | |
class RouteMapViewController: UIViewController, PulleyPrimaryContentControllerDelegate { | ||
@IBOutlet weak var mapView: NavigationMapView! | ||
@IBOutlet weak var recenterButton: UIButton! | ||
@IBOutlet weak var wayNameLabel: StyleLabel! | ||
|
||
var routePageViewController: RoutePageViewController! | ||
var routeTableViewController: RouteTableViewController! | ||
|
@@ -40,6 +41,9 @@ class RouteMapViewController: UIViewController, PulleyPrimaryContentControllerDe | |
var shieldImageDownloadToken: SDWebImageDownloadToken? | ||
var arrowCurrentStep: RouteStep? | ||
|
||
let streetsLanguages = ["zh", "ru", "fr", "es", "en"] | ||
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. According to this documentation, the Mapbox Streets v7 source’s |
||
let RoadLabelLayerIdentifier = "roadLabelLayer" | ||
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. This property is only used in one method, and there won’t ever be a need for another class to know about it. Make this a local variable instead. |
||
|
||
var simulatesLocationUpdates: Bool { | ||
guard let parent = parent as? NavigationViewController else { return false } | ||
return parent.simulatesLocationUpdates | ||
|
@@ -54,6 +58,10 @@ class RouteMapViewController: UIViewController, PulleyPrimaryContentControllerDe | |
mapView.tintColor = NavigationUI.shared.tintColor | ||
recenterButton.tintColor = NavigationUI.shared.tintColor | ||
recenterButton.applyDefaultCornerRadiusShadow(cornerRadius: 22) | ||
wayNameLabel.applyDefaultCornerRadiusShadow() | ||
wayNameLabel.layer.masksToBounds = true | ||
wayNameLabel.insets = UIEdgeInsetsMake(1, 4, 1, 4) | ||
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 the Swift-style |
||
|
||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
|
@@ -141,6 +149,7 @@ class RouteMapViewController: UIViewController, PulleyPrimaryContentControllerDe | |
mapView.addArrow(routeController.routeProgress) | ||
mapView.showRoute(route) | ||
mapView.userTrackingMode = .followWithCourse | ||
wayNameLabel.isHidden = true | ||
} | ||
|
||
func notifyAlertLevelDidChange(routeProgress: RouteProgress) { | ||
|
@@ -253,6 +262,51 @@ extension RouteMapViewController: NavigationMapViewDelegate { | |
let route = routeController.routeProgress.route | ||
guard let coordinates = route.coordinates else { return nil } | ||
|
||
if let userLocation = mapView.userLocation, | ||
let style = mapView.style, | ||
routeController.showCurrentWayNameLabel, | ||
recenterButton.isHidden { | ||
|
||
let streetsSources = style.sources.flatMap { | ||
$0 as? MGLVectorSource | ||
}.filter { | ||
$0.isMapboxStreets | ||
} | ||
let streetsSourceIdentifiers = streetsSources.map { | ||
$0.identifier | ||
} | ||
assert(!streetsSourceIdentifiers.isEmpty, "The option `showCurrentWayNameLabel` must contain the source `mapbox.mapbox-streets-v7`") | ||
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. An option can’t contain a source. A style contains a source. 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. If the style doesn’t contain Mapbox Streets source, we could add it. |
||
|
||
if let mapboxSteetsSource = streetsSources.first, style.layer(withIdentifier: "roadLabelLayer") == nil{ | ||
let streetLabelLayer = MGLLineStyleLayer(identifier: RoadLabelLayerIdentifier, source: mapboxSteetsSource) | ||
streetLabelLayer.sourceLayerIdentifier = "road_label" | ||
|
||
// If the opacity is set to 0, the feature will be ignored in `mapView.visibleFeatures()` | ||
streetLabelLayer.lineOpacity = MGLStyleValue(rawValue: 0.001) | ||
streetLabelLayer.lineWidth = MGLStyleValue(rawValue: 10) | ||
style.addLayer(streetLabelLayer) | ||
} | ||
|
||
if let userPuck = mapView.view(for: userLocation) { | ||
let features = mapView.visibleFeatures(in: userPuck.frame, styleLayerIdentifiers: Set([RoadLabelLayerIdentifier])) | ||
|
||
for feature in features { | ||
|
||
var key = "name" | ||
if let language = Locale.preferredLanguages.first!.components(separatedBy: "-").first, | ||
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. It’d be great to adapt this UI to the user’s preferred language, but are we doing that in the turn banner and step table and on the map? I think it’d be more important to be consistent throughout the UI. We could use the runtime styling API to localize the map, with code very similar to this code. However, the Directions API doesn’t yet return localized way names, so the turn banner and step table are stuck in the local language. |
||
streetsLanguages.contains(language) { | ||
key += "_\(language)" | ||
} | ||
|
||
if let name = feature.attribute(forKey: key) as? String { | ||
wayNameLabel.text = name | ||
wayNameLabel.sizeToFit() | ||
wayNameLabel.isHidden = false | ||
} | ||
} | ||
} | ||
} | ||
|
||
var newCoordinate = location.coordinate | ||
if routeController.snapsUserLocationAnnotationToRoute { | ||
// Snap to route | ||
|
@@ -338,6 +392,7 @@ extension RouteMapViewController: MGLMapViewDelegate { | |
|
||
if mode != .followWithCourse { | ||
recenterButton.isHidden = false | ||
wayNameLabel.isHidden = true | ||
startResetTrackingModeTimer() | ||
} else { | ||
recenterButton.isHidden = true | ||
|
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.
Does this still need to be an option?