Как изменить маркер для местоположений, отличных от пункта назначения в Mapbox? - PullRequest
0 голосов
/ 16 ноября 2018

Для функции навигации в моем приложении я использую Mapbox SDK. Ниже приведен фрагмент, который я использую.

func showNavigationMap() {

    let origin = Waypoint(coordinate: currentLocation.coordinate, name: "Your Location")

    guard pickUpCoordinate != nil, dropOffCoordinate != nil else {
        showAlertMessage("Locations not generated")
        return
    }

    let pickUpLocation = Waypoint(coordinate: pickUpCoordinate, name: "Pickup Location")
    let deliveryLocation = Waypoint(coordinate: dropOffCoordinate, name: "Delivery Location")

    let options = NavigationRouteOptions(waypoints: [origin, pickUpLocation, deliveryLocation])

    Directions.shared.calculate(options) { (waypoints, routes, error) in
        guard let route = routes?.first else {
            self.showAlertMessage("No possible routes detected")
            return
        }

        self.mapNavigationViewController = NavigationViewController(for: route)

        self.mapNavigationViewController.delegate = self

        self.present(self.mapNavigationViewController, animated: true, completion: {
            print("Navigation shown")   
        })
    }
}

Пример экрана, как показано ниже.

enter image description here

Место первой остановки обозначено как «1». Я хотел бы, чтобы это местоположение было представлено каким-либо пользовательским изображением маркера. Я пробовал документацию к картографическому блоку (https://www.mapbox.com/ios-sdk/navigation/examples/custom-destination-marker/). Однако я мог изменить только маркер назначения. Можно ли изменить маркер для нужного местоположения?

1 Ответ

0 голосов
/ 14 января 2019

Вот обходной путь, я проверил его, и он работает.

extension NavigationManager: NavigationViewControllerDelegate {

  public func navigationViewController(_ navigationViewController: NavigationViewController, waypointStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
    let waypointStyleLayer = MGLCircleStyleLayer(identifier: identifier, source: source)

    // Way to custom waypoint style
    //waypointStyleLayer.circleColor = NSExpression(forConstantValue: UIColor.yellow)
    //waypointStyleLayer.circleRadius = NSExpression(forConstantValue: 12)
    //waypointStyleLayer.circleStrokeColor = NSExpression(forConstantValue: UIColor.black)
    //waypointStyleLayer.circleStrokeWidth = NSExpression(forConstantValue: 2)

    // Hides waypoint
    waypointStyleLayer.circleOpacity = NSExpression(forConstantValue: 0)
    waypointStyleLayer.circleStrokeOpacity = NSExpression(forConstantValue: 0)

    return waypointStyleLayer
  }

  public func navigationViewController(_ navigationViewController: NavigationViewController, waypointSymbolStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
    let waypointSymbolStyleLayer = MGLSymbolStyleLayer(identifier: identifier, source: source)

    // Way to custom waypoint symbol
    //waypointSymbolStyleLayer.text = NSExpression(forKeyPath: "title")
    //waypointSymbolStyleLayer.textColor = NSExpression(forConstantValue: UIColor.white)

    return waypointSymbolStyleLayer
  }

}

Справка: https://github.com/mapbox/mapbox-navigation-ios/issues/1893

...