@@ -39,7 +39,7 @@ open class NavigationMapView: UIView {
39
39
public var showsCongestionForAlternativeRoutes : Bool = false
40
40
41
41
/**
42
- Controls wheter to show restricted portions of a route line.
42
+ Controls whether to show restricted portions of a route line.
43
43
44
44
Restricted areas are drawn using `routeRestrictedAreaColor` which is customizable.
45
45
*/
@@ -96,6 +96,11 @@ open class NavigationMapView: UIView {
96
96
}
97
97
}
98
98
99
+ /**
100
+ Controls whether to use a dotted line for the route line when the transport type is walking.
101
+ */
102
+ public var usesDottedLineForWalking : Bool = true
103
+
99
104
/**
100
105
Location manager that is used to track accuracy and status authorization changes.
101
106
*/
@@ -165,6 +170,12 @@ open class NavigationMapView: UIView {
165
170
}
166
171
}
167
172
173
+ var isWalking : Bool {
174
+ get {
175
+ return routes? . first? . legs. first? . profileIdentifier == . walking ? true : false
176
+ }
177
+ }
178
+
168
179
func updateRouteLineWithRouteLineTracksTraversal( ) {
169
180
if let routes = self . routes {
170
181
let offset = fractionTraveled
@@ -349,6 +360,15 @@ open class NavigationMapView: UIView {
349
360
mapView. mapboxMap. style. removeLayers ( layerIdentifiers)
350
361
mapView. mapboxMap. style. removeSources ( sourceIdentifiers)
351
362
363
+ do {
364
+ if mapView. mapboxMap. style. image ( withId: NavigationMapView . ImageIdentifier. minusImage) != nil {
365
+ try mapView. mapboxMap. style. removeImage ( withId: NavigationMapView . ImageIdentifier. minusImage)
366
+ }
367
+ } catch {
368
+ Log . error ( " Failed to remove image \( NavigationMapView . ImageIdentifier. minusImage) from style with error: \( error. localizedDescription) . " ,
369
+ category: . navigationUI)
370
+ }
371
+
352
372
routes = nil
353
373
removeLineGradientStops ( )
354
374
}
@@ -623,13 +643,22 @@ open class NavigationMapView: UIView {
623
643
below parentLayerIndentifier: String ? = nil ,
624
644
isMainRoute: Bool = true ,
625
645
legIndex: Int ? = nil ) -> String ? {
626
- guard let defaultShape = route. shape else { return nil }
646
+ guard let defaultShape = route. shape,
647
+ let circleImage = Bundle . mapboxNavigation. image ( named: " minus " ) ? . withRenderingMode ( . alwaysTemplate) else { return nil }
627
648
let shape = delegate? . navigationMapView ( self , shapeFor: route) ?? defaultShape
628
649
629
650
let geoJSONSource = self . geoJSONSource ( shape)
630
651
let sourceIdentifier = route. identifier ( . source( isMainRoute: isMainRoute, isSourceCasing: false ) )
631
652
632
653
do {
654
+ if isWalking && usesDottedLineForWalking && mapView. mapboxMap. style. image ( withId: NavigationMapView . ImageIdentifier. minusImage) == nil {
655
+ try mapView. mapboxMap. style. addImage ( circleImage,
656
+ id: NavigationMapView . ImageIdentifier. minusImage,
657
+ sdf: true ,
658
+ stretchX: [ ImageStretches ( first: 0 , second: 0 ) ] ,
659
+ stretchY: [ ImageStretches ( first: 0 , second: 0 ) ] )
660
+ }
661
+
633
662
if mapView. mapboxMap. style. sourceExists ( withId: sourceIdentifier) {
634
663
try mapView. mapboxMap. style. updateGeoJSONSource ( withId: sourceIdentifier,
635
664
geoJSON: . geometry( . lineString( shape) ) )
@@ -659,6 +688,9 @@ open class NavigationMapView: UIView {
659
688
lineLayer? . lineWidth = . expression( Expression . routeLineWidthExpression ( ) )
660
689
lineLayer? . lineJoin = . constant( . round)
661
690
lineLayer? . lineCap = . constant( . round)
691
+ if isWalking && usesDottedLineForWalking {
692
+ lineLayer? . linePattern = . constant( . name( NavigationMapView . ImageIdentifier. minusImage) )
693
+ }
662
694
663
695
if isMainRoute {
664
696
let congestionFeatures = route. congestionFeatures ( legIndex: legIndex, roadClassesWithOverriddenCongestionLevels: roadClassesWithOverriddenCongestionLevels)
@@ -717,6 +749,7 @@ open class NavigationMapView: UIView {
717
749
@discardableResult func addRouteCasingLayer( _ route: Route ,
718
750
below parentLayerIndentifier: String ? = nil ,
719
751
isMainRoute: Bool = true ) -> String ? {
752
+ if isWalking && usesDottedLineForWalking { return nil }
720
753
guard let defaultShape = route. shape else { return nil }
721
754
let shape = delegate? . navigationMapView ( self , casingShapeFor: route) ?? defaultShape
722
755
0 commit comments