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

Insert route below text on reroute #91

Merged
merged 5 commits into from
Mar 27, 2017
Merged

Insert route below text on reroute #91

merged 5 commits into from
Mar 27, 2017

Conversation

bsudekum
Copy link
Contributor

  • Cleans up the arguments for annotate
  • Removes the arrow sooner when rerouting
  • ^ This actually solves inserting the route line below labels. Before, we were inserting below the layer arrow instead.
  • Only redraw the arrow when it actually changes.

closes: #90 #89

/cc @1ec5

@@ -9,8 +9,8 @@ let routeLayerCasingIdentifier = "routeLayerCasing"

extension MGLMapView {

public func annotate(_ routes: [Route], clearMap: Bool) {
guard let route = routes.first, var coordinates = route.coordinates else {
public func annotate(_ route: Route) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this method originally took an array in anticipation of alternative route support, but the next line brushed that idea away anyways. 😄

@@ -33,6 +33,7 @@ class RouteMapViewController: UIViewController, PulleyPrimaryContentControllerDe
let webImageManager = SDWebImageManager.shared()
var shieldAPIDataTask: URLSessionDataTask?
var shieldImageDownloadToken: SDWebImageDownloadToken?
var arrowCurrentStep: RouteStep?
Copy link
Contributor

Choose a reason for hiding this comment

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

(sigh) If we were using annotations instead of runtime styling, we could just make RouteStep conform to MGLAnnotation and ask the map which step is being annotated…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're using runtime styling

Copy link
Contributor

Choose a reason for hiding this comment

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

mapView.addArrow(routeProgress)
if step != arrowCurrentStep {
mapView.removeArrow()
mapView.addArrow(routeProgress)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of tearing down all the style layers and sources then rebuilding them from scratch, we should simply update the source’s shape property to reflect the current step. The check above becomes unnecessary, because mbgl will automatically redraw the style layers without any flashing.

@bsudekum
Copy link
Contributor Author

Updated with feedback

style?.addSource(arrowSourceStroke)
style?.addSource(arrowSource)
if let source = style.source(withIdentifier: arrowSourceIdentifier) {
let s = source as! MGLShapeSource
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine these two lines:

if let source = style.source(withIdentifier: arrowSourceIdentifier) as? MGLShapeSource

s.shape = MGLShapeCollection(shapes: maneuverArrowPolylines)
} else {
style.addSource(arrowSource)
style.addLayer(arrow)
Copy link
Contributor

Choose a reason for hiding this comment

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

Move all the code that sets up arrowSource and arrow into this else block. That way it’s clear that, on the second time around, the only thing that happens is the existing source’s shape getting modified.

s.shape = MGLShapeCollection(shapes: maneuverArrowStrokePolylines)
} else {
style.addSource(arrowSourceStroke)
style.insertLayer(arrowStroke, below: arrow)
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, move all the code that sets up arrowSourceStroke and arrowStroke into this else block.

@@ -122,15 +123,14 @@ class RouteMapViewController: UIViewController, PulleyPrimaryContentControllerDe

func notifyDidReroute(route: Route) {
routePageViewController.notifyDidReRoute()
mapView.annotate([route], clearMap: true)
mapView.addArrow(routeController.routeProgress)
mapView.annotate(route)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s fix annotate(_:) the same way you’ve fixed addArrow(_:): instead of blowing away the source and layers and adding them back in, just change the source’s shape. That’ll fix any flashing that occurs during rerouting and also reduce the amount of work MGLMapView has to do every time the route changes.

@bsudekum bsudekum merged commit 7380929 into master Mar 27, 2017
@bsudekum bsudekum deleted the arrow-line-stuff branch March 27, 2017 20:53
let arrowSourceStroke = MGLShapeSource(identifier: arrowSourceStrokeIdentifier, shape: arrowStrokeShape, options: nil)
let arrowStroke = MGLLineStyleLayer(identifier: arrowSourceIdentifier, source: arrowSourceStroke)
let arrowSource = MGLShapeSource(identifier: arrowSourceIdentifier, shape: arrowShape, options: nil)
let arrow = MGLLineStyleLayer(identifier: arrowLayerIdentifier, source: arrowSource)
Copy link
Contributor

Choose a reason for hiding this comment

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

arrow and arrowStroke should ideally be declared down in the else block instead of up here, since they aren't used in the if let block.

wishtrip-dev pushed a commit to wishtrip-dev/mapbox-navigation-ios that referenced this pull request Feb 28, 2018
Structured road names, codes, destinations
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.

Don't redraw the maneuver arrow if it's in the correct location
2 participants