Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
bsudekum committed Mar 27, 2017
1 parent f1b8e0f commit 0f688b0
Showing 1 changed file with 50 additions and 46 deletions.
96 changes: 50 additions & 46 deletions MapboxNavigationUI/MGLMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,35 @@ extension MGLMapView {
}

let polyline = MGLPolylineFeature(coordinates: &coordinates, count: route.coordinateCount)
let geoJSONSource = MGLShapeSource(identifier: sourceIdentifier, shape: polyline, options: nil)
let line = MGLLineStyleLayer(identifier: routeLayerIdentifier, source: geoJSONSource)
let lineCasing = MGLLineStyleLayer(identifier: routeLayerCasingIdentifier, source: geoJSONSource)

line.lineColor = MGLStyleValue(rawValue: NavigationUI.shared.tintStrokeColor.withAlphaComponent(0.6))
line.lineWidth = MGLStyleValue(rawValue: 5)
lineCasing.lineColor = MGLStyleValue(rawValue: NavigationUI.shared.tintStrokeColor)
lineCasing.lineWidth = MGLStyleValue(rawValue: 9)

let cap = NSValue(mglLineCap: .round)
let join = NSValue(mglLineJoin: .round)

line.lineCap = MGLStyleValue(rawValue: cap)
line.lineJoin = MGLStyleValue(rawValue: join)
lineCasing.lineCap = MGLStyleValue(rawValue: cap)
lineCasing.lineJoin = MGLStyleValue(rawValue: join)

style.addSource(geoJSONSource)

for layer in style.layers.reversed() {
if let layer = layer as? MGLStyleLayer, !(layer is MGLSymbolStyleLayer) &&
layer.identifier != arrowLayerIdentifier && layer.identifier != arrowSourceIdentifier {
style.insertLayer(line, above: layer)
style.insertLayer(lineCasing, below: line)
return
if let source = style.source(withIdentifier: sourceIdentifier) as? MGLShapeSource {
source.shape = polyline
} else {
let geoJSONSource = MGLShapeSource(identifier: sourceIdentifier, shape: polyline, options: nil)
let line = MGLLineStyleLayer(identifier: routeLayerIdentifier, source: geoJSONSource)
let lineCasing = MGLLineStyleLayer(identifier: routeLayerCasingIdentifier, source: geoJSONSource)

line.lineColor = MGLStyleValue(rawValue: NavigationUI.shared.tintStrokeColor.withAlphaComponent(0.6))
line.lineWidth = MGLStyleValue(rawValue: 5)
lineCasing.lineColor = MGLStyleValue(rawValue: NavigationUI.shared.tintStrokeColor)
lineCasing.lineWidth = MGLStyleValue(rawValue: 9)

let cap = NSValue(mglLineCap: .round)
let join = NSValue(mglLineJoin: .round)

line.lineCap = MGLStyleValue(rawValue: cap)
line.lineJoin = MGLStyleValue(rawValue: join)
lineCasing.lineCap = MGLStyleValue(rawValue: cap)
lineCasing.lineJoin = MGLStyleValue(rawValue: join)

style.addSource(geoJSONSource)
for layer in style.layers.reversed() {
if let layer = layer as? MGLStyleLayer, !(layer is MGLSymbolStyleLayer) &&
layer.identifier != arrowLayerIdentifier && layer.identifier != arrowSourceIdentifier {
style.insertLayer(line, above: layer)
style.insertLayer(lineCasing, below: line)
return
}
}
}
}
Expand Down Expand Up @@ -132,39 +136,39 @@ extension MGLMapView {

maneuverArrowPolylines.append(headStrokePolyline)

let arrowSource = MGLShapeSource(identifier: arrowSourceIdentifier, shape: MGLShapeCollection(shapes: maneuverArrowPolylines), options: nil)
let arrow = MGLLineStyleLayer(identifier: arrowLayerIdentifier, source: arrowSource)

arrow.lineWidth = MGLStyleValue(rawValue: 6)
arrow.lineColor = MGLStyleValue(rawValue: .white)

// Arrow stroke
let arrowSourceStroke = MGLShapeSource(identifier: arrowSourceStrokeIdentifier, shape: MGLShapeCollection(shapes: maneuverArrowStrokePolylines), options: nil)
let arrowStroke = MGLLineStyleLayer(identifier: arrowSourceIdentifier, source: arrowSourceStroke)
let arrowShape = MGLShapeCollection(shapes: maneuverArrowPolylines)
let arrowStrokeShape = MGLShapeCollection(shapes: maneuverArrowStrokePolylines)

let cap = NSValue(mglLineCap: .round)
let join = NSValue(mglLineJoin: .round)

arrowStroke.lineCap = MGLStyleValue(rawValue: cap)
arrowStroke.lineJoin = MGLStyleValue(rawValue: join)
arrow.lineCap = MGLStyleValue(rawValue: cap)
arrow.lineJoin = MGLStyleValue(rawValue: join)

arrowStroke.lineWidth = MGLStyleValue(rawValue: 8)
arrowStroke.lineColor = MGLStyleValue(rawValue: NavigationUI.shared.tintColor)
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)

if let source = style.source(withIdentifier: arrowSourceIdentifier) {
let s = source as! MGLShapeSource
s.shape = MGLShapeCollection(shapes: maneuverArrowPolylines)
if let source = style.source(withIdentifier: arrowSourceIdentifier) as? MGLShapeSource {
source.shape = arrowShape
} else {

arrow.lineCap = MGLStyleValue(rawValue: cap)
arrow.lineJoin = MGLStyleValue(rawValue: join)
arrow.lineWidth = MGLStyleValue(rawValue: 6)
arrow.lineColor = MGLStyleValue(rawValue: .white)

style.addSource(arrowSource)
style.addLayer(arrow)
}

if let source = style.source(withIdentifier: arrowSourceStrokeIdentifier) {
let s = source as! MGLShapeSource
s.shape = MGLShapeCollection(shapes: maneuverArrowStrokePolylines)
if let source = style.source(withIdentifier: arrowSourceStrokeIdentifier) as? MGLShapeSource {
source.shape = arrowStrokeShape
} else {

arrowStroke.lineCap = MGLStyleValue(rawValue: cap)
arrowStroke.lineJoin = MGLStyleValue(rawValue: join)
arrowStroke.lineWidth = MGLStyleValue(rawValue: 8)
arrowStroke.lineColor = MGLStyleValue(rawValue: NavigationUI.shared.tintColor)

style.addSource(arrowSourceStroke)
style.insertLayer(arrowStroke, below: arrow)
}
Expand Down

0 comments on commit 0f688b0

Please sign in to comment.