如何更改Mapbox中目标以外位置的标记?

Suj*_*jal 5 markers ios mapbox swift

对于我的应用程序中的导航功能,我使用的是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")   
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

示例屏幕如下所示.

在此输入图像描述

第一个停止位置表示为"1".我希望这个位置由一些自定义标记图像表示.我已经尝试过mapbox文档(https://www.mapbox.com/ios-sdk/navigation/examples/custom-destination-marker/).但是,我只能更改目标标记.是否可以更改所需位置的标记?

tez*_*zqa 1

这是解决方法,我已经测试过并且有效。

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
  }

}
Run Code Online (Sandbox Code Playgroud)



参考: https: //github.com/mapbox/mapbox-navigation-ios/issues/1893