Skip to content

Commit

Permalink
Rebase to latest release-v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
avi-c committed May 11, 2021
1 parent ad2b88f commit 1680bfa
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions Sources/MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ open class NavigationMapView: UIView {
@objc dynamic public var routeDurationAnnotationColor: UIColor = .routeDurationAnnotationColor
@objc dynamic public var routeDurationAnnotationSelectedTextColor: UIColor = .selectedRouteDurationAnnotationTextColor
@objc dynamic public var routeDurationAnnotationTextColor: UIColor = .routeDurationAnnotationTextColor
static let routeDurationAnnotationsLayerIdentifier: String = "routeDurationAnnotationsLayerIdentifier"

/**
List of Mapbox Maps font names to be used for any symbol layers added by the Navigation SDK.
Expand Down Expand Up @@ -855,15 +856,13 @@ open class NavigationMapView: UIView {
with: "RouteInfoAnnotationRightHanded",
stretchX: stretchX,
stretchY: stretchY,
scale: 2.0,
imageContent: imageContent)

let selectedAnnotationImage = image.tint(routeDurationAnnotationSelectedColor)
style.setStyleImage(image: selectedAnnotationImage,
with: "RouteInfoAnnotationRightHanded-Selected",
stretchX: stretchX,
stretchY: stretchY,
scale: 2.0,
imageContent: imageContent)
}

Expand All @@ -880,15 +879,13 @@ open class NavigationMapView: UIView {
with: "RouteInfoAnnotationLeftHanded",
stretchX: stretchX,
stretchY: stretchY,
scale: 2.0,
imageContent: imageContent)

let selectedAnnotationImage = image.tint(routeDurationAnnotationSelectedColor)
style.setStyleImage(image: selectedAnnotationImage,
with: "RouteInfoAnnotationLeftHanded-Selected",
stretchX: stretchX,
stretchY: stretchY,
scale: 2.0,
imageContent: imageContent)
}
}
Expand Down Expand Up @@ -1007,24 +1004,24 @@ open class NavigationMapView: UIView {
*/
private func addRouteAnnotationSymbolLayer(features: FeatureCollection) {
guard let style = mapView.style else { return }
if let _ = try? mapView.style.getSource(identifier: IdentifierString.routeDurationAnnotations, type: GeoJSONSource.self).get() {
let _ = mapView.style.updateGeoJSON(for: IdentifierString.routeDurationAnnotations, with: features)
if let _ = try? mapView.style.getSource(identifier: NavigationMapView.routeDurationAnnotationsLayerIdentifier, type: GeoJSONSource.self).get() {
let _ = mapView.style.updateGeoJSON(for: NavigationMapView.routeDurationAnnotationsLayerIdentifier, with: features)
} else {

var dataSource = GeoJSONSource()
dataSource.data = .featureCollection(features)
mapView.style.addSource(source: dataSource, identifier: IdentifierString.routeDurationAnnotations)
mapView.style.addSource(source: dataSource, identifier: NavigationMapView.routeDurationAnnotationsLayerIdentifier)
}

var shapeLayer: SymbolLayer

if let layer = try? mapView.style.getLayer(with: IdentifierString.routeDurationAnnotations, type: SymbolLayer.self).get() {
if let layer = try? mapView.style.getLayer(with: NavigationMapView.routeDurationAnnotationsLayerIdentifier, type: SymbolLayer.self).get() {
shapeLayer = layer
} else {
shapeLayer = SymbolLayer(id: IdentifierString.routeDurationAnnotations)
shapeLayer = SymbolLayer(id: NavigationMapView.routeDurationAnnotationsLayerIdentifier)
}

shapeLayer.source = IdentifierString.routeDurationAnnotations
shapeLayer.source = NavigationMapView.routeDurationAnnotationsLayerIdentifier

shapeLayer.layout?.textField = .expression(Exp(.get) {
"text"
Expand Down Expand Up @@ -1061,7 +1058,7 @@ open class NavigationMapView: UIView {

if let expressionData = symbolSortKeyString.data(using: .utf8), let expJSONObject = try? JSONSerialization.jsonObject(with: expressionData, options: []) {

mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(IdentifierString.routeDurationAnnotations,
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(NavigationMapView.routeDurationAnnotationsLayerIdentifier,
property: "symbol-sort-key",
value: expJSONObject)
}
Expand All @@ -1081,10 +1078,10 @@ open class NavigationMapView: UIView {

if let expressionData = expressionString.data(using: .utf8), let expJSONObject = try? JSONSerialization.jsonObject(with: expressionData, options: []) {

mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(IdentifierString.routeDurationAnnotations,
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(NavigationMapView.routeDurationAnnotationsLayerIdentifier,
property: "icon-anchor",
value: expJSONObject)
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(IdentifierString.routeDurationAnnotations,
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(NavigationMapView.routeDurationAnnotationsLayerIdentifier,
property: "text-anchor",
value: expJSONObject)
}
Expand All @@ -1104,11 +1101,11 @@ open class NavigationMapView: UIView {

if let expressionData = offsetExpressionString.data(using: .utf8), let expJSONObject = try? JSONSerialization.jsonObject(with: expressionData, options: []) {

mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(IdentifierString.routeDurationAnnotations,
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(NavigationMapView.routeDurationAnnotationsLayerIdentifier,
property: "icon-offset",
value: expJSONObject)

mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(IdentifierString.routeDurationAnnotations,
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(NavigationMapView.routeDurationAnnotationsLayerIdentifier,
property: "text-offset",
value: expJSONObject)
}
Expand All @@ -1126,8 +1123,8 @@ open class NavigationMapView: UIView {
Remove the underlying style layers and data sources for the route duration annotations.
*/
private func removeRouteDurationAnnotationsLayerFromStyle(_ style: MapboxMaps.Style) {
style.removeLayers([IdentifierString.routeDurationAnnotations])
style.removeSources([IdentifierString.routeDurationAnnotations])
style.removeLayers([NavigationMapView.routeDurationAnnotationsLayerIdentifier])
style.removeSources([NavigationMapView.routeDurationAnnotationsLayerIdentifier])
}

// This function generates the text for the label to be shown on screen. It will include estimated duration and info on Tolls, if applicable
Expand Down

0 comments on commit 1680bfa

Please sign in to comment.