@@ -39,7 +39,7 @@ open class NavigationMapView: UIView {
3939 public var showsCongestionForAlternativeRoutes : Bool = false
4040
4141 /**
42- Controls wheter to show restricted portions of a route line.
42+ Controls whether to show restricted portions of a route line.
4343
4444 Restricted areas are drawn using `routeRestrictedAreaColor` which is customizable.
4545 */
@@ -96,6 +96,11 @@ open class NavigationMapView: UIView {
9696 }
9797 }
9898
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+
99104 /**
100105 Location manager that is used to track accuracy and status authorization changes.
101106 */
@@ -165,6 +170,12 @@ open class NavigationMapView: UIView {
165170 }
166171 }
167172
173+ var isWalking : Bool {
174+ get {
175+ return routes? . first? . legs. first? . profileIdentifier == . walking ? true : false
176+ }
177+ }
178+
168179 func updateRouteLineWithRouteLineTracksTraversal( ) {
169180 if let routes = self . routes {
170181 let offset = fractionTraveled
@@ -349,6 +360,15 @@ open class NavigationMapView: UIView {
349360 mapView. mapboxMap. style. removeLayers ( layerIdentifiers)
350361 mapView. mapboxMap. style. removeSources ( sourceIdentifiers)
351362
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+
352372 routes = nil
353373 removeLineGradientStops ( )
354374 }
@@ -623,13 +643,22 @@ open class NavigationMapView: UIView {
623643 below parentLayerIndentifier: String ? = nil ,
624644 isMainRoute: Bool = true ,
625645 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 }
627648 let shape = delegate? . navigationMapView ( self , shapeFor: route) ?? defaultShape
628649
629650 let geoJSONSource = self . geoJSONSource ( shape)
630651 let sourceIdentifier = route. identifier ( . source( isMainRoute: isMainRoute, isSourceCasing: false ) )
631652
632653 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+
633662 if mapView. mapboxMap. style. sourceExists ( withId: sourceIdentifier) {
634663 try mapView. mapboxMap. style. updateGeoJSONSource ( withId: sourceIdentifier,
635664 geoJSON: . geometry( . lineString( shape) ) )
@@ -659,6 +688,9 @@ open class NavigationMapView: UIView {
659688 lineLayer? . lineWidth = . expression( Expression . routeLineWidthExpression ( ) )
660689 lineLayer? . lineJoin = . constant( . round)
661690 lineLayer? . lineCap = . constant( . round)
691+ if isWalking && usesDottedLineForWalking {
692+ lineLayer? . linePattern = . constant( . name( NavigationMapView . ImageIdentifier. minusImage) )
693+ }
662694
663695 if isMainRoute {
664696 let congestionFeatures = route. congestionFeatures ( legIndex: legIndex, roadClassesWithOverriddenCongestionLevels: roadClassesWithOverriddenCongestionLevels)
@@ -717,6 +749,7 @@ open class NavigationMapView: UIView {
717749 @discardableResult func addRouteCasingLayer( _ route: Route ,
718750 below parentLayerIndentifier: String ? = nil ,
719751 isMainRoute: Bool = true ) -> String ? {
752+ if isWalking && usesDottedLineForWalking { return nil }
720753 guard let defaultShape = route. shape else { return nil }
721754 let shape = delegate? . navigationMapView ( self , casingShapeFor: route) ?? defaultShape
722755
0 commit comments